diff --git a/Makefile b/Makefile index 99ef5c3..4d1a263 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .PHONY: all test COMMIT := $(shell git rev-parse --short HEAD) -TD_COMMIT := "8517026415e75a8eec567774072cbbbbb52376c1" -VERSION := "v1.8.3" +TD_COMMIT := "3870c29b158b75ca5e48e0eebd6b5c3a7994a000" +VERSION := "v1.9.0-dev" MAKEOPTS := "-j4" all: diff --git a/go.mod b/go.mod index db7c380..50e753d 100644 --- a/go.mod +++ b/go.mod @@ -34,4 +34,4 @@ require ( ) replace gosrc.io/xmpp => dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f -replace github.com/zelenin/go-tdlib => dev.narayana.im/narayana/go-tdlib v0.0.0-20230730021136-47da33180615 +replace github.com/zelenin/go-tdlib => dev.narayana.im/narayana/go-tdlib v0.0.0-20231111182840-bc2f985e6268 diff --git a/go.sum b/go.sum index 2565582..6fd2f3e 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= dev.narayana.im/narayana/go-tdlib v0.0.0-20230730021136-47da33180615 h1:RRUZJSro+k8FkazNx7QEYLVoO4wZtchvsd0Y2RBWjeU= dev.narayana.im/narayana/go-tdlib v0.0.0-20230730021136-47da33180615/go.mod h1:Xs8fXbk5n7VaPyrSs9DP7QYoBScWYsjX+lUcWmx1DIU= +dev.narayana.im/narayana/go-tdlib v0.0.0-20231111182840-bc2f985e6268 h1:NCbc2bYuUGQsb/3z5SCIia3N34Ktwq3FwaUAfgF/WEU= +dev.narayana.im/narayana/go-tdlib v0.0.0-20231111182840-bc2f985e6268/go.mod h1:Xs8fXbk5n7VaPyrSs9DP7QYoBScWYsjX+lUcWmx1DIU= dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f h1:6249ajbMjgYz53Oq0IjTvjHXbxTfu29Mj1J/6swRHs4= dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/telegabber.go b/telegabber.go index e316aa6..8db6077 100644 --- a/telegabber.go +++ b/telegabber.go @@ -12,10 +12,11 @@ import ( "dev.narayana.im/narayana/telegabber/xmpp" log "github.com/sirupsen/logrus" + "github.com/zelenin/go-tdlib/client" goxmpp "gosrc.io/xmpp" ) -var version string = "1.8.3" +var version string = "1.9.0-dev" var commit string var sm *goxmpp.StreamManager @@ -60,6 +61,9 @@ func main() { log.Fatal(err) } + client.SetLogVerbosityLevel(&client.SetLogVerbosityLevelRequest{ + NewVerbosityLevel: stringToTdlibLogConstant(config.Telegram.Loglevel), + }) SetLogrusLevel(config.XMPP.Loglevel) log.Infof("Starting telegabber version %v", version) @@ -89,6 +93,25 @@ func main() { } } +var tdlibLogConstants = map[string]int32{ + ":fatal": 0, + ":error": 1, + ":warn": 2, + ":info": 3, + ":debug": 4, + ":verbose": 5, + ":all": 1023, +} + +func stringToTdlibLogConstant(c string) int32 { + level, ok := tdlibLogConstants[c] + if !ok { + level = 0 + } + + return level +} + func exit() { xmpp.Close(component) close(cleanupDone) diff --git a/telegram/client.go b/telegram/client.go index 6f6d719..49fc1ef 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -16,25 +16,6 @@ import ( "gosrc.io/xmpp" ) -var logConstants = map[string]int32{ - ":fatal": 0, - ":error": 1, - ":warn": 2, - ":info": 3, - ":debug": 4, - ":verbose": 5, - ":all": 1023, -} - -func stringToLogConstant(c string) int32 { - level, ok := logConstants[c] - if !ok { - level = 0 - } - - return level -} - // DelayedStatus describes an online status expiring on timeout type DelayedStatus struct { TimestampOnline int64 @@ -83,10 +64,6 @@ type clientLocks struct { func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component, session *persistence.Session) (*Client, error) { var options []client.Option - options = append(options, client.WithLogVerbosity(&client.SetLogVerbosityLevelRequest{ - NewVerbosityLevel: stringToLogConstant(conf.Loglevel), - })) - if conf.Tdlib.Client.CatchTimeout != 0 { options = append(options, client.WithCatchTimeout( time.Duration(conf.Tdlib.Client.CatchTimeout)*time.Second, diff --git a/telegram/commands.go b/telegram/commands.go index 87fff72..48c3615 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -422,7 +422,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string text := rawCmdArguments(cmdline, 1) _, err = c.client.ReportChat(&client.ReportChatRequest{ ChatId: contact.Id, - Reason: &client.ChatReportReasonCustom{}, + Reason: &client.ReportReasonCustom{}, Text: text, }) if err != nil { @@ -710,18 +710,18 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } // blacklists current user case "block": - _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ + _, err := c.client.SetMessageSenderBlockList(&client.SetMessageSenderBlockListRequest{ SenderId: &client.MessageSenderUser{UserId: chatID}, - IsBlocked: true, + BlockList: &client.BlockListMain{}, }) if err != nil { return err.Error(), true } // unblacklists current user case "unblock": - _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ + _, err := c.client.SetMessageSenderBlockList(&client.SetMessageSenderBlockListRequest{ SenderId: &client.MessageSenderUser{UserId: chatID}, - IsBlocked: false, + BlockList: nil, }) if err != nil { return err.Error(), true diff --git a/telegram/utils.go b/telegram/utils.go index 6edea31..b22f156 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -343,20 +343,28 @@ func (c *Client) formatSender(message *client.Message) string { } func (c *Client) getMessageReply(message *client.Message) (reply *gateway.Reply, replyMsg *client.Message) { - if message.ReplyToMessageId != 0 { + if message.ReplyTo != nil && message.ReplyTo.MessageReplyToType() == client.TypeMessageReplyToMessage { + replyTo, _ := message.ReplyTo.(*client.MessageReplyToMessage) + // TODO: support replies from other chats + if message.ChatId != replyTo.ChatId { + log.Warn("Reply from other/unknown chat") + log.Debugf("replyTo: %#v", replyTo) + return + } + var err error replyMsg, err = c.client.GetMessage(&client.GetMessageRequest{ ChatId: message.ChatId, - MessageId: message.ReplyToMessageId, + MessageId: replyTo.MessageId, }) if err != nil { log.Errorf("", err.Error()) return } - replyId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, message.ChatId, message.ReplyToMessageId) + replyId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, message.ChatId, replyTo.MessageId) if err != nil { - replyId = strconv.FormatInt(message.ReplyToMessageId, 10) + replyId = strconv.FormatInt(replyTo.MessageId, 10) } reply = &gateway.Reply{ Author: fmt.Sprintf("%v@%s", c.getSenderId(replyMsg), gateway.Jid.Full()), @@ -417,30 +425,27 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess } func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { - switch fwd.Origin.MessageForwardOriginType() { - case client.TypeMessageForwardOriginUser: - originUser := fwd.Origin.(*client.MessageForwardOriginUser) + switch fwd.Origin.MessageOriginType() { + case client.TypeMessageOriginUser: + originUser := fwd.Origin.(*client.MessageOriginUser) return c.formatContact(originUser.SenderUserId) - case client.TypeMessageForwardOriginChat: - originChat := fwd.Origin.(*client.MessageForwardOriginChat) + case client.TypeMessageOriginChat: + originChat := fwd.Origin.(*client.MessageOriginChat) var signature string if originChat.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature) } return c.formatContact(originChat.SenderChatId) + signature - case client.TypeMessageForwardOriginHiddenUser: - originUser := fwd.Origin.(*client.MessageForwardOriginHiddenUser) + case client.TypeMessageOriginHiddenUser: + originUser := fwd.Origin.(*client.MessageOriginHiddenUser) return originUser.SenderName - case client.TypeMessageForwardOriginChannel: - channel := fwd.Origin.(*client.MessageForwardOriginChannel) + case client.TypeMessageOriginChannel: + channel := fwd.Origin.(*client.MessageOriginChannel) var signature string if channel.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) } return c.formatContact(channel.ChatId) + signature - case client.TypeMessageForwardOriginMessageImport: - originImport := fwd.Origin.(*client.MessageForwardOriginMessageImport) - return originImport.SenderName } return "Unknown forward type" } @@ -890,11 +895,12 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string, } } // reply to - if message.ReplyToMessageId != 0 { + if message.ReplyTo != nil && message.ReplyTo.MessageReplyToType() == client.TypeMessageReplyToMessage { + replyTo, _ := message.ReplyTo.(*client.MessageReplyToMessage) if len(prefix) > 0 { replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator) } - replyLine := "reply: " + c.formatMessage(message.ChatId, message.ReplyToMessageId, true, replyMsg) + replyLine := "reply: " + c.formatMessage(message.ChatId, replyTo.MessageId, true, replyMsg) prefix = append(prefix, replyLine) replyEnd = replyStart + utf8.RuneCountInString(replyLine) if len(prefix) > 0 { @@ -1116,7 +1122,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str tgMessage, err := c.client.SendMessage(&client.SendMessageRequest{ ChatId: chatID, - ReplyToMessageId: reply, + ReplyTo: &client.InputMessageReplyToMessage{MessageId: reply}, InputMessageContent: content, }) if err != nil {