ghost: improve metadata handling

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans
2024-08-05 13:06:34 -06:00
parent e8b5d286dc
commit b539e5d63d
2 changed files with 14 additions and 7 deletions
+13 -7
View File
@@ -301,11 +301,13 @@ func (t *TelegramClient) getUserInfoFromTelegramUser(u tg.UserClass) (*bridgev2.
return nil, fmt.Errorf("user is %T not *tg.User", user)
}
var identifiers []string
for _, username := range user.Usernames {
identifiers = append(identifiers, fmt.Sprintf("telegram:%s", username.Username))
}
if phone, ok := user.GetPhone(); ok {
identifiers = append(identifiers, fmt.Sprintf("tel:+%s", strings.TrimPrefix(phone, "+")))
if !user.Min {
for _, username := range user.Usernames {
identifiers = append(identifiers, fmt.Sprintf("telegram:%s", username.Username))
}
if phone, ok := user.GetPhone(); ok {
identifiers = append(identifiers, fmt.Sprintf("tel:+%s", strings.TrimPrefix(phone, "+")))
}
}
var avatar *bridgev2.Avatar
@@ -328,8 +330,12 @@ func (t *TelegramClient) getUserInfoFromTelegramUser(u tg.UserClass) (*bridgev2.
Identifiers: identifiers,
ExtraUpdates: func(ctx context.Context, ghost *bridgev2.Ghost) (changed bool) {
meta := ghost.Metadata.(*GhostMetadata)
changed = meta.IsPremium != user.Premium || meta.AccessHash != user.AccessHash
meta.IsPremium = user.Premium
if !user.Min {
changed = changed || meta.IsPremium != user.Premium || meta.IsBot != user.Bot
meta.IsPremium = user.Premium
meta.IsBot = user.Bot
}
changed = changed || meta.AccessHash != user.AccessHash
meta.AccessHash = user.AccessHash
return changed
},
+1
View File
@@ -89,6 +89,7 @@ func (tg *TelegramConnector) GetDBMetaTypes() database.MetaTypes {
type GhostMetadata struct {
IsPremium bool `json:"is_premium"`
IsBot bool `json:"is_bot"`
AccessHash int64 `json:"access_hash"`
}