mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 16:17:03 +00:00
fix(BRIDGE-336): check and create all labels in Gluon on Bridge start
This commit is contained in:
@ -111,39 +111,6 @@ func (s *SyncUpdateApplier) ApplySyncUpdates(ctx context.Context, updates []sync
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SyncUpdateApplier) SyncSystemLabelsOnly(ctx context.Context, labels map[string]proton.Label) error {
|
|
||||||
request := func(ctx context.Context, _ usertypes.AddressMode, connectors map[string]*Connector) ([]imap.Update, error) {
|
|
||||||
updates := make([]imap.Update, 0, len(labels)*len(connectors))
|
|
||||||
for _, label := range labels {
|
|
||||||
if !WantLabel(label) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if label.Type != proton.LabelTypeSystem {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range connectors {
|
|
||||||
update := newSystemMailboxCreatedUpdate(imap.MailboxID(label.ID), label.Name)
|
|
||||||
updates = append(updates, update)
|
|
||||||
c.publishUpdate(ctx, update)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return updates, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
updates, err := s.sendRequest(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := waitOnIMAPUpdates(ctx, updates); err != nil {
|
|
||||||
return fmt.Errorf("could not sync system labels: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SyncUpdateApplier) SyncLabels(ctx context.Context, labels map[string]proton.Label) error {
|
func (s *SyncUpdateApplier) SyncLabels(ctx context.Context, labels map[string]proton.Label) error {
|
||||||
request := func(ctx context.Context, _ usertypes.AddressMode, connectors map[string]*Connector) ([]imap.Update, error) {
|
request := func(ctx context.Context, _ usertypes.AddressMode, connectors map[string]*Connector) ([]imap.Update, error) {
|
||||||
return syncLabels(ctx, labels, maps.Values(connectors))
|
return syncLabels(ctx, labels, maps.Values(connectors))
|
||||||
|
|||||||
@ -138,11 +138,10 @@ func (t *Handler) run(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if syncStatus.IsComplete() {
|
if syncStatus.IsComplete() {
|
||||||
t.log.Info("Sync already complete, only system labels will be updated")
|
t.log.Info("Sync already complete, updating labels")
|
||||||
|
|
||||||
if err := updateApplier.SyncSystemLabelsOnly(ctx, labels); err != nil {
|
|
||||||
t.log.WithError(err).Error("Failed to sync system labels")
|
|
||||||
|
|
||||||
|
if err := updateApplier.SyncLabels(ctx, labels); err != nil {
|
||||||
|
t.log.WithError(err).Error("Failed to sync labels")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,8 +74,7 @@ func TestTask_NoStateAndSucceeds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
call1 := tt.updateApplier.EXPECT().SyncLabels(gomock.Any(), gomock.Eq(labels)).Times(1).Return(nil)
|
tt.updateApplier.EXPECT().SyncLabels(gomock.Any(), gomock.Eq(labels)).Times(2).Return(nil)
|
||||||
tt.updateApplier.EXPECT().SyncSystemLabelsOnly(gomock.Any(), gomock.Eq(labels)).After(call1).Times(1).Return(nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -203,7 +202,7 @@ func TestTask_StateHasSyncedState(t *testing.T) {
|
|||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
tt.updateApplier.EXPECT().SyncSystemLabelsOnly(gomock.Any(), gomock.Eq(labels)).Return(nil)
|
tt.updateApplier.EXPECT().SyncLabels(gomock.Any(), gomock.Eq(labels)).Return(nil)
|
||||||
|
|
||||||
err := tt.task.run(context.Background(), tt.syncReporter, labels, tt.updateApplier, tt.messageBuilder)
|
err := tt.task.run(context.Background(), tt.syncReporter, labels, tt.updateApplier, tt.messageBuilder)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@ -80,7 +80,6 @@ type MessageBuilder interface {
|
|||||||
|
|
||||||
type UpdateApplier interface {
|
type UpdateApplier interface {
|
||||||
ApplySyncUpdates(ctx context.Context, updates []BuildResult) error
|
ApplySyncUpdates(ctx context.Context, updates []BuildResult) error
|
||||||
SyncSystemLabelsOnly(ctx context.Context, labels map[string]proton.Label) error
|
|
||||||
SyncLabels(ctx context.Context, labels map[string]proton.Label) error
|
SyncLabels(ctx context.Context, labels map[string]proton.Label) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -548,20 +548,6 @@ func (mr *MockUpdateApplierMockRecorder) SyncLabels(arg0, arg1 interface{}) *gom
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncLabels", reflect.TypeOf((*MockUpdateApplier)(nil).SyncLabels), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncLabels", reflect.TypeOf((*MockUpdateApplier)(nil).SyncLabels), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncSystemLabelsOnly mocks base method.
|
|
||||||
func (m *MockUpdateApplier) SyncSystemLabelsOnly(arg0 context.Context, arg1 map[string]proton.Label) error {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
ret := m.ctrl.Call(m, "SyncSystemLabelsOnly", arg0, arg1)
|
|
||||||
ret0, _ := ret[0].(error)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
// SyncSystemLabelsOnly indicates an expected call of SyncSystemLabelsOnly.
|
|
||||||
func (mr *MockUpdateApplierMockRecorder) SyncSystemLabelsOnly(arg0, arg1 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncSystemLabelsOnly", reflect.TypeOf((*MockUpdateApplier)(nil).SyncSystemLabelsOnly), arg0, arg1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MockMessageBuilder is a mock of MessageBuilder interface.
|
// MockMessageBuilder is a mock of MessageBuilder interface.
|
||||||
type MockMessageBuilder struct {
|
type MockMessageBuilder struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
|
|||||||
Reference in New Issue
Block a user