Skip to content

Commit

Permalink
Ignore conversation updates that arrive soon after marking as spam
Browse files Browse the repository at this point in the history
Apparently there are race conditions in the gmessages app where it may
send a `SPAM_FOLDER` update and then `ACTIVE` immediately afterwards.
  • Loading branch information
tulir committed Apr 16, 2024
1 parent accd12a commit d0a8b84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type Portal struct {
matrixMessages chan PortalMatrixMessage

cancelCreation atomic.Pointer[context.CancelCauseFunc]
markedSpamAt time.Time
}

var (
Expand Down
6 changes: 6 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ func (user *User) syncConversation(v *gmproto.Conversation, source string) {
Logger()
log.Debug().Any("conversation_data", convCopy).Msg("Got conversation update")
ctx := log.WithContext(context.TODO())
if updateType == gmproto.ConversationStatus_SPAM_FOLDER || updateType == gmproto.ConversationStatus_BLOCKED_FOLDER {
portal.markedSpamAt = time.Now()
}
if cancel := portal.cancelCreation.Load(); cancel != nil {
if updateType == gmproto.ConversationStatus_SPAM_FOLDER || updateType == gmproto.ConversationStatus_BLOCKED_FOLDER {
(*cancel)(fmt.Errorf("conversation was moved to spam"))
Expand Down Expand Up @@ -1161,6 +1164,9 @@ func (user *User) syncConversation(v *gmproto.Conversation, source string) {
if v.Participants == nil {
log.Debug().Msg("Not syncing conversation with nil participants")
return
} else if time.Since(portal.markedSpamAt) < 1*time.Minute {
log.Warn().Msg("Dropping conversation update due to suspected race condition")
return
}
if source == "event" {
go func() {
Expand Down

0 comments on commit d0a8b84

Please sign in to comment.