matrixfmt,telegramfmt: correctly bridge mentions of other logged-in users

This commit is contained in:
Tulir Asokan
2026-04-02 23:56:08 +03:00
parent 693ced7dea
commit 835afb0100
5 changed files with 32 additions and 12 deletions
+17 -4
View File
@@ -236,6 +236,8 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
// FIXME this should look for user logins by ID, not hardcode the current user
if id == client.telegramUserID {
userInfo.MXID = client.userLogin.UserMXID
} else if login := tc.Bridge.GetCachedUserLoginByID(ids.MakeUserLoginID(id)); login != nil {
userInfo.MXID = login.UserMXID
}
return userInfo, nil
},
@@ -250,6 +252,8 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
userInfo := telegramfmt.UserInfo{MXID: ghost.Intent.GetMXID(), Name: ghost.Name}
if ghost.ID == client.userID {
userInfo.MXID = client.userLogin.UserMXID
} else if login := tc.Bridge.GetCachedUserLoginByID(ids.MakeUserLoginID(userID)); login != nil {
userInfo.MXID = login.UserMXID
}
return userInfo, nil
}
@@ -334,10 +338,19 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
}
client.matrixParser = &matrixfmt.HTMLParser{
Store: tc.Store,
GetGhostDetails: func(ctx context.Context, ui id.UserID) (networkid.UserID, string, int64, bool) {
if userID, ok := tc.Bridge.Matrix.ParseGhostMXID(ui); !ok {
return "", "", 0, false
} else if peerType, telegramUserID, err := ids.ParseUserID(userID); err != nil {
GetGhostDetails: func(ctx context.Context, portal *bridgev2.Portal, ui id.UserID) (networkid.UserID, string, int64, bool) {
userID, ok := tc.Bridge.Matrix.ParseGhostMXID(ui)
if !ok {
user, err := tc.Bridge.GetExistingUserByMXID(ctx, ui)
if err != nil {
return "", "", 0, false
} else if login, _, _ := portal.FindPreferredLogin(ctx, user, false); login != nil {
userID = ids.UserLoginIDToUserID(login.ID)
} else {
return "", "", 0, false
}
}
if peerType, telegramUserID, err := ids.ParseUserID(userID); err != nil {
return "", "", 0, false
} else if accessHash, err := client.ScopedStore.GetAccessHash(ctx, peerType, telegramUserID); err != nil || accessHash == 0 {
return "", "", 0, false