diff options
Diffstat (limited to 'account.go')
-rw-r--r-- | account.go | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -418,10 +418,17 @@ func (a *Account) eventInternal(event *Event) error { } } + var cache_key string if event.Id != "" { - cache_key := fmt.Sprintf("%s/event_seen/%s/%s", + // If the event has an ID, make sure it is processed only once + cache_key = fmt.Sprintf("%s/event_seen/%s/%s", a.Protocol, mx_room_id, event.Id) - if !dbKvTestAndSet(cache_key, "yes") { + slot_key := dbKvSlotKey(cache_key) + + dbLockSlot(slot_key) + defer dbUnlockSlot(slot_key) + + if dbKvGet(cache_key) == "yes" { // false: cache key was not modified, meaning we // already saw the event return nil @@ -470,6 +477,12 @@ func (a *Account) eventInternal(event *Event) error { } } } + + // Mark message as received in db + if cache_key != "" { + dbKvPutLocked(cache_key, "yes") + } + return nil } } |