Migrate to TDLib 1.8.21

This commit is contained in:
Bohdan Horbeshko 2023-11-11 16:10:23 -05:00
parent 67b8ad57f0
commit 576acba0d1
7 changed files with 59 additions and 51 deletions

View file

@ -1,8 +1,8 @@
.PHONY: all test .PHONY: all test
COMMIT := $(shell git rev-parse --short HEAD) COMMIT := $(shell git rev-parse --short HEAD)
TD_COMMIT := "8517026415e75a8eec567774072cbbbbb52376c1" TD_COMMIT := "3870c29b158b75ca5e48e0eebd6b5c3a7994a000"
VERSION := "v1.8.3" VERSION := "v1.9.0-dev"
MAKEOPTS := "-j4" MAKEOPTS := "-j4"
all: all:

2
go.mod
View file

@ -34,4 +34,4 @@ require (
) )
replace gosrc.io/xmpp => dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f 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

2
go.sum
View file

@ -1,6 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 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 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-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 h1:6249ajbMjgYz53Oq0IjTvjHXbxTfu29Mj1J/6swRHs4=
dev.narayana.im/narayana/go-xmpp v0.0.0-20220524203317-306b4ff58e8f/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY= 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= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

View file

@ -12,10 +12,11 @@ import (
"dev.narayana.im/narayana/telegabber/xmpp" "dev.narayana.im/narayana/telegabber/xmpp"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/zelenin/go-tdlib/client"
goxmpp "gosrc.io/xmpp" goxmpp "gosrc.io/xmpp"
) )
var version string = "1.8.3" var version string = "1.9.0-dev"
var commit string var commit string
var sm *goxmpp.StreamManager var sm *goxmpp.StreamManager
@ -60,6 +61,9 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
client.SetLogVerbosityLevel(&client.SetLogVerbosityLevelRequest{
NewVerbosityLevel: stringToTdlibLogConstant(config.Telegram.Loglevel),
})
SetLogrusLevel(config.XMPP.Loglevel) SetLogrusLevel(config.XMPP.Loglevel)
log.Infof("Starting telegabber version %v", version) 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() { func exit() {
xmpp.Close(component) xmpp.Close(component)
close(cleanupDone) close(cleanupDone)

View file

@ -16,25 +16,6 @@ import (
"gosrc.io/xmpp" "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 // DelayedStatus describes an online status expiring on timeout
type DelayedStatus struct { type DelayedStatus struct {
TimestampOnline int64 TimestampOnline int64
@ -83,10 +64,6 @@ type clientLocks struct {
func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component, session *persistence.Session) (*Client, error) { func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component, session *persistence.Session) (*Client, error) {
var options []client.Option var options []client.Option
options = append(options, client.WithLogVerbosity(&client.SetLogVerbosityLevelRequest{
NewVerbosityLevel: stringToLogConstant(conf.Loglevel),
}))
if conf.Tdlib.Client.CatchTimeout != 0 { if conf.Tdlib.Client.CatchTimeout != 0 {
options = append(options, client.WithCatchTimeout( options = append(options, client.WithCatchTimeout(
time.Duration(conf.Tdlib.Client.CatchTimeout)*time.Second, time.Duration(conf.Tdlib.Client.CatchTimeout)*time.Second,

View file

@ -422,7 +422,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
text := rawCmdArguments(cmdline, 1) text := rawCmdArguments(cmdline, 1)
_, err = c.client.ReportChat(&client.ReportChatRequest{ _, err = c.client.ReportChat(&client.ReportChatRequest{
ChatId: contact.Id, ChatId: contact.Id,
Reason: &client.ChatReportReasonCustom{}, Reason: &client.ReportReasonCustom{},
Text: text, Text: text,
}) })
if err != nil { if err != nil {
@ -710,18 +710,18 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
} }
// blacklists current user // blacklists current user
case "block": case "block":
_, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ _, err := c.client.SetMessageSenderBlockList(&client.SetMessageSenderBlockListRequest{
SenderId: &client.MessageSenderUser{UserId: chatID}, SenderId: &client.MessageSenderUser{UserId: chatID},
IsBlocked: true, BlockList: &client.BlockListMain{},
}) })
if err != nil { if err != nil {
return err.Error(), true return err.Error(), true
} }
// unblacklists current user // unblacklists current user
case "unblock": case "unblock":
_, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ _, err := c.client.SetMessageSenderBlockList(&client.SetMessageSenderBlockListRequest{
SenderId: &client.MessageSenderUser{UserId: chatID}, SenderId: &client.MessageSenderUser{UserId: chatID},
IsBlocked: false, BlockList: nil,
}) })
if err != nil { if err != nil {
return err.Error(), true return err.Error(), true

View file

@ -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) { 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 var err error
replyMsg, err = c.client.GetMessage(&client.GetMessageRequest{ replyMsg, err = c.client.GetMessage(&client.GetMessageRequest{
ChatId: message.ChatId, ChatId: message.ChatId,
MessageId: message.ReplyToMessageId, MessageId: replyTo.MessageId,
}) })
if err != nil { if err != nil {
log.Errorf("<error fetching message: %s>", err.Error()) log.Errorf("<error fetching message: %s>", err.Error())
return 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 { if err != nil {
replyId = strconv.FormatInt(message.ReplyToMessageId, 10) replyId = strconv.FormatInt(replyTo.MessageId, 10)
} }
reply = &gateway.Reply{ reply = &gateway.Reply{
Author: fmt.Sprintf("%v@%s", c.getSenderId(replyMsg), gateway.Jid.Full()), 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 { func (c *Client) formatForward(fwd *client.MessageForwardInfo) string {
switch fwd.Origin.MessageForwardOriginType() { switch fwd.Origin.MessageOriginType() {
case client.TypeMessageForwardOriginUser: case client.TypeMessageOriginUser:
originUser := fwd.Origin.(*client.MessageForwardOriginUser) originUser := fwd.Origin.(*client.MessageOriginUser)
return c.formatContact(originUser.SenderUserId) return c.formatContact(originUser.SenderUserId)
case client.TypeMessageForwardOriginChat: case client.TypeMessageOriginChat:
originChat := fwd.Origin.(*client.MessageForwardOriginChat) originChat := fwd.Origin.(*client.MessageOriginChat)
var signature string var signature string
if originChat.AuthorSignature != "" { if originChat.AuthorSignature != "" {
signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature) signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature)
} }
return c.formatContact(originChat.SenderChatId) + signature return c.formatContact(originChat.SenderChatId) + signature
case client.TypeMessageForwardOriginHiddenUser: case client.TypeMessageOriginHiddenUser:
originUser := fwd.Origin.(*client.MessageForwardOriginHiddenUser) originUser := fwd.Origin.(*client.MessageOriginHiddenUser)
return originUser.SenderName return originUser.SenderName
case client.TypeMessageForwardOriginChannel: case client.TypeMessageOriginChannel:
channel := fwd.Origin.(*client.MessageForwardOriginChannel) channel := fwd.Origin.(*client.MessageOriginChannel)
var signature string var signature string
if channel.AuthorSignature != "" { if channel.AuthorSignature != "" {
signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) signature = fmt.Sprintf(" (%s)", channel.AuthorSignature)
} }
return c.formatContact(channel.ChatId) + signature return c.formatContact(channel.ChatId) + signature
case client.TypeMessageForwardOriginMessageImport:
originImport := fwd.Origin.(*client.MessageForwardOriginMessageImport)
return originImport.SenderName
} }
return "Unknown forward type" return "Unknown forward type"
} }
@ -890,11 +895,12 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
} }
} }
// reply to // reply to
if message.ReplyToMessageId != 0 { if message.ReplyTo != nil && message.ReplyTo.MessageReplyToType() == client.TypeMessageReplyToMessage {
replyTo, _ := message.ReplyTo.(*client.MessageReplyToMessage)
if len(prefix) > 0 { if len(prefix) > 0 {
replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator) 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) prefix = append(prefix, replyLine)
replyEnd = replyStart + utf8.RuneCountInString(replyLine) replyEnd = replyStart + utf8.RuneCountInString(replyLine)
if len(prefix) > 0 { 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{ tgMessage, err := c.client.SendMessage(&client.SendMessageRequest{
ChatId: chatID, ChatId: chatID,
ReplyToMessageId: reply, ReplyTo: &client.InputMessageReplyToMessage{MessageId: reply},
InputMessageContent: content, InputMessageContent: content,
}) })
if err != nil { if err != nil {