message: delete immediate edits
diff: @@ -53,6 +53,7 @@ export class DiscordBot {
  private bridge: Bridge;
  private presenceInterval: number;
  private sentMessages: string[];
  + private lastEventIds: { [channelId: string]: string };
  private discordMsgProcessor: DiscordMessageProcessor;
  private mxEventProcessor: MatrixEventProcessor;
  private presenceHandler: PresenceHandler;
  @@ -73,6 +74,7 @@ export class DiscordBot {
  );
  this.presenceHandler = new PresenceHandler(this);
  this.discordMessageQueue = {};
  + this.lastEventIds = {};
  }
  public setBridge(bridge: Bridge) {
  @@ -314,6 +316,7 @@ export class DiscordBot {
  await Util.AsyncForEach(res, async (m: Discord.Message) => {
  log.verbose("Sent (state msg) ", m.id);
  this.sentMessages.push(m.id);
  + this.lastEventIds[event.room_id] = event.event_id;
  const evt = new DbEvent();
  evt.MatrixId = `${event.event_id};${event.room_id}`;
  evt.DiscordId = m.id;
  @@ -385,6 +388,7 @@ export class DiscordBot {
  await Util.AsyncForEach(msg, async (m: Discord.Message) => {
  log.verbose("Sent ", m.id);
  this.sentMessages.push(m.id);
  + this.lastEventIds[event.room_id] = event.event_id;
  const evt = new DbEvent();
  evt.MatrixId = `${event.event_id};${event.room_id}`;
  evt.DiscordId = m.id;
  @@ -534,6 +538,7 @@ export class DiscordBot {
  formatted_body: matrixMsg.formattedBody,
  msgtype: "m.text",
  });
  + this.lastEventIds[room] = res.event_id;
  const evt = new DbEvent();
  evt.MatrixId = `${res.event_id};${room}`;
  evt.DiscordId = msgID;
  @@ -648,6 +653,7 @@ export class DiscordBot {
  msgtype,
  url: content.mxcUrl,
  });
  + this.lastEventIds[room] = res.event_id;
  const evt = new DbEvent();
  evt.MatrixId = `${res.event_id};${room}`;
  evt.DiscordId = msg.id;
  @@ -671,6 +677,7 @@ export class DiscordBot {
  msgtype: result.msgtype,
  });
  const afterSend = async (re) => {
  + this.lastEventIds[room] = re.event_id;
  const evt = new DbEvent();
  evt.MatrixId = `${re.event_id};${room}`;
  evt.DiscordId = msg.id;
  @@ -705,10 +712,18 @@ export class DiscordBot {
  log.info(`Got edit event for ${newMsg.id}`);
  let link = "";
  const storeEvent = await this.store.Get(DbEvent, {discord_id: oldMsg.id});
  - if (storeEvent && storeEvent.Result && storeEvent.Next()) {
  + if (storeEvent && storeEvent.Result) {
  + while (storeEvent.Next()) {
  const matrixIds = storeEvent.MatrixId.split(";");
  + if (matrixIds[0] === this.lastEventIds[matrixIds[1]]) {
  + log.info("Immediate edit, deleting and re-sending");
  + await this.DeleteDiscordMessage(oldMsg);
  + await this.OnMessage(newMsg);
  + return;
  + }
  link = `https://matrix.to/#/${matrixIds[1]}/${matrixIds[0]}`;
  }
  + }
  // Create a new edit message using the old and new message contents
  const editedMsg = await this.discordMsgProcessor.FormatEdit(oldMsg, newMsg, link);
  