Don't panic on Matrix message when user isn't logged in

This commit is contained in:
Tulir Asokan 2023-09-07 17:21:15 +03:00
parent 15015f280e
commit 1b7f876b44
2 changed files with 12 additions and 0 deletions

View file

@ -46,6 +46,9 @@ var (
errMediaDecryptFailed = errors.New("failed to decrypt media") errMediaDecryptFailed = errors.New("failed to decrypt media")
errMediaReuploadFailed = errors.New("failed to upload media to google") errMediaReuploadFailed = errors.New("failed to upload media to google")
errIncorrectUser = errors.New("incorrect user")
errNotLoggedIn = errors.New("not logged in")
errMessageTakingLong = errors.New("bridging the message is taking longer than usual") errMessageTakingLong = errors.New("bridging the message is taking longer than usual")
) )
@ -84,6 +87,8 @@ func errorToStatusReason(err error) (reason event.MessageStatusReason, status ev
case errors.Is(err, errUnexpectedParsedContentType), case errors.Is(err, errUnexpectedParsedContentType),
errors.Is(err, errUnknownMsgType): errors.Is(err, errUnknownMsgType):
return event.MessageStatusUnsupported, event.MessageStatusFail, true, true, "" return event.MessageStatusUnsupported, event.MessageStatusFail, true, true, ""
case errors.Is(err, errIncorrectUser), errors.Is(err, errNotLoggedIn):
return event.MessageStatusUnsupported, event.MessageStatusFail, true, true, err.Error()
case errors.Is(err, errMNoticeDisabled): case errors.Is(err, errMNoticeDisabled):
return event.MessageStatusUnsupported, event.MessageStatusFail, true, false, "" return event.MessageStatusUnsupported, event.MessageStatusFail, true, false, ""
case errors.Is(err, errMediaUnsupportedType): case errors.Is(err, errMediaUnsupportedType):

View file

@ -312,6 +312,13 @@ func (portal *Portal) handleMessageLoopItem(msg PortalMessage) {
} }
func (portal *Portal) handleMatrixMessageLoopItem(msg PortalMatrixMessage) { func (portal *Portal) handleMatrixMessageLoopItem(msg PortalMatrixMessage) {
if msg.user.RowID != portal.Receiver {
go portal.sendMessageMetrics(msg.user, msg.evt, errIncorrectUser, "Ignoring", nil)
return
} else if msg.user.Client == nil {
go portal.sendMessageMetrics(msg.user, msg.evt, errNotLoggedIn, "Ignoring", nil)
return
}
portal.forwardBackfillLock.Lock() portal.forwardBackfillLock.Lock()
defer portal.forwardBackfillLock.Unlock() defer portal.forwardBackfillLock.Unlock()
evtTS := time.UnixMilli(msg.evt.Timestamp) evtTS := time.UnixMilli(msg.evt.Timestamp)