userinfo: sync ghost info for non-broadcast channels too
This commit is contained in:
@@ -818,47 +818,14 @@ func (t *TelegramClient) updateGhost(ctx context.Context, userID int64, user *tg
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) updateChannel(ctx context.Context, channel *tg.Channel) (*bridgev2.UserInfo, error) {
|
func (t *TelegramClient) updateChannel(ctx context.Context, channel *tg.Channel) (*bridgev2.UserInfo, error) {
|
||||||
if accessHash, ok := channel.GetAccessHash(); ok && !channel.Min {
|
|
||||||
if err := t.ScopedStore.SetAccessHash(ctx, ids.PeerTypeChannel, channel.ID, accessHash); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO resync portal metadata?
|
// TODO resync portal metadata?
|
||||||
|
userInfo, err := t.wrapChannelGhostInfo(ctx, channel)
|
||||||
if !channel.Broadcast {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the channel ghost if this is a broadcast channel.
|
|
||||||
ghost, err := t.main.Bridge.GetGhostByID(ctx, ids.MakeChannelUserID(channel.ID))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ghost, err := t.main.Bridge.GetGhostByID(ctx, ids.MakeChannelUserID(channel.ID))
|
||||||
var avatar *bridgev2.Avatar
|
if err != nil {
|
||||||
if photo, ok := channel.GetPhoto().(*tg.ChatPhoto); ok {
|
return nil, err
|
||||||
avatar, err = t.convertChatPhoto(channel.AsInputPeer(), photo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if username, set := channel.GetUsername(); set {
|
|
||||||
err := t.main.Store.Username.Set(ctx, ids.PeerTypeChannel, channel.ID, username)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
userInfo := &bridgev2.UserInfo{
|
|
||||||
Name: &channel.Title,
|
|
||||||
Avatar: avatar,
|
|
||||||
ExtraUpdates: func(ctx context.Context, g *bridgev2.Ghost) bool {
|
|
||||||
updated := !g.Metadata.(*GhostMetadata).IsChannel
|
|
||||||
g.Metadata.(*GhostMetadata).IsChannel = true
|
|
||||||
return updated
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
ghost.UpdateInfo(ctx, userInfo)
|
ghost.UpdateInfo(ctx, userInfo)
|
||||||
return userInfo, nil
|
return userInfo, nil
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ func (tg *TelegramConnector) GetDBMetaTypes() database.MetaTypes {
|
|||||||
|
|
||||||
type GhostMetadata struct {
|
type GhostMetadata struct {
|
||||||
IsPremium bool `json:"is_premium,omitempty"`
|
IsPremium bool `json:"is_premium,omitempty"`
|
||||||
IsChannel bool `json:"is_channel,omitempty"`
|
|
||||||
Deleted bool `json:"deleted,omitempty"`
|
Deleted bool `json:"deleted,omitempty"`
|
||||||
NotMin bool `json:"not_min,omitempty"`
|
NotMin bool `json:"not_min,omitempty"`
|
||||||
|
|
||||||
|
|||||||
@@ -187,10 +187,6 @@ func (t *TelegramClient) wrapChannelGhostInfo(ctx context.Context, channel *tg.C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !channel.Broadcast {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var avatar *bridgev2.Avatar
|
var avatar *bridgev2.Avatar
|
||||||
avatar, err = t.convertChatPhoto(channel.AsInputPeer(), channel.GetPhoto())
|
avatar, err = t.convertChatPhoto(channel.AsInputPeer(), channel.GetPhoto())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -210,11 +206,6 @@ func (t *TelegramClient) wrapChannelGhostInfo(ctx context.Context, channel *tg.C
|
|||||||
Name: &channel.Title,
|
Name: &channel.Title,
|
||||||
Avatar: avatar,
|
Avatar: avatar,
|
||||||
Identifiers: identifiers,
|
Identifiers: identifiers,
|
||||||
ExtraUpdates: func(ctx context.Context, g *bridgev2.Ghost) bool {
|
|
||||||
updated := !g.Metadata.(*GhostMetadata).IsChannel
|
|
||||||
g.Metadata.(*GhostMetadata).IsChannel = true
|
|
||||||
return updated
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user