Check that relaybot is logged in before relaying messages

This commit is contained in:
Tulir Asokan 2023-11-12 16:17:13 +02:00
parent 5ffb20b85b
commit 2767819ae0
2 changed files with 6 additions and 1 deletions

View file

@ -37,6 +37,7 @@ var (
errUserNotConnected = errors.New("you are not connected to WhatsApp")
errDifferentUser = errors.New("user is not the recipient of this private chat portal")
errUserNotLoggedIn = errors.New("user is not logged in and chat has no relay bot")
errRelaybotNotLoggedIn = errors.New("neither user nor relay bot of chat are logged in")
errMNoticeDisabled = errors.New("bridging m.notice messages is disabled")
errUnexpectedParsedContentType = errors.New("unexpected parsed content type")
errInvalidGeoURI = errors.New("invalid `geo:` URI in message")
@ -111,7 +112,8 @@ func errorToStatusReason(err error) (reason event.MessageStatusReason, status ev
errors.Is(err, errUserNotConnected):
return event.MessageStatusGenericError, event.MessageStatusRetriable, true, true, ""
case errors.Is(err, errUserNotLoggedIn),
errors.Is(err, errDifferentUser):
errors.Is(err, errDifferentUser),
errors.Is(err, errRelaybotNotLoggedIn):
return event.MessageStatusGenericError, event.MessageStatusRetriable, true, false, ""
case errors.Is(err, errMessageDisconnected),
errors.Is(err, errMessageRetryDisconnected):

View file

@ -4237,6 +4237,9 @@ func (portal *Portal) convertMatrixMessage(ctx context.Context, sender *User, ev
return nil, sender, extraMeta, errUserNotLoggedIn
}
sender = portal.GetRelayUser()
if !sender.IsLoggedIn() {
return nil, sender, extraMeta, errRelaybotNotLoggedIn
}
isRelay = true
}
var editRootMsg *database.Message