metadata: gate setting DM portal metadata behind config option
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
+49
-45
@@ -206,13 +206,12 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var name, topic *string
|
chatInfo := bridgev2.ChatInfo{
|
||||||
roomType := database.RoomTypeDM
|
Type: ptr.Ptr(database.RoomTypeDM),
|
||||||
memberList := &bridgev2.ChatMemberList{
|
Members: &bridgev2.ChatMemberList{
|
||||||
IsFull: true, // TODO not true for channels
|
IsFull: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
var avatar *bridgev2.Avatar
|
|
||||||
var disappearingSetting *database.DisappearingSetting
|
|
||||||
|
|
||||||
switch peerType {
|
switch peerType {
|
||||||
case ids.PeerTypeUser:
|
case ids.PeerTypeUser:
|
||||||
@@ -223,36 +222,48 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
return nil, fmt.Errorf("failed to get user info for user %d", id)
|
return nil, fmt.Errorf("failed to get user info for user %d", id)
|
||||||
}
|
}
|
||||||
if user, ok := users[0].(*tg.User); !ok {
|
user, ok := users[0].(*tg.User)
|
||||||
|
if !ok {
|
||||||
return nil, fmt.Errorf("returned user is not *tg.User")
|
return nil, fmt.Errorf("returned user is not *tg.User")
|
||||||
|
}
|
||||||
|
userInfo, err := t.getUserInfoFromTelegramUser(user)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.main.Config.SetPrivateChatPortalMeta {
|
||||||
|
chatInfo.Name = userInfo.Name
|
||||||
|
chatInfo.Avatar = userInfo.Avatar
|
||||||
} else {
|
} else {
|
||||||
name = ptr.Ptr(util.FormatFullName(user.FirstName, user.LastName)) // TODO gate this behind a config?
|
chatInfo.Name = ptr.Ptr("")
|
||||||
t.updateGhost(ctx, id, user)
|
chatInfo.Avatar = &bridgev2.Avatar{Remove: true}
|
||||||
memberList.Members = []bridgev2.ChatMember{
|
}
|
||||||
{
|
|
||||||
EventSender: bridgev2.EventSender{
|
chatInfo.Members.Members = []bridgev2.ChatMember{
|
||||||
SenderLogin: ids.MakeUserLoginID(id),
|
{
|
||||||
Sender: ids.MakeUserID(id),
|
EventSender: bridgev2.EventSender{
|
||||||
},
|
SenderLogin: ids.MakeUserLoginID(id),
|
||||||
|
Sender: ids.MakeUserID(id),
|
||||||
},
|
},
|
||||||
{
|
UserInfo: userInfo,
|
||||||
EventSender: bridgev2.EventSender{
|
},
|
||||||
IsFromMe: true,
|
{
|
||||||
SenderLogin: t.loginID,
|
EventSender: bridgev2.EventSender{
|
||||||
Sender: t.userID,
|
IsFromMe: true,
|
||||||
},
|
SenderLogin: t.loginID,
|
||||||
|
Sender: t.userID,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
case ids.PeerTypeChat:
|
case ids.PeerTypeChat:
|
||||||
roomType = database.RoomTypeGroupDM
|
chatInfo.Type = ptr.Ptr(database.RoomTypeGroupDM)
|
||||||
fullChat, err := t.client.API().MessagesGetFullChat(ctx, id)
|
fullChat, err := t.client.API().MessagesGetFullChat(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, c := range fullChat.Chats {
|
for _, c := range fullChat.GetChats() {
|
||||||
if c.GetID() == id {
|
if c.GetID() == id {
|
||||||
name = &c.(*tg.Chat).Title
|
chatInfo.Name = &c.(*tg.Chat).Title
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,7 +274,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if photo, ok := chatFull.GetChatPhoto(); ok {
|
if photo, ok := chatFull.GetChatPhoto(); ok {
|
||||||
avatar = &bridgev2.Avatar{
|
chatInfo.Avatar = &bridgev2.Avatar{
|
||||||
ID: ids.MakeAvatarID(photo.GetID()),
|
ID: ids.MakeAvatarID(photo.GetID()),
|
||||||
Get: func(ctx context.Context) (data []byte, err error) {
|
Get: func(ctx context.Context) (data []byte, err error) {
|
||||||
data, _, err = media.NewTransferer(t.client.API()).WithPhoto(photo).Download(ctx)
|
data, _, err = media.NewTransferer(t.client.API()).WithPhoto(photo).Download(ctx)
|
||||||
@@ -273,14 +284,14 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ttl, ok := chatFull.GetTTLPeriod(); ok {
|
if ttl, ok := chatFull.GetTTLPeriod(); ok {
|
||||||
disappearingSetting = &database.DisappearingSetting{
|
chatInfo.Disappear = &database.DisappearingSetting{
|
||||||
Type: database.DisappearingTypeAfterSend,
|
Type: database.DisappearingTypeAfterSend,
|
||||||
Timer: time.Duration(ttl) * time.Second,
|
Timer: time.Duration(ttl) * time.Second,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if about := chatFull.GetAbout(); about != "" {
|
if about := chatFull.GetAbout(); about != "" {
|
||||||
topic = &about
|
chatInfo.Topic = &about
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range fullChat.GetUsers() {
|
for _, user := range fullChat.GetUsers() {
|
||||||
@@ -291,7 +302,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
|
|
||||||
if participants, ok := chatFull.Participants.(*tg.ChatParticipants); ok {
|
if participants, ok := chatFull.Participants.(*tg.ChatParticipants); ok {
|
||||||
for _, user := range participants.Participants {
|
for _, user := range participants.Participants {
|
||||||
memberList.Members = append(memberList.Members, bridgev2.ChatMember{
|
chatInfo.Members.Members = append(chatInfo.Members.Members, bridgev2.ChatMember{
|
||||||
EventSender: bridgev2.EventSender{
|
EventSender: bridgev2.EventSender{
|
||||||
IsFromMe: user.GetUserID() == t.telegramUserID,
|
IsFromMe: user.GetUserID() == t.telegramUserID,
|
||||||
SenderLogin: ids.MakeUserLoginID(user.GetUserID()),
|
SenderLogin: ids.MakeUserLoginID(user.GetUserID()),
|
||||||
@@ -301,6 +312,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ids.PeerTypeChannel:
|
case ids.PeerTypeChannel:
|
||||||
|
chatInfo.Type = ptr.Ptr(database.RoomTypeGroupDM) // TODO is this correct?
|
||||||
accessHash, found, err := t.ScopedStore.GetChannelAccessHash(ctx, t.telegramUserID, id)
|
accessHash, found, err := t.ScopedStore.GetChannelAccessHash(ctx, t.telegramUserID, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get channel access hash: %w", err)
|
return nil, fmt.Errorf("failed to get channel access hash: %w", err)
|
||||||
@@ -316,9 +328,9 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
if c.GetID() == id {
|
if c.GetID() == id {
|
||||||
switch chat := c.(type) {
|
switch chat := c.(type) {
|
||||||
case *tg.Chat:
|
case *tg.Chat:
|
||||||
name = &chat.Title
|
chatInfo.Name = &chat.Title
|
||||||
case *tg.Channel:
|
case *tg.Channel:
|
||||||
name = &chat.Title
|
chatInfo.Name = &chat.Title
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -330,7 +342,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if photo := channelFull.GetChatPhoto(); photo.TypeID() == tg.PhotoTypeID {
|
if photo := channelFull.GetChatPhoto(); photo.TypeID() == tg.PhotoTypeID {
|
||||||
avatar = &bridgev2.Avatar{
|
chatInfo.Avatar = &bridgev2.Avatar{
|
||||||
ID: ids.MakeAvatarID(photo.GetID()),
|
ID: ids.MakeAvatarID(photo.GetID()),
|
||||||
Get: func(ctx context.Context) (data []byte, err error) {
|
Get: func(ctx context.Context) (data []byte, err error) {
|
||||||
data, _, err = media.NewTransferer(t.client.API()).WithPhoto(photo).Download(ctx)
|
data, _, err = media.NewTransferer(t.client.API()).WithPhoto(photo).Download(ctx)
|
||||||
@@ -340,21 +352,21 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ttl, ok := channelFull.GetTTLPeriod(); ok {
|
if ttl, ok := channelFull.GetTTLPeriod(); ok {
|
||||||
disappearingSetting = &database.DisappearingSetting{
|
chatInfo.Disappear = &database.DisappearingSetting{
|
||||||
Type: database.DisappearingTypeAfterSend,
|
Type: database.DisappearingTypeAfterSend,
|
||||||
Timer: time.Duration(ttl) * time.Second,
|
Timer: time.Duration(ttl) * time.Second,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if about := channelFull.GetAbout(); about != "" {
|
if about := channelFull.GetAbout(); about != "" {
|
||||||
topic = &about
|
chatInfo.Topic = &about
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO save available reactions?
|
// TODO save available reactions?
|
||||||
// TODO save reactions limit?
|
// TODO save reactions limit?
|
||||||
// TODO save emojiset?
|
// TODO save emojiset?
|
||||||
|
|
||||||
memberList.IsFull = false
|
chatInfo.Members.IsFull = false
|
||||||
|
|
||||||
// TODO when do we have to make a request to get the participants?
|
// TODO when do we have to make a request to get the participants?
|
||||||
|
|
||||||
@@ -388,7 +400,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
memberList.Members = append(memberList.Members, bridgev2.ChatMember{
|
chatInfo.Members.Members = append(chatInfo.Members.Members, bridgev2.ChatMember{
|
||||||
EventSender: bridgev2.EventSender{
|
EventSender: bridgev2.EventSender{
|
||||||
IsFromMe: user.GetID() == t.telegramUserID,
|
IsFromMe: user.GetID() == t.telegramUserID,
|
||||||
SenderLogin: ids.MakeUserLoginID(user.GetID()),
|
SenderLogin: ids.MakeUserLoginID(user.GetID()),
|
||||||
@@ -403,15 +415,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
panic("unimplemented getchatinfo")
|
panic("unimplemented getchatinfo")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &bridgev2.ChatInfo{
|
return &chatInfo, nil
|
||||||
Name: name,
|
|
||||||
Topic: topic,
|
|
||||||
Avatar: avatar,
|
|
||||||
Members: memberList,
|
|
||||||
Type: &roomType,
|
|
||||||
|
|
||||||
Disappear: disappearingSetting,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error) {
|
func (t *TelegramClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error) {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ type TelegramConfig struct {
|
|||||||
AppID int `yaml:"app_id"`
|
AppID int `yaml:"app_id"`
|
||||||
AppHash string `yaml:"app_hash"`
|
AppHash string `yaml:"app_hash"`
|
||||||
|
|
||||||
|
SetPrivateChatPortalMeta bool `yaml:"set_private_chat_portal_meta"`
|
||||||
|
|
||||||
AnimatedSticker media.AnimatedStickerConfig `yaml:"animated_sticker"`
|
AnimatedSticker media.AnimatedStickerConfig `yaml:"animated_sticker"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ var ExampleConfig string
|
|||||||
func upgradeConfig(helper up.Helper) {
|
func upgradeConfig(helper up.Helper) {
|
||||||
helper.Copy(up.Int, "app_id")
|
helper.Copy(up.Int, "app_id")
|
||||||
helper.Copy(up.Str, "app_hash")
|
helper.Copy(up.Str, "app_hash")
|
||||||
|
helper.Copy(up.Bool, "set_private_chat_portal_meta")
|
||||||
helper.Copy(up.Str, "animated_sticker", "target")
|
helper.Copy(up.Str, "animated_sticker", "target")
|
||||||
helper.Copy(up.Bool, "animated_sticker", "convert_from_webm")
|
helper.Copy(up.Bool, "animated_sticker", "convert_from_webm")
|
||||||
helper.Copy(up.Int, "animated_sticker", "args", "width")
|
helper.Copy(up.Int, "animated_sticker", "args", "width")
|
||||||
|
|||||||
@@ -2,13 +2,21 @@
|
|||||||
app_id: 12345
|
app_id: 12345
|
||||||
app_hash: tjyd5yge35lbodk1xwzw2jstp90k55qz
|
app_hash: tjyd5yge35lbodk1xwzw2jstp90k55qz
|
||||||
|
|
||||||
|
# Whether to explicitly set the avatar and room name for private chat portal
|
||||||
|
# rooms.
|
||||||
|
set_private_chat_portal_meta: true
|
||||||
|
|
||||||
|
# Settings for converting animated stickers.
|
||||||
animated_sticker:
|
animated_sticker:
|
||||||
# Format to which animated stickers should be converted.
|
# Format to which animated stickers should be converted.
|
||||||
# disable - No conversion, send as-is (gzipped lottie)
|
#
|
||||||
# png - converts to non-animated png (fastest),
|
# disable - no conversion, send as-is (gzipped lottie)
|
||||||
# gif - converts to animated gif
|
# png - converts to non-animated png (fastest),
|
||||||
# webm - converts to webm video, requires ffmpeg executable with vp9 codec and webm container support
|
# gif - converts to animated gif
|
||||||
# webp - converts to animated webp, requires ffmpeg executable with webp codec/container support
|
# webm - converts to webm video, requires ffmpeg executable with vp9 codec
|
||||||
|
# and webm container support
|
||||||
|
# webp - converts to animated webp, requires ffmpeg executable with webp
|
||||||
|
# codec/container support
|
||||||
target: gif
|
target: gif
|
||||||
# Should video stickers be converted to the specified format as well?
|
# Should video stickers be converted to the specified format as well?
|
||||||
convert_from_webm: false
|
convert_from_webm: false
|
||||||
|
|||||||
Reference in New Issue
Block a user