aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2021-12-04 21:10:54 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2021-12-04 21:10:54 +0300
commit105f5017c35f92a9e2f5398a06cfdd3f1da31bad (patch)
treec602c7eb3ede37718894e7dea7875490cbc8d728 /telegram
parentbc37cf0c4f0d58752f92238a013513be9aa3caff (diff)
Migrate to TDlib 1.7.9
Diffstat (limited to 'telegram')
-rw-r--r--telegram/cache/cache.go12
-rw-r--r--telegram/client.go2
-rw-r--r--telegram/commands.go86
-rw-r--r--telegram/handlers.go46
-rw-r--r--telegram/utils.go95
5 files changed, 135 insertions, 106 deletions
diff --git a/telegram/cache/cache.go b/telegram/cache/cache.go
index b799709..3d9608d 100644
--- a/telegram/cache/cache.go
+++ b/telegram/cache/cache.go
@@ -17,7 +17,7 @@ type Status struct {
// a thread-safe manner
type Cache struct {
chats map[int64]*client.Chat
- users map[int32]*client.User
+ users map[int64]*client.User
statuses map[int64]*Status
chatsLock sync.Mutex
usersLock sync.Mutex
@@ -28,7 +28,7 @@ type Cache struct {
func NewCache() *Cache {
return &Cache{
chats: map[int64]*client.Chat{},
- users: map[int32]*client.User{},
+ users: map[int64]*client.User{},
statuses: map[int64]*Status{},
}
}
@@ -48,11 +48,11 @@ func (cache *Cache) ChatsKeys() []int64 {
// UsersKeys grabs user ids synchronously to avoid lockups
// while they are used
-func (cache *Cache) UsersKeys() []int32 {
+func (cache *Cache) UsersKeys() []int64 {
cache.usersLock.Lock()
defer cache.usersLock.Unlock()
- var keys []int32
+ var keys []int64
for id := range cache.users {
keys = append(keys, id)
}
@@ -89,7 +89,7 @@ func (cache *Cache) GetChat(id int64) (*client.Chat, bool) {
}
// GetUser retrieves user by id if it's present in the cache
-func (cache *Cache) GetUser(id int32) (*client.User, bool) {
+func (cache *Cache) GetUser(id int64) (*client.User, bool) {
cache.usersLock.Lock()
defer cache.usersLock.Unlock()
@@ -115,7 +115,7 @@ func (cache *Cache) SetChat(id int64, chat *client.Chat) {
}
// SetUser stores a user in the cache
-func (cache *Cache) SetUser(id int32, user *client.User) {
+func (cache *Cache) SetUser(id int64, user *client.User) {
cache.usersLock.Lock()
defer cache.usersLock.Unlock()
diff --git a/telegram/client.go b/telegram/client.go
index 2b122f8..07603b5 100644
--- a/telegram/client.go
+++ b/telegram/client.go
@@ -87,7 +87,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
UseMessageDatabase: true,
UseSecretChats: conf.Tdlib.Client.UseSecretChats,
- ApiId: int32(apiID),
+ ApiID: int64(apiID),
ApiHash: conf.Tdlib.Client.APIHash,
SystemLanguageCode: "en",
diff --git a/telegram/commands.go b/telegram/commands.go
index 558652d..58c0e17 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -3,7 +3,6 @@ package telegram
import (
"fmt"
"github.com/pkg/errors"
- "math"
"regexp"
"strconv"
"strings"
@@ -134,8 +133,8 @@ func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) {
}
}
-func (c *Client) usernameOrIDToID(username string) (int32, error) {
- userID, err := strconv.ParseInt(username, 10, 32)
+func (c *Client) usernameOrIDToID(username string) (int64, error) {
+ userID, err := strconv.ParseInt(username, 10, 64)
// couldn't parse the id, try to lookup as a username
if err != nil {
chat, err := c.client.SearchPublicChat(&client.SearchPublicChatRequest{
@@ -145,13 +144,13 @@ func (c *Client) usernameOrIDToID(username string) (int32, error) {
return 0, err
}
- userID = chat.Id
- if userID <= 0 || userID > math.MaxInt32 {
+ userID = chat.ID
+ if userID <= 0 {
return 0, errors.New("Not a user")
}
}
- return int32(userID), nil
+ return userID, nil
}
// ProcessTransportCommand executes a command sent directly to the component
@@ -345,10 +344,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
messages, err := c.client.SearchChatMessages(&client.SearchChatMessagesRequest{
- ChatId: chatID,
- Limit: limit,
- SenderUserId: c.me.Id,
- Filter: &client.SearchMessagesFilterEmpty{},
+ ChatID: chatID,
+ Limit: limit,
+ Sender: &client.MessageSenderUser{UserID: c.me.ID},
+ Filter: &client.SearchMessagesFilterEmpty{},
})
if err != nil {
return err.Error(), true
@@ -358,13 +357,13 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
var messageIds []int64
for _, message := range messages.Messages {
if message != nil {
- messageIds = append(messageIds, message.Id)
+ messageIds = append(messageIds, message.ID)
}
}
_, err = c.client.DeleteMessages(&client.DeleteMessagesRequest{
- ChatId: chatID,
- MessageIds: messageIds,
+ ChatID: chatID,
+ MessageIDs: messageIds,
Revoke: true,
})
if err != nil {
@@ -384,10 +383,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
messages, err := c.client.SearchChatMessages(&client.SearchChatMessagesRequest{
- ChatId: chatID,
- Limit: 1,
- SenderUserId: c.me.Id,
- Filter: &client.SearchMessagesFilterEmpty{},
+ ChatID: chatID,
+ Limit: 1,
+ Sender: &client.MessageSenderUser{UserID: c.me.ID},
+ Filter: &client.SearchMessagesFilterEmpty{},
})
if err != nil {
return err.Error(), true
@@ -407,7 +406,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
text := regex.ReplaceAllString(messageText.Text.Text, strings.Join(args[1:], " "))
- c.ProcessOutgoingMessage(chatID, text, message.Id, "")
+ c.ProcessOutgoingMessage(chatID, text, message.ID, "")
// add @contact
case "add":
if len(args) < 1 {
@@ -427,7 +426,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
gateway.SendPresence(
c.xmpp,
c.jid,
- gateway.SPFrom(strconv.FormatInt(chat.Id, 10)),
+ gateway.SPFrom(strconv.FormatInt(chat.ID, 10)),
gateway.SPType("subscribe"),
)
// join https://t.me/publichat
@@ -477,7 +476,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
_, err = c.client.CreateNewSecretChat(&client.CreateNewSecretChatRequest{
- UserId: int32(chatID),
+ UserID: chatID,
})
if err != nil {
return err.Error(), true
@@ -490,7 +489,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
if chatID > 0 {
_, err := c.client.CreateNewBasicGroupChat(&client.CreateNewBasicGroupChatRequest{
- UserIds: []int32{int32(chatID)},
+ UserIDs: []int64{chatID},
Title: args[0],
})
if err != nil {
@@ -500,8 +499,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
// blacklists current user
case "block":
if chatID > 0 {
- _, err := c.client.BlockUser(&client.BlockUserRequest{
- UserId: int32(chatID),
+ _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{
+ Sender: &client.MessageSenderUser{UserID: chatID},
+ IsBlocked: true,
})
if err != nil {
return err.Error(), true
@@ -510,8 +510,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
// unblacklists current user
case "unblock":
if chatID > 0 {
- _, err := c.client.UnblockUser(&client.UnblockUserRequest{
- UserId: int32(chatID),
+ _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{
+ Sender: &client.MessageSenderUser{UserID: chatID},
+ IsBlocked: false,
})
if err != nil {
return err.Error(), true
@@ -530,8 +531,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
_, err = c.client.AddChatMember(&client.AddChatMemberRequest{
- ChatId: chatID,
- UserId: userID,
+ ChatID: chatID,
+ UserID: userID,
})
if err != nil {
return err.Error(), true
@@ -550,8 +551,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
- ChatId: chatID,
- UserId: userID,
+ ChatID: chatID,
+ UserID: userID,
Status: &client.ChatMemberStatusLeft{},
})
if err != nil {
@@ -579,8 +580,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
- ChatId: chatID,
- UserId: userID,
+ ChatID: chatID,
+ UserID: userID,
Status: &client.ChatMemberStatusBanned{
BannedUntilDate: until,
},
@@ -599,7 +600,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
chatType := chat.Type.ChatTypeType()
if chatType == client.TypeChatTypeBasicGroup || chatType == client.TypeChatTypeSupergroup {
_, err = c.client.LeaveChat(&client.LeaveChatRequest{
- ChatId: chatID,
+ ChatID: chatID,
})
if err != nil {
return err.Error(), true
@@ -618,7 +619,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
if chatType == client.TypeChatTypeSecret {
chatTypeSecret, _ := chat.Type.(*client.ChatTypeSecret)
_, err = c.client.CloseSecretChat(&client.CloseSecretChatRequest{
- SecretChatId: chatTypeSecret.SecretChatId,
+ SecretChatID: chatTypeSecret.SecretChatID,
})
if err != nil {
return err.Error(), true
@@ -629,7 +630,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
// delete current chat
case "delete":
_, err := c.client.DeleteChatHistory(&client.DeleteChatHistoryRequest{
- ChatId: chatID,
+ ChatID: chatID,
RemoveFromChatList: true,
})
if err != nil {
@@ -653,7 +654,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
messages, err := c.client.SearchChatMessages(&client.SearchChatMessagesRequest{
- ChatId: chatID,
+ ChatID: chatID,
Query: query,
Limit: limit,
Filter: &client.SearchMessagesFilterEmpty{},
@@ -674,7 +675,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
messages, err := c.client.GetChatHistory(&client.GetChatHistoryRequest{
- ChatId: chatID,
+ ChatID: chatID,
Limit: limit,
})
if err != nil {
@@ -690,7 +691,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
members, err := c.client.SearchChatMembers(&client.SearchChatMembersRequest{
- ChatId: chatID,
+ ChatID: chatID,
Limit: 9999,
Query: query,
Filter: &client.ChatMembersFilterMembers{},
@@ -701,9 +702,18 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
var entries []string
for _, member := range members.Members {
+ var senderId int64
+ switch member.MemberID.MessageSenderType() {
+ case client.TypeMessageSenderUser:
+ memberUser, _ := member.MemberID.(*client.MessageSenderUser)
+ senderId = memberUser.UserID
+ case client.TypeMessageSenderChat:
+ memberChat, _ := member.MemberID.(*client.MessageSenderChat)
+ senderId = memberChat.ChatID
+ }
entries = append(entries, fmt.Sprintf(
"%v | role: %v",
- c.formatContact(int64(member.UserId)),
+ c.formatContact(senderId),
member.Status.ChatMemberStatusType(),
))
}
diff --git a/telegram/handlers.go b/telegram/handlers.go
index e768f04..f8e6751 100644
--- a/telegram/handlers.go
+++ b/telegram/handlers.go
@@ -119,15 +119,15 @@ func (c *Client) updateHandler() {
// new user discovered
func (c *Client) updateUser(update *client.UpdateUser) {
- c.cache.SetUser(update.User.Id, update.User)
+ c.cache.SetUser(update.User.ID, update.User)
show, status := c.userStatusToText(update.User.Status)
- go c.ProcessStatusUpdate(int64(update.User.Id), status, show)
+ go c.ProcessStatusUpdate(update.User.ID, status, show)
}
// user status changed
func (c *Client) updateUserStatus(update *client.UpdateUserStatus) {
show, status := c.userStatusToText(update.Status)
- go c.ProcessStatusUpdate(int64(update.UserId), status, show, gateway.SPImmed(false))
+ go c.ProcessStatusUpdate(update.UserID, status, show, gateway.SPImmed(false))
}
// new chat discovered
@@ -135,7 +135,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
go func() {
if update.Chat != nil && update.Chat.Photo != nil && update.Chat.Photo.Small != nil {
_, err := c.client.DownloadFile(&client.DownloadFileRequest{
- FileId: update.Chat.Photo.Small.Id,
+ FileID: update.Chat.Photo.Small.ID,
Priority: 32,
Synchronous: true,
})
@@ -145,7 +145,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
}
}
- c.cache.SetChat(update.Chat.Id, update.Chat)
+ c.cache.SetChat(update.Chat.ID, update.Chat)
var isChannel = false
if update.Chat.Type.ChatTypeType() == client.TypeChatTypeSupergroup {
@@ -157,21 +157,21 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
}
// don't subscribe to channel posters
- if !((isChannel && update.Chat.LastReadInboxMessageId == 0) ||
+ if !((isChannel && update.Chat.LastReadInboxMessageID == 0) ||
// don't subscribe to chats with no conversation
// (manual adding will trigger a subscribe anyway)
- (update.Chat.LastReadInboxMessageId == 0 && update.Chat.LastReadOutboxMessageId == 0)) {
+ (update.Chat.LastReadInboxMessageID == 0 && update.Chat.LastReadOutboxMessageID == 0)) {
gateway.SendPresence(
c.xmpp,
c.jid,
- gateway.SPFrom(strconv.FormatInt(update.Chat.Id, 10)),
+ gateway.SPFrom(strconv.FormatInt(update.Chat.ID, 10)),
gateway.SPType("subscribe"),
gateway.SPNickname(update.Chat.Title),
)
}
- if update.Chat.Id < 0 {
- c.ProcessStatusUpdate(update.Chat.Id, update.Chat.Title, "chat")
+ if update.Chat.ID < 0 {
+ c.ProcessStatusUpdate(update.Chat.ID, update.Chat.Title, "chat")
}
}()
}
@@ -180,7 +180,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
go func() {
// guarantee sequential message delivering per chat
- lock := c.getChatMessageLock(update.Message.ChatId)
+ lock := c.getChatMessageLock(update.Message.ChatID)
lock.Lock()
defer lock.Unlock()
@@ -192,7 +192,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
}
log.WithFields(log.Fields{
- "chat_id": update.Message.ChatId,
+ "chat_id": update.Message.ChatID,
}).Warn("New message from chat")
text := c.messageToText(update.Message)
@@ -201,7 +201,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
// download file(s)
if file != nil && !file.Local.IsDownloadingCompleted {
c.client.DownloadFile(&client.DownloadFileRequest{
- FileId: file.Id,
+ FileID: file.ID,
Priority: 32,
Synchronous: true,
})
@@ -212,9 +212,9 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
prefix.WriteString(c.messageToPrefix(update.Message, c.formatContent(file, filename)))
if text != "" {
// \n if it is groupchat and message is not empty
- if update.Message.ChatId < 0 {
+ if update.Message.ChatID < 0 {
prefix.WriteString("\n")
- } else if update.Message.ChatId > 0 {
+ } else if update.Message.ChatID > 0 {
prefix.WriteString(" | ")
}
@@ -226,12 +226,12 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
// mark message as read
c.client.ViewMessages(&client.ViewMessagesRequest{
- ChatId: update.Message.ChatId,
- MessageIds: []int64{update.Message.Id},
+ ChatID: update.Message.ChatID,
+ MessageIDs: []int64{update.Message.ID},
ForceRead: true,
})
// forward message to XMPP
- gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatId, 10), text, c.xmpp)
+ gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatID, 10), text, c.xmpp)
}()
}
@@ -240,20 +240,20 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
markupFunction := formatter.EntityToMarkdown
if update.NewContent.MessageContentType() == client.TypeMessageText {
textContent := update.NewContent.(*client.MessageText)
- text := fmt.Sprintf("✎ %v | %s", update.MessageId, formatter.Format(
+ text := fmt.Sprintf("✎ %v | %s", update.MessageID, formatter.Format(
textContent.Text.Text,
formatter.SortEntities(textContent.Text.Entities),
markupFunction,
))
- gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp)
+ gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp)
}
}
// message(s) deleted
func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) {
if update.IsPermanent {
- text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIds), ",")
- gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp)
+ text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIDs), ",")
+ gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp)
}
}
@@ -269,7 +269,7 @@ func (c *Client) updateFile(update *client.UpdateFile) {
fmt.Sprintf(
"%s/%s%s",
c.content.Path,
- fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.Id))),
+ fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.ID))),
filepath.Ext(update.File.Local.Path),
),
)
diff --git a/telegram/utils.go b/telegram/utils.go
index f7e7a28..3082b5f 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/pkg/errors"
"io"
- "math"
"os"
"path/filepath"
"regexp"
@@ -44,7 +43,7 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us
return nil, nil, err
}
- return c.GetContactByID(chat.Id, chat)
+ return c.GetContactByID(chat.ID, chat)
}
// GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing)
@@ -58,18 +57,13 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
var ok bool
var err error
- if id <= math.MaxInt32 && id >= math.MinInt32 {
- userID := int32(id)
- user, ok = c.cache.GetUser(userID)
- if !ok && userID > 0 {
- user, err = c.client.GetUser(&client.GetUserRequest{
- UserId: userID,
- })
- if err != nil {
- return nil, nil, err
- }
-
- c.cache.SetUser(userID, user)
+ user, ok = c.cache.GetUser(id)
+ if !ok && id > 0 {
+ user, err = c.client.GetUser(&client.GetUserRequest{
+ UserID: id,
+ })
+ if err == nil {
+ c.cache.SetUser(id, user)
}
}
@@ -77,7 +71,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
if !ok {
if chat == nil {
cacheChat, err = c.client.GetChat(&client.GetChatRequest{
- ChatId: id,
+ ChatID: id,
})
if err != nil {
// error is irrelevant if the user was found successfully
@@ -200,11 +194,11 @@ func (c *Client) formatContact(chatID int64) string {
var str string
if chat != nil {
- str = fmt.Sprintf("%s (%v)", chat.Title, chat.Id)
+ str = fmt.Sprintf("%s (%v)", chat.Title, chat.ID)
} else if user != nil {
username := user.Username
if username == "" {
- username = strconv.FormatInt(int64(user.Id), 10)
+ username = strconv.FormatInt(user.ID, 10)
}
str = fmt.Sprintf("%s %s (%v)", user.FirstName, user.LastName, username)
@@ -221,8 +215,8 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess
var err error
if message == nil {
message, err = c.client.GetMessage(&client.GetMessageRequest{
- ChatId: chatID,
- MessageId: messageID,
+ ChatID: chatID,
+ MessageID: messageID,
})
if err != nil {
return fmt.Sprintf("<error fetching message: %s>", err.Error())
@@ -234,7 +228,16 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess
}
var str strings.Builder
- str.WriteString(fmt.Sprintf("%v | %s | ", message.Id, c.formatContact(int64(message.SenderUserId))))
+ var senderId int64
+ switch message.Sender.MessageSenderType() {
+ case client.TypeMessageSenderUser:
+ senderUser, _ := message.Sender.(*client.MessageSenderUser)
+ senderId = senderUser.UserID
+ case client.TypeMessageSenderChat:
+ senderChat, _ := message.Sender.(*client.MessageSenderChat)
+ senderId = senderChat.ChatID
+ }
+ str.WriteString(fmt.Sprintf("%v | %s | ", message.ID, c.formatContact(senderId)))
if !preview {
str.WriteString(
time.Unix(int64(message.Date), 0).
@@ -276,7 +279,7 @@ func (c *Client) formatContent(file *client.File, filename string) string {
filename,
file.Size/1024,
c.content.Link,
- fmt.Sprintf("%x", sha256.Sum256([]byte(file.Remote.Id))),
+ fmt.Sprintf("%x", sha256.Sum256([]byte(file.Remote.ID))),
filepath.Ext(filename),
)
}
@@ -295,17 +298,17 @@ func (c *Client) messageToText(message *client.Message) string {
addMembers, _ := message.Content.(*client.MessageChatAddMembers)
text := "invited "
- if len(addMembers.MemberUserIds) > 0 {
- text += c.formatContact(int64(addMembers.MemberUserIds[0]))
+ if len(addMembers.MemberUserIDs) > 0 {
+ text += c.formatContact(addMembers.MemberUserIDs[0])
}
return text
case client.TypeMessageChatDeleteMember:
deleteMember, _ := message.Content.(*client.MessageChatDeleteMember)
- return "kicked " + c.formatContact(int64(deleteMember.UserId))
+ return "kicked " + c.formatContact(deleteMember.UserID)
case client.TypeMessagePinMessage:
pinMessage, _ := message.Content.(*client.MessagePinMessage)
- return "pinned message: " + c.formatMessage(message.ChatId, pinMessage.MessageId, false, nil)
+ return "pinned message: " + c.formatMessage(message.ChatID, pinMessage.MessageID, false, nil)
case client.TypeMessageChatChangeTitle:
changeTitle, _ := message.Content.(*client.MessageChatChangeTitle)
return "chat title set to: " + changeTitle.Title
@@ -393,7 +396,7 @@ func (c *Client) contentToFilename(content client.MessageContent) (*client.File,
sizes := photo.Photo.Sizes
if len(sizes) > 1 {
file := sizes[len(sizes)-1].Photo
- return file, strconv.FormatInt(int64(file.Id), 10) + ".jpg"
+ return file, strconv.FormatInt(file.ID, 10) + ".jpg"
}
return nil, ""
case client.TypeMessageAudio:
@@ -419,16 +422,32 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str
} else {
directionChar = "⬅ "
}
- prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10))
+ prefix = append(prefix, directionChar+strconv.FormatInt(message.ID, 10))
// show sender in group chats
- if message.ChatId < 0 && message.SenderUserId != 0 {
- prefix = append(prefix, c.formatContact(int64(message.SenderUserId)))
+ if message.ChatID < 0 && message.Sender != nil {
+ var senderId int64
+ switch message.Sender.MessageSenderType() {
+ case client.TypeMessageSenderUser:
+ senderUser, _ := message.Sender.(*client.MessageSenderUser)
+ senderId = senderUser.UserID
+ case client.TypeMessageSenderChat:
+ senderChat, _ := message.Sender.(*client.MessageSenderChat)
+ senderId = senderChat.ChatID
+ }
+ prefix = append(prefix, c.formatContact(senderId))
}
if message.ForwardInfo != nil {
switch message.ForwardInfo.Origin.MessageForwardOriginType() {
case client.TypeMessageForwardOriginUser:
originUser := message.ForwardInfo.Origin.(*client.MessageForwardOriginUser)
- prefix = append(prefix, "fwd: "+c.formatContact(int64(originUser.SenderUserId)))
+ prefix = append(prefix, "fwd: "+c.formatContact(originUser.SenderUserID))
+ case client.TypeMessageForwardOriginChat:
+ originChat := message.ForwardInfo.Origin.(*client.MessageForwardOriginChat)
+ var signature string
+ if originChat.AuthorSignature != "" {
+ signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature)
+ }
+ prefix = append(prefix, "fwd: "+c.formatContact(originChat.SenderChatID)+signature)
case client.TypeMessageForwardOriginHiddenUser:
originUser := message.ForwardInfo.Origin.(*client.MessageForwardOriginHiddenUser)
prefix = append(prefix, fmt.Sprintf("fwd: anonymous (%s)", originUser.SenderName))
@@ -438,12 +457,12 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str
if channel.AuthorSignature != "" {
signature = fmt.Sprintf(" (%s)", channel.AuthorSignature)
}
- prefix = append(prefix, "fwd: "+c.formatContact(channel.ChatId)+signature)
+ prefix = append(prefix, "fwd: "+c.formatContact(channel.ChatID)+signature)
}
}
// reply to
- if message.ReplyToMessageId != 0 {
- prefix = append(prefix, "reply: "+c.formatMessage(message.ChatId, message.ReplyToMessageId, true, nil))
+ if message.ReplyToMessageID != 0 {
+ prefix = append(prefix, "reply: "+c.formatMessage(message.ChatID, message.ReplyToMessageID, true, nil))
}
if fileString != "" {
prefix = append(prefix, "file: "+fileString)
@@ -484,8 +503,8 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int
}
c.client.EditMessageText(&client.EditMessageTextRequest{
- ChatId: chatID,
- MessageId: messageID,
+ ChatID: chatID,
+ MessageID: messageID,
InputMessageContent: message,
})
} else {
@@ -500,7 +519,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int
var file *client.InputFileRemote
if c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) {
file = &client.InputFileRemote{
- Id: text,
+ ID: text,
}
}
@@ -531,8 +550,8 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int
}
_, err := c.client.SendMessage(&client.SendMessageRequest{
- ChatId: chatID,
- ReplyToMessageId: reply,
+ ChatID: chatID,
+ ReplyToMessageID: reply,
InputMessageContent: message,
})
if err != nil {