mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/portal: handle portal deletion edge cases
This commit is contained in:
parent
efd4136c7a
commit
9e3fa96fb4
3 changed files with 10 additions and 3 deletions
|
|
@ -39,6 +39,7 @@ var ErrNotLoggedIn = errors.New("not logged in")
|
|||
var ErrDirectMediaNotEnabled = errors.New("direct media is not enabled")
|
||||
|
||||
var ErrPortalIsDeleted = errors.New("portal is deleted")
|
||||
var ErrPortalNotFoundInEventHandler = errors.New("portal not found to handle remote event")
|
||||
|
||||
// Common message status errors
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -5195,6 +5195,9 @@ func (portal *Portal) addToUserSpaces(ctx context.Context) {
|
|||
}
|
||||
|
||||
func (portal *Portal) Delete(ctx context.Context) error {
|
||||
if portal.deleted.IsSet() {
|
||||
return nil
|
||||
}
|
||||
portal.removeInPortalCache(ctx)
|
||||
err := portal.Bridge.DB.Portal.Delete(ctx, portal.PortalKey)
|
||||
if err != nil {
|
||||
|
|
@ -5254,6 +5257,9 @@ func (portal *Portal) unlockedDelete(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (portal *Portal) unlockedDeleteCache() {
|
||||
if portal.deleted.IsSet() {
|
||||
return
|
||||
}
|
||||
delete(portal.Bridge.portalsByKey, portal.PortalKey)
|
||||
if portal.MXID != "" {
|
||||
delete(portal.Bridge.portalsByMXID, portal.MXID)
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ func (ul *UserLogin) QueueRemoteEvent(evt RemoteEvent) EventHandlingResult {
|
|||
return ul.Bridge.QueueRemoteEvent(ul, evt)
|
||||
}
|
||||
|
||||
func (br *Bridge) QueueRemoteEvent(login *UserLogin, evt RemoteEvent) (res EventHandlingResult) {
|
||||
func (br *Bridge) QueueRemoteEvent(login *UserLogin, evt RemoteEvent) EventHandlingResult {
|
||||
log := login.Log
|
||||
ctx := log.WithContext(br.BackgroundCtx)
|
||||
maybeUncertain, ok := evt.(RemoteEventWithUncertainPortalReceiver)
|
||||
|
|
@ -236,14 +236,14 @@ func (br *Bridge) QueueRemoteEvent(login *UserLogin, evt RemoteEvent) (res Event
|
|||
if err != nil {
|
||||
log.Err(err).Object("portal_key", key).Bool("uncertain_receiver", isUncertain).
|
||||
Msg("Failed to get portal to handle remote event")
|
||||
return
|
||||
return EventHandlingResultFailed.WithError(fmt.Errorf("failed to get portal: %w", err))
|
||||
} else if portal == nil {
|
||||
log.Warn().
|
||||
Stringer("event_type", evt.GetType()).
|
||||
Object("portal_key", key).
|
||||
Bool("uncertain_receiver", isUncertain).
|
||||
Msg("Portal not found to handle remote event")
|
||||
return
|
||||
return EventHandlingResultFailed.WithError(ErrPortalNotFoundInEventHandler)
|
||||
}
|
||||
// TODO put this in a better place, and maybe cache to avoid constant db queries
|
||||
login.MarkInPortal(ctx, portal)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue