aboutsummaryrefslogtreecommitdiff
path: root/xmpp/handlers.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-08-26 15:59:14 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-08-26 15:59:14 +0300
commit8ba7596ab5b9cd731fb507f60da51c6acf1ef27f (patch)
tree91e17a6bdd70300f2d784e60a1f88d47d3ec18ad /xmpp/handlers.go
parent3c917c16983c1afdd4a21d8021461585a1e785c9 (diff)
parent64515e2c666067953e3a9680b4f0db84f3838498 (diff)
Merge branch 'master' into dev
Diffstat (limited to 'xmpp/handlers.go')
-rw-r--r--xmpp/handlers.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index fd1afad..36f9cf9 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -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"
)
@@ -148,7 +149,12 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
"end": body.End,
}).Warn(errors.Wrap(err, "Failed to parse fallback end!"))
}
- text = text[:start] + text[end:]
+
+ fullRunes := []rune(text)
+ cutRunes := make([]rune, 0, len(text)-int(end-start))
+ cutRunes = append(cutRunes, fullRunes[:start]...)
+ cutRunes = append(cutRunes, fullRunes[end:]...)
+ text = string(cutRunes)
}
}
var replaceId int64
@@ -183,7 +189,6 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
if err != nil {
log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, msg.Id)
}
- session.AddToOutbox(msg.Id, resource)
}
} else {
/*
@@ -210,14 +215,25 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
}
if msg.Body == "" {
- var privilege extensions.ComponentPrivilege
- if ok := msg.Get(&privilege); ok {
- log.Debugf("privilege: %#v", privilege)
+ var privilege1 extensions.ComponentPrivilege1
+ if ok := msg.Get(&privilege1); ok {
+ log.Debugf("privilege1: %#v", privilege1)
}
- for _, perm := range privilege.Perms {
+ for _, perm := range privilege1.Perms {
if perm.Access == "message" && perm.Type == "outgoing" {
- gateway.MessageOutgoingPermission = true
+ gateway.MessageOutgoingPermissionVersion = 1
+ }
+ }
+
+ var privilege2 extensions.ComponentPrivilege2
+ if ok := msg.Get(&privilege2); ok {
+ log.Debugf("privilege2: %#v", privilege2)
+ }
+
+ for _, perm := range privilege2.Perms {
+ if perm.Access == "message" && perm.Type == "outgoing" {
+ gateway.MessageOutgoingPermissionVersion = 2
}
}
}
@@ -339,11 +355,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()