mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/matrixinvite: allow redirecting created DM to no ghost
This commit is contained in:
parent
e805815e41
commit
1cd285dee0
2 changed files with 10 additions and 4 deletions
|
|
@ -221,6 +221,7 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
|
|||
rejectInvite(ctx, evt, br.Bot, "")
|
||||
return EventHandlingResultSuccess
|
||||
}
|
||||
overrideIntent := invitedGhost.Intent
|
||||
if resp.DMRedirectedTo != "" && resp.DMRedirectedTo != invitedGhost.ID {
|
||||
log.Debug().
|
||||
Str("dm_redirected_to_id", string(resp.DMRedirectedTo)).
|
||||
|
|
@ -234,11 +235,13 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
|
|||
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 {
|
||||
if resp.DMRedirectedTo != SpecialValueDMRedirectedToBot {
|
||||
overrideIntent = br.Bot
|
||||
} else if otherUserGhost, err := br.GetGhostByID(ctx, resp.DMRedirectedTo); err != nil {
|
||||
log.Err(err).Msg("Failed to get ghost of real portal other user ID")
|
||||
} else {
|
||||
invitedGhost = otherUserGhost
|
||||
overrideIntent = otherUserGhost.Intent
|
||||
}
|
||||
}
|
||||
err = portal.UpdateMatrixRoomID(ctx, evt.RoomID, UpdateMatrixRoomIDParams{
|
||||
|
|
@ -251,7 +254,7 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
|
|||
})
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to update Matrix room ID for new DM portal")
|
||||
sendNotice(ctx, evt, invitedGhost.Intent, "Failed to finish configuring portal. The chat may or may not work")
|
||||
sendNotice(ctx, evt, overrideIntent, "Failed to finish configuring portal. The chat may or may not work")
|
||||
return EventHandlingResultSuccess
|
||||
}
|
||||
message := "Private chat portal created"
|
||||
|
|
@ -263,7 +266,7 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
|
|||
message += fmt.Sprintf("\n\nWarning: %s", err.Error())
|
||||
}
|
||||
}
|
||||
sendNotice(ctx, evt, invitedGhost.Intent, message)
|
||||
sendNotice(ctx, evt, overrideIntent, message)
|
||||
return EventHandlingResultSuccess
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/configupgrade"
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/util/random"
|
||||
|
||||
"maunium.net/go/mautrix/bridgev2/database"
|
||||
"maunium.net/go/mautrix/bridgev2/networkid"
|
||||
|
|
@ -724,6 +725,8 @@ type ResolveIdentifierResponse struct {
|
|||
Chat *CreateChatResponse
|
||||
}
|
||||
|
||||
var SpecialValueDMRedirectedToBot = networkid.UserID("__fi.mau.bridgev2.dm_redirected_to_bot::" + random.String(10))
|
||||
|
||||
type CreateChatResponse struct {
|
||||
PortalKey networkid.PortalKey
|
||||
// Portal and PortalInfo are not required, the caller will fetch them automatically based on PortalKey if necessary.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue