GODT-2223: Fix handling deletion of nonexistent labels

This commit is contained in:
James Houlahan
2023-01-17 17:13:52 +01:00
committed by Leander Beernaert
parent 849c8bee78
commit b63029054d
2 changed files with 3 additions and 8 deletions

View File

@ -52,9 +52,8 @@ type UserLabelDeleted struct {
UserID string UserID string
LabelID string LabelID string
Name string
} }
func (event UserLabelDeleted) String() string { func (event UserLabelDeleted) String() string {
return fmt.Sprintf("UserLabelDeleted: UserID: %s, LabelID: %s, Name: %s", event.UserID, event.LabelID, logging.Sensitive(event.Name)) return fmt.Sprintf("UserLabelDeleted: UserID: %s, LabelID: %s", event.UserID, event.LabelID)
} }

View File

@ -393,21 +393,17 @@ func (user *User) handleDeleteLabelEvent(ctx context.Context, event proton.Label
user.log.WithField("labelID", event.ID).Info("Handling label deleted event") user.log.WithField("labelID", event.ID).Info("Handling label deleted event")
label, ok := user.apiLabels[event.ID]
if !ok {
delete(user.apiLabels, event.ID)
}
for _, updateCh := range xslices.Unique(maps.Values(user.updateCh)) { for _, updateCh := range xslices.Unique(maps.Values(user.updateCh)) {
update := imap.NewMailboxDeleted(imap.MailboxID(event.ID)) update := imap.NewMailboxDeleted(imap.MailboxID(event.ID))
updateCh.Enqueue(update) updateCh.Enqueue(update)
updates = append(updates, update) updates = append(updates, update)
} }
delete(user.apiLabels, event.ID)
user.eventCh.Enqueue(events.UserLabelDeleted{ user.eventCh.Enqueue(events.UserLabelDeleted{
UserID: user.apiUser.ID, UserID: user.apiUser.ID,
LabelID: event.ID, LabelID: event.ID,
Name: label.Name,
}) })
return updates, nil return updates, nil