bridgev2/matrixinvite: allow redirecting DM creations to another user

This commit is contained in:
Tulir Asokan 2025-06-14 12:21:05 +03:00
commit c888801751
2 changed files with 23 additions and 0 deletions

View file

@ -187,6 +187,26 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
message += "\n\nWarning: failed to promote bot"
hasWarning = true
}
if resp.DMRedirectedTo != "" && resp.DMRedirectedTo != invitedGhost.ID {
log.Debug().
Str("dm_redirected_to_id", string(resp.DMRedirectedTo)).
Msg("Created DM was redirected to another user ID")
_, err = invitedGhost.Intent.SendState(ctx, portal.MXID, event.StateMember, invitedGhost.Intent.GetMXID().String(), &event.Content{
Parsed: &event.MemberEventContent{
Membership: event.MembershipLeave,
Reason: "Direct chat redirected to another internal user ID",
},
}, time.Time{})
if err != nil {
log.Err(err).Msg("Failed to make incorrect ghost leave new DM room")
}
otherUserGhost, err := br.GetGhostByID(ctx, resp.DMRedirectedTo)
if err != nil {
log.Err(err).Msg("Failed to get ghost of real portal other user ID")
} else {
invitedGhost = otherUserGhost
}
}
if resp.PortalInfo != nil {
portal.UpdateInfo(ctx, resp.PortalInfo, sourceLogin, nil, time.Time{})
} else {

View file

@ -696,6 +696,9 @@ type CreateChatResponse struct {
// Portal and PortalInfo are not required, the caller will fetch them automatically based on PortalKey if necessary.
Portal *Portal
PortalInfo *ChatInfo
// If a start DM request (CreateChatWithGhost or ResolveIdentifier) returns the DM to a different user,
// this field should have the user ID of said different user.
DMRedirectedTo networkid.UserID
}
// IdentifierResolvingNetworkAPI is an optional interface that network connectors can implement to support starting new direct chats.