tomatrix: use channel ghost if portal not found

This commit is contained in:
Tulir Asokan
2026-03-29 13:33:25 +03:00
parent 4a538f77ef
commit 8bd4ff8f82
2 changed files with 18 additions and 2 deletions
+16 -1
View File
@@ -273,8 +273,10 @@ func (t *TelegramClient) addForwardHeader(ctx context.Context, part *bridgev2.Co
)
case *tg.PeerChannel, *tg.PeerChat:
unknownType := "unknown chat"
if _, ok := from.(*tg.PeerChannel); ok {
var channelID int64
if ch, ok := from.(*tg.PeerChannel); ok {
unknownType = "unknown channel"
channelID = ch.ChannelID
}
portal, err := t.main.Bridge.GetExistingPortalByKey(ctx, t.makePortalKeyFromPeer(from, 0))
if err != nil {
@@ -293,6 +295,19 @@ func (t *TelegramClient) addForwardHeader(ctx context.Context, part *bridgev2.Co
fwdFromText = unknownType
fwdFromHTML = unknownType
}
if channelID != 0 && fwdFromText == unknownType {
ghost, err := t.main.Bridge.GetExistingGhostByID(ctx, ids.MakeChannelUserID(channelID))
if err != nil {
return err
} else if ghost != nil && ghost.Name != "" {
fwdFromText = ghost.Name
fwdFromHTML = fmt.Sprintf(
`<a href="%s">%s</a>`,
ghost.Intent.GetMXID().URI().MatrixToURL(),
html.EscapeString(fwdFromText),
)
}
}
// TODO fetch channel if not found
}
if fwdFromText == "" && fwd.FromName != "" {