config: re-add displayname template

Fixes #1057
This commit is contained in:
Tulir Asokan
2026-04-03 15:09:36 +03:00
parent 9b92aa3d50
commit cbff082e4d
8 changed files with 73 additions and 47 deletions
+12 -9
View File
@@ -42,7 +42,6 @@ import (
"go.mau.fi/mautrix-telegram/pkg/connector/media"
"go.mau.fi/mautrix-telegram/pkg/connector/store"
"go.mau.fi/mautrix-telegram/pkg/connector/tljson"
"go.mau.fi/mautrix-telegram/pkg/connector/util"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)
@@ -728,13 +727,7 @@ func (t *TelegramClient) onUserName(ctx context.Context, e tg.Entities, update *
var userInfo bridgev2.UserInfo
name := util.FormatFullName(update.FirstName, update.LastName, false, update.UserID)
userInfo.Name = &name
if meta.ContactSource != 0 && meta.ContactSource != t.telegramUserID && !t.main.Config.ContactNames {
// TODO fetch full info to accurately detect if the user is a contact or not
userInfo.Name = nil
}
var firstUsername string
if len(update.Usernames) > 0 {
for _, ident := range ghost.Identifiers {
if !strings.HasPrefix(ident, "telegram:") {
@@ -742,7 +735,10 @@ func (t *TelegramClient) onUserName(ctx context.Context, e tg.Entities, update *
}
}
for _, username := range update.Usernames {
for i, username := range update.Usernames {
if i == 0 {
firstUsername = username.Username
}
userInfo.Identifiers = append(userInfo.Identifiers, fmt.Sprintf("telegram:%s", username.Username))
}
@@ -750,6 +746,13 @@ func (t *TelegramClient) onUserName(ctx context.Context, e tg.Entities, update *
userInfo.Identifiers = slices.Compact(userInfo.Identifiers)
}
name := t.main.Config.FormatDisplayname(update.FirstName, update.LastName, firstUsername, false, update.UserID)
userInfo.Name = &name
if meta.ContactSource != 0 && meta.ContactSource != t.telegramUserID && !t.main.Config.ContactNames {
// TODO fetch full info to accurately detect if the user is a contact or not
userInfo.Name = nil
}
ghost.UpdateInfo(ctx, &userInfo)
if ghost.ID == t.userID {
var firstUsername string