Skip to content
Extraits de code Groupes Projets
Valider 845ea4a9 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Merge branch 'matrix-attachments-order-fix' into 'develop'

Fix discord attachments order issue

See merge request arise/matrix-appservice-discord!3
parents 2fd24ef3 49d2f3ba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -1056,58 +1056,6 @@ export class DiscordBot {
}
try {
const intent = this.GetIntentFromDiscordMember(msg.author, msg.webhookID);
// Check Attachements
if (!editEventId) {
// on discord you can't edit in images, you can only edit text
// so it is safe to only check image upload stuff if we don't have
// an edit
await Util.AsyncForEach(msg.attachments.array(), async (attachment) => {
const content = await Util.DownloadFile(attachment.url);
const fileMime = content.mimeType || mime.getType(attachment.name || "")
|| "application/octet-stream";
const mxcUrl = await intent.underlyingClient.uploadContent(
content.buffer,
fileMime,
attachment.name || "",
);
const type = fileMime.split("/")[0];
let msgtype = {
audio: "m.audio",
image: "m.image",
video: "m.video",
}[type];
if (!msgtype) {
msgtype = "m.file";
}
const info = {
mimetype: fileMime,
size: attachment.size,
} as IMatrixMediaInfo;
if (msgtype === "m.image" || msgtype === "m.video") {
info.w = attachment.width!;
info.h = attachment.height!;
}
await Util.AsyncForEach(rooms, async (room) => {
const eventId = await intent.sendEvent(room, {
body: attachment.name || "file",
external_url: attachment.url,
info,
msgtype,
url: mxcUrl,
});
this.lastEventIds[room] = eventId;
const evt = new DbEvent();
evt.MatrixId = `${eventId};${room}`;
evt.DiscordId = msg.id;
evt.ChannelId = msg.channel.id;
if (msg.guild) {
evt.GuildId = msg.guild.id;
}
await this.store.Insert(evt);
this.userActivity.updateUserActivity(intent.userId);
});
});
}
if (!msg.content && msg.embeds.length === 0) {
return;
}
......@@ -1180,6 +1128,58 @@ export class DiscordBot {
res = await trySend();
await afterSend(res);
}
// Check Attachements
if (!editEventId) {
// on discord you can't edit in images, you can only edit text
// so it is safe to only check image upload stuff if we don't have
// an edit
await Util.AsyncForEach(msg.attachments.array(), async (attachment) => {
const content = await Util.DownloadFile(attachment.url);
const fileMime = content.mimeType || mime.getType(attachment.name || "")
|| "application/octet-stream";
const mxcUrl = await intent.underlyingClient.uploadContent(
content.buffer,
fileMime,
attachment.name || "",
);
const type = fileMime.split("/")[0];
let msgtype = {
audio: "m.audio",
image: "m.image",
video: "m.video",
}[type];
if (!msgtype) {
msgtype = "m.file";
}
const info = {
mimetype: fileMime,
size: attachment.size,
} as IMatrixMediaInfo;
if (msgtype === "m.image" || msgtype === "m.video") {
info.w = attachment.width!;
info.h = attachment.height!;
}
await Util.AsyncForEach(rooms, async (room) => {
const eventId = await intent.sendEvent(room, {
body: attachment.name || "file",
external_url: attachment.url,
info,
msgtype,
url: mxcUrl,
});
this.lastEventIds[room] = eventId;
const evt = new DbEvent();
evt.MatrixId = `${eventId};${room}`;
evt.DiscordId = msg.id;
evt.ChannelId = msg.channel.id;
if (msg.guild) {
evt.GuildId = msg.guild.id;
}
await this.store.Insert(evt);
this.userActivity.updateUserActivity(intent.userId);
});
});
}
});
MetricPeg.get.requestOutcome(msg.id, true, "success");
} catch (err) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter