Save/read unavailable presence type in cache
This commit is contained in:
parent
c03ccfdfb7
commit
9377d7a155
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
|||
|
||||
COMMIT := $(shell git rev-parse --short HEAD)
|
||||
TD_COMMIT := "8517026415e75a8eec567774072cbbbbb52376c1"
|
||||
VERSION := "v1.7.4"
|
||||
VERSION := "v1.7.5"
|
||||
MAKEOPTS := "-j4"
|
||||
|
||||
all:
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
goxmpp "gosrc.io/xmpp"
|
||||
)
|
||||
|
||||
var version string = "1.7.4"
|
||||
var version string = "1.7.5"
|
||||
var commit string
|
||||
|
||||
var sm *goxmpp.StreamManager
|
||||
|
|
10
telegram/cache/cache.go
vendored
10
telegram/cache/cache.go
vendored
|
@ -133,3 +133,13 @@ func (cache *Cache) SetStatus(id int64, show string, status string) {
|
|||
Description: status,
|
||||
}
|
||||
}
|
||||
|
||||
// Destruct splits a cached status into show, description and type
|
||||
func (status *Status) Destruct() (show, description, typ string) {
|
||||
show, description = status.XMPP, status.Description
|
||||
if show == "unavailable" {
|
||||
typ = show
|
||||
show = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/soheilhy/args"
|
||||
"gosrc.io/xmpp"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
)
|
||||
|
@ -349,11 +350,18 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
|||
log.Error(errors.Wrap(err, "TDlib connection failure"))
|
||||
} else {
|
||||
for status := range session.StatusesRange() {
|
||||
show, description, typ := status.Destruct()
|
||||
newArgs := []args.V{
|
||||
gateway.SPImmed(false),
|
||||
}
|
||||
if typ != "" {
|
||||
newArgs = append(newArgs, gateway.SPType(typ))
|
||||
}
|
||||
go session.ProcessStatusUpdate(
|
||||
status.ID,
|
||||
status.Description,
|
||||
status.XMPP,
|
||||
gateway.SPImmed(false),
|
||||
description,
|
||||
show,
|
||||
newArgs...,
|
||||
)
|
||||
}
|
||||
session.UpdateChatNicknames()
|
||||
|
|
Loading…
Reference in a new issue