aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go57
1 files changed, 40 insertions, 17 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index a91c6da..4d77fc4 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)),
@@ -837,7 +855,7 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
}
- isCarbonsEnabled := gateway.MessageOutgoingPermission && c.Session.Carbons
+ isCarbonsEnabled := gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons
// with carbons, hide for all messages in PM and only for outgoing in group chats
hideSender := isCarbonsEnabled && (message.IsOutgoing || isPM)
@@ -914,18 +932,9 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
}
// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side
-func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message, ignoredResource string) {
- var isCarbon bool
- isOutgoing := message.IsOutgoing
- if gateway.MessageOutgoingPermission && c.Session.Carbons {
- isCarbon = isOutgoing
- }
-
- jids := c.getCarbonFullJids(isOutgoing, ignoredResource)
- if len(jids) == 0 {
- log.Info("The only resource is ignored, aborting")
- return
- }
+func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
+ isCarbon := gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons && message.IsOutgoing
+ jids := c.getCarbonFullJids(isCarbon, "")
var text, oob, auxText string
@@ -1369,12 +1378,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)
}
}