diff --git a/imessage.go b/imessage.go index e85ae37..985c7fa 100644 --- a/imessage.go +++ b/imessage.go @@ -38,6 +38,7 @@ func init() { "im-ids-not-registered": "Missing iMessage registration.", "im-ids-refresh-credentials": "Credentials expired. Please use the Reconnect button to log in again.", "im-nacserv-not-configured": "Please enter an iMessage registration code to use the bridge.", + "im-nacserv-fail": "Registration provider couldn't be reached when trying to reregister with iMessage.", }) } @@ -68,6 +69,8 @@ func (user *User) HandleEvent(evt any) { user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnected}) case *direct.IDSRegisterFail: user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Error: "im-ids-register-fail"}) + case *direct.NACServFail: + user.BridgeState.Send(status.BridgeState{StateEvent: status.StateBadCredentials, Error: "im-nacserv-fail"}) case *direct.RefreshCredentialsRequired: user.BridgeState.Send(status.BridgeState{ StateEvent: status.StateBadCredentials, diff --git a/imessage/direct/connector.go b/imessage/direct/connector.go index fffe748..4884e86 100644 --- a/imessage/direct/connector.go +++ b/imessage/direct/connector.go @@ -235,6 +235,12 @@ func (dc *Connector) RegisterIDS(ctx context.Context, forceRegister bool) error if errors.Is(err, types.ErrActionRefreshCredentials) { err = nil + } else if errors.Is(err, nacserv.ErrProviderNotReachable) { + dc.EventHandler(&NACServFail{err}) + dc.nextReregisterCheck = time.Now().Add(1 * time.Hour) + dc.reregisterTicker.Reset(1 * time.Hour) + zerolog.Ctx(ctx).Debug(). + Msg("Reset reregister ticker to retry in an hour after nacserv error") } else if err != nil { dc.EventHandler(&IDSRegisterFail{err}) } else { @@ -829,8 +835,7 @@ func (dc *Connector) handleAPNSMessage(ctx context.Context, payload *apns.SendMe log.Debug().Msg("Re-fetching own handles due to c:130 from self") err = dc.RegisterIDS(ctx, false) if err != nil { - log.Err(err).Msg("Error re-registering IDS") - dc.EventHandler(&IDSRegisterFail{err}) + log.Err(err).Msg("Error re-registering IDS after c:130") } // TODO broadcast handle to recent entries in IDS cache (without looking up anyone)? } @@ -890,6 +895,7 @@ type RefreshCredentialsRequired struct { type IDSRegisterFail struct { Error error } +type NACServFail IDSRegisterFail type BridgeInfoUpdated struct{} type HandlesUpdated struct { OldHandles []uri.ParsedURI