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
+7 -1
View File
@@ -301,12 +301,14 @@ func (t *TelegramClient) getUserInfoFromTelegramUser(u tg.UserClass) (*bridgev2.
return nil, fmt.Errorf("user is %T not *tg.User", user) return nil, fmt.Errorf("user is %T not *tg.User", user)
} }
var identifiers []string var identifiers []string
if !user.Min {
for _, username := range user.Usernames { for _, username := range user.Usernames {
identifiers = append(identifiers, fmt.Sprintf("telegram:%s", username.Username)) identifiers = append(identifiers, fmt.Sprintf("telegram:%s", username.Username))
} }
if phone, ok := user.GetPhone(); ok { if phone, ok := user.GetPhone(); ok {
identifiers = append(identifiers, fmt.Sprintf("tel:+%s", strings.TrimPrefix(phone, "+"))) identifiers = append(identifiers, fmt.Sprintf("tel:+%s", strings.TrimPrefix(phone, "+")))
} }
}
var avatar *bridgev2.Avatar var avatar *bridgev2.Avatar
if p, ok := user.GetPhoto(); ok && p.TypeID() == tg.UserProfilePhotoTypeID { if p, ok := user.GetPhoto(); ok && p.TypeID() == tg.UserProfilePhotoTypeID {
@@ -328,8 +330,12 @@ func (t *TelegramClient) getUserInfoFromTelegramUser(u tg.UserClass) (*bridgev2.
Identifiers: identifiers, Identifiers: identifiers,
ExtraUpdates: func(ctx context.Context, ghost *bridgev2.Ghost) (changed bool) { ExtraUpdates: func(ctx context.Context, ghost *bridgev2.Ghost) (changed bool) {
meta := ghost.Metadata.(*GhostMetadata) meta := ghost.Metadata.(*GhostMetadata)
changed = meta.IsPremium != user.Premium || meta.AccessHash != user.AccessHash if !user.Min {
changed = changed || meta.IsPremium != user.Premium || meta.IsBot != user.Bot
meta.IsPremium = user.Premium meta.IsPremium = user.Premium
meta.IsBot = user.Bot
}
changed = changed || meta.AccessHash != user.AccessHash
meta.AccessHash = user.AccessHash meta.AccessHash = user.AccessHash
return changed return changed
}, },
+1
View File
@@ -89,6 +89,7 @@ func (tg *TelegramConnector) GetDBMetaTypes() database.MetaTypes {
type GhostMetadata struct { type GhostMetadata struct {
IsPremium bool `json:"is_premium"` IsPremium bool `json:"is_premium"`
IsBot bool `json:"is_bot"`
AccessHash int64 `json:"access_hash"` AccessHash int64 `json:"access_hash"`
} }