JojiiOfficial / Matrix-EmailBridge

A bridge written in Golang to receive and write emails in matrix
BSD 2-Clause "Simplified" License
120 stars 14 forks source link

Avoid duplicated events #53

Open nicuh opened 2 years ago

nicuh commented 2 years ago

Problem

Same events are being consumed after the bot is removed and then added back into the room. This makes impossible to re-add the bot to the same room without first removing old messages.

How to reproduce it

Cause

The bot reprocesses all events and as a result it executes !leave command again, even though it is an old one.

Solution

Use the FileStore to persist the room state and make use of membership state and timestamp to ignore messages that were sent before the bot was invited into the room. Additionally, avoid reprocessing same events between restarts by storing and using nextBatchToken