Other: Do not fail on label events

Do not treat unknown label creation/deletion/update or deletion in Bridge
as an error as the Gluon cache still needs to receive these events to
correct its internal state.
This commit is contained in:
Leander Beernaert
2022-12-19 14:16:46 +01:00
parent 031ed9c203
commit 00059e6754

View File

@ -301,11 +301,9 @@ func (user *User) handleCreateLabelEvent(_ context.Context, event proton.LabelEv
}).Info("Handling label created event") }).Info("Handling label created event")
if _, ok := user.apiLabels[event.Label.ID]; ok { if _, ok := user.apiLabels[event.Label.ID]; ok {
return fmt.Errorf("label %q already exists", event.ID) user.apiLabels[event.Label.ID] = event.Label
} }
user.apiLabels[event.Label.ID] = event.Label
for _, updateCh := range user.updateCh { for _, updateCh := range user.updateCh {
updateCh.Enqueue(newMailboxCreatedUpdate(imap.MailboxID(event.ID), getMailboxName(event.Label))) updateCh.Enqueue(newMailboxCreatedUpdate(imap.MailboxID(event.ID), getMailboxName(event.Label)))
} }
@ -328,11 +326,9 @@ func (user *User) handleUpdateLabelEvent(_ context.Context, event proton.LabelEv
}).Info("Handling label updated event") }).Info("Handling label updated event")
if _, ok := user.apiLabels[event.Label.ID]; !ok { if _, ok := user.apiLabels[event.Label.ID]; !ok {
return fmt.Errorf("label %q does not exist", event.ID) user.apiLabels[event.Label.ID] = event.Label
} }
user.apiLabels[event.Label.ID] = event.Label
for _, updateCh := range user.updateCh { for _, updateCh := range user.updateCh {
updateCh.Enqueue(imap.NewMailboxUpdated( updateCh.Enqueue(imap.NewMailboxUpdated(
imap.MailboxID(event.ID), imap.MailboxID(event.ID),
@ -356,11 +352,9 @@ func (user *User) handleDeleteLabelEvent(_ context.Context, event proton.LabelEv
label, ok := user.apiLabels[event.ID] label, ok := user.apiLabels[event.ID]
if !ok { if !ok {
return fmt.Errorf("label %q does not exist", event.ID) delete(user.apiLabels, event.ID)
} }
delete(user.apiLabels, event.ID)
for _, updateCh := range user.updateCh { for _, updateCh := range user.updateCh {
updateCh.Enqueue(imap.NewMailboxDeleted(imap.MailboxID(event.ID))) updateCh.Enqueue(imap.NewMailboxDeleted(imap.MailboxID(event.ID)))
} }