aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go40
1 files changed, 36 insertions, 4 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index 4caf88c..2578671 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -243,15 +243,33 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
cachedStatus, ok := c.cache.GetStatus(chatID)
if status == "" {
if ok {
- show, status = cachedStatus.XMPP, cachedStatus.Description
+ var typ string
+ show, status, typ = cachedStatus.Destruct()
+ if presenceType == "" {
+ presenceType = typ
+ }
+ log.WithFields(log.Fields{
+ "show": show,
+ "status": status,
+ "presenceType": presenceType,
+ }).Debug("Cached status")
} else if user != nil && user.Status != nil {
show, status, presenceType = c.userStatusToText(user.Status, chatID)
+ log.WithFields(log.Fields{
+ "show": show,
+ "status": status,
+ "presenceType": presenceType,
+ }).Debug("Status to text")
} else {
show, status = "chat", chat.Title
}
}
- c.cache.SetStatus(chatID, show, status)
+ cacheShow := show
+ if presenceType == "unavailable" {
+ cacheShow = presenceType
+ }
+ c.cache.SetStatus(chatID, cacheShow, status)
newArgs := []args.V{
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
@@ -1366,12 +1384,26 @@ func (c *Client) UpdateChatNicknames() {
for _, id := range c.cache.ChatsKeys() {
chat, ok := c.cache.GetChat(id)
if ok {
+ newArgs := []args.V{
+ gateway.SPFrom(strconv.FormatInt(id, 10)),
+ gateway.SPNickname(chat.Title),
+ }
+
+ cachedStatus, ok := c.cache.GetStatus(id)
+ if ok {
+ show, status, typ := cachedStatus.Destruct()
+ newArgs = append(newArgs, gateway.SPShow(show), gateway.SPStatus(status))
+ if typ != "" {
+ newArgs = append(newArgs, gateway.SPType(typ))
+ }
+ }
+
gateway.SendPresence(
c.xmpp,
c.jid,
- gateway.SPFrom(strconv.FormatInt(id, 10)),
- gateway.SPNickname(chat.Title),
+ newArgs...,
)
+
gateway.SetNickname(c.jid, strconv.FormatInt(id, 10), chat.Title, c.xmpp)
}
}