diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-01-25 02:52:40 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-01-25 02:52:40 +0300 |
commit | b40ccf4a4d1391ba1f67a159697fea859e2a92fd (patch) | |
tree | 44d9638a98db6513ff450ab2839e993c3613c03b /telegram | |
parent | 4532748c8458971151dfb6b535b11b2a3e17a372 (diff) |
Fix presences sent with no resource
Diffstat (limited to 'telegram')
-rw-r--r-- | telegram/commands.go | 8 | ||||
-rw-r--r-- | telegram/connect.go | 11 | ||||
-rw-r--r-- | telegram/utils.go | 33 |
3 files changed, 16 insertions, 36 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index c4b5988..19fd655 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -185,12 +185,8 @@ func keyValueString(key, value string) string { } func (c *Client) unsubscribe(chatID int64) error { - return gateway.SendPresence( - c.xmpp, - c.jid, - gateway.SPFrom(strconv.FormatInt(chatID, 10)), - gateway.SPType("unsubscribed"), - ) + args := gateway.SimplePresence(chatID, "unsubscribed") + return c.sendPresence(args...) } func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) { diff --git a/telegram/connect.go b/telegram/connect.go index b1b8b10..6c88cd1 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -2,7 +2,6 @@ package telegram import ( "github.com/pkg/errors" - "strconv" "time" "dev.narayana.im/narayana/telegabber/xmpp/gateway" @@ -159,7 +158,7 @@ func (c *Client) Connect(resource string) error { } gateway.SubscribeToTransport(c.xmpp, c.jid) - gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in as: "+c.Session.Login)) + c.sendPresence(gateway.SPStatus("Logged in as: "+c.Session.Login)) }() return nil @@ -228,12 +227,8 @@ func (c *Client) Disconnect(resource string, quit bool) bool { // we're offline (unsubscribe if logout) for _, id := range c.cache.ChatsKeys() { - gateway.SendPresence( - c.xmpp, - c.jid, - gateway.SPFrom(strconv.FormatInt(id, 10)), - gateway.SPType("unavailable"), - ) + args := gateway.SimplePresence(id, "unavailable") + c.sendPresence(args...) } c.close() diff --git a/telegram/utils.go b/telegram/utils.go index b17d692..f0316f2 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -281,22 +281,17 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o c.cache.SetStatus(chatID, cacheShow, status) newArgs := []args.V{ - gateway.SPFrom(strconv.FormatInt(chatID, 10)), gateway.SPShow(show), gateway.SPStatus(status), gateway.SPPhoto(photo), - gateway.SPResource(gateway.Jid.Resource), gateway.SPImmed(gateway.SPImmed.Get(oldArgs)), } + newArgs = gateway.SPAppendFrom(newArgs, chatID) if presenceType != "" { newArgs = append(newArgs, gateway.SPType(presenceType)) } - return gateway.SendPresence( - c.xmpp, - c.jid, - newArgs..., - ) + return c.sendPresence(newArgs...) } func (c *Client) formatContact(chatID int64) string { @@ -1292,7 +1287,7 @@ func (c *Client) roster(resource string) { c.ProcessStatusUpdate(chat, "", "") } - gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in as: "+c.Session.Login)) + c.sendPresence(gateway.SPStatus("Logged in as: "+c.Session.Login)) c.addResource(resource) } @@ -1393,9 +1388,7 @@ func (c *Client) GetChatDescription(chat *client.Chat) string { // subscribe to a Telegram ID func (c *Client) subscribeToID(id int64, chat *client.Chat) { - var args []args.V - args = append(args, gateway.SPFrom(strconv.FormatInt(id, 10))) - args = append(args, gateway.SPType("subscribe")) + args := gateway.SimplePresence(id, "subscribe") if chat == nil { chat, _, _ = c.GetContactByID(id, nil) @@ -1406,11 +1399,11 @@ func (c *Client) subscribeToID(id int64, chat *client.Chat) { gateway.SetNickname(c.jid, strconv.FormatInt(id, 10), chat.Title, c.xmpp) } - gateway.SendPresence( - c.xmpp, - c.jid, - args..., - ) + c.sendPresence(args...) +} + +func (c *Client) sendPresence(args ...args.V) error { + return gateway.SendPresence(c.xmpp, c.jid, args...) } func (c *Client) prepareDiskSpace(size uint64) { @@ -1459,9 +1452,9 @@ func (c *Client) UpdateChatNicknames() { chat, ok := c.cache.GetChat(id) if ok { newArgs := []args.V{ - gateway.SPFrom(strconv.FormatInt(id, 10)), gateway.SPNickname(chat.Title), } + newArgs = gateway.SPAppendFrom(newArgs, id) cachedStatus, ok := c.cache.GetStatus(id) if ok { @@ -1472,11 +1465,7 @@ func (c *Client) UpdateChatNicknames() { } } - gateway.SendPresence( - c.xmpp, - c.jid, - newArgs..., - ) + c.sendPresence(newArgs...) gateway.SetNickname(c.jid, strconv.FormatInt(id, 10), chat.Title, c.xmpp) } |