From 6eb0e5f15fd9a81bbafb2189dd73b6c093b487e6 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Mon, 17 Jan 2022 15:45:40 -0500 Subject: Migrate back to the upstream go-tdlib --- telegram/utils.go | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'telegram/utils.go') diff --git a/telegram/utils.go b/telegram/utils.go index 556b1a7..63a880e 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -19,7 +19,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/soheilhy/args" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) var errOffline = errors.New("TDlib instance is offline") @@ -43,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) @@ -60,7 +60,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli user, ok = c.cache.GetUser(id) if !ok && id > 0 { user, err = c.client.GetUser(&client.GetUserRequest{ - UserID: id, + UserId: id, }) if err == nil { c.cache.SetUser(id, user) @@ -71,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 @@ -194,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(user.ID, 10) + username = strconv.FormatInt(user.Id, 10) } str = fmt.Sprintf("%s %s (%v)", user.FirstName, user.LastName, username) @@ -215,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("", err.Error()) @@ -229,15 +229,15 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess var str strings.Builder var senderId int64 - switch message.Sender.MessageSenderType() { + switch message.SenderId.MessageSenderType() { case client.TypeMessageSenderUser: - senderUser, _ := message.Sender.(*client.MessageSenderUser) - senderId = senderUser.UserID + senderUser, _ := message.SenderId.(*client.MessageSenderUser) + senderId = senderUser.UserId case client.TypeMessageSenderChat: - senderChat, _ := message.Sender.(*client.MessageSenderChat) - senderId = senderChat.ChatID + senderChat, _ := message.SenderId.(*client.MessageSenderChat) + senderId = senderChat.ChatId } - str.WriteString(fmt.Sprintf("%v | %s | ", message.ID, c.formatContact(senderId))) + str.WriteString(fmt.Sprintf("%v | %s | ", message.Id, c.formatContact(senderId))) if !preview { str.WriteString( time.Unix(int64(message.Date), 0). @@ -275,14 +275,14 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { switch fwd.Origin.MessageForwardOriginType() { case client.TypeMessageForwardOriginUser: originUser := fwd.Origin.(*client.MessageForwardOriginUser) - return c.formatContact(originUser.SenderUserID) + return c.formatContact(originUser.SenderUserId) case client.TypeMessageForwardOriginChat: originChat := fwd.Origin.(*client.MessageForwardOriginChat) var signature string if originChat.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature) } - return c.formatContact(originChat.SenderChatID)+signature + return c.formatContact(originChat.SenderChatId)+signature case client.TypeMessageForwardOriginHiddenUser: originUser := fwd.Origin.(*client.MessageForwardOriginHiddenUser) return originUser.SenderName @@ -292,7 +292,7 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { if channel.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) } - return c.formatContact(channel.ChatID)+signature + return c.formatContact(channel.ChatId)+signature } return "Unknown forward type" } @@ -307,7 +307,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), ) } @@ -346,17 +346,17 @@ func (c *Client) messageToText(message *client.Message) string { addMembers, _ := message.Content.(*client.MessageChatAddMembers) text := "invited " - if len(addMembers.MemberUserIDs) > 0 { - text += c.formatContact(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(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 @@ -448,7 +448,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(file.ID, 10) + ".jpg" + return file, strconv.FormatInt(int64(file.Id), 10) + ".jpg" } return nil, "" case client.TypeMessageAudio: @@ -474,23 +474,23 @@ 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.Sender != nil { + if message.ChatId < 0 && message.SenderId != nil { var senderId int64 - switch message.Sender.MessageSenderType() { + switch message.SenderId.MessageSenderType() { case client.TypeMessageSenderUser: - senderUser, _ := message.Sender.(*client.MessageSenderUser) - senderId = senderUser.UserID + senderUser, _ := message.SenderId.(*client.MessageSenderUser) + senderId = senderUser.UserId case client.TypeMessageSenderChat: - senderChat, _ := message.Sender.(*client.MessageSenderChat) - senderId = senderChat.ChatID + senderChat, _ := message.SenderId.(*client.MessageSenderChat) + senderId = senderChat.ChatId } prefix = append(prefix, c.formatContact(senderId)) } // 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 message.ForwardInfo != nil { prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo)) @@ -535,7 +535,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str var file *client.InputFileRemote if chatID != 0 && c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) { file = &client.InputFileRemote{ - ID: text, + Id: text, } } @@ -567,8 +567,8 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str if chatID != 0 { _, err := c.client.SendMessage(&client.SendMessageRequest{ - ChatID: chatID, - ReplyToMessageID: reply, + ChatId: chatID, + ReplyToMessageId: reply, InputMessageContent: message, }) if err != nil { @@ -628,10 +628,10 @@ func (c *Client) roster(resource string) { func (c *Client) getLastMessages(id int64, query string, from int64, count int32) (*client.Messages, error) { return c.client.SearchChatMessages(&client.SearchChatMessagesRequest{ - ChatID: id, - Query: query, - Sender: &client.MessageSenderUser{UserID: from}, - Filter: &client.SearchMessagesFilterEmpty{}, - Limit: count, + ChatId: id, + Query: query, + SenderId: &client.MessageSenderUser{UserId: from}, + Filter: &client.SearchMessagesFilterEmpty{}, + Limit: count, }) } -- cgit v1.2.3