Attach resource to presences to prevent unwanted behaviour of some clients

This commit is contained in:
Bohdan Horbeshko 2022-02-08 12:43:51 -05:00
parent 76364388ad
commit 0610479734
3 changed files with 17 additions and 0 deletions

View file

@ -48,6 +48,7 @@ type Client struct {
options []client.Option options []client.Option
me *client.User me *client.User
resource string
xmpp *xmpp.Component xmpp *xmpp.Component
jid string jid string
Session *persistence.Session Session *persistence.Session
@ -115,8 +116,14 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
IgnoreFileNames: false, IgnoreFileNames: false,
} }
resource := conf.Tdlib.Client.DeviceModel
if resource == "" {
resource = "telegabber"
}
return &Client{ return &Client{
parameters: &parameters, parameters: &parameters,
resource: resource,
xmpp: component, xmpp: component,
jid: jid, jid: jid,
Session: session, Session: session,

View file

@ -217,6 +217,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
gateway.SPShow(show), gateway.SPShow(show),
gateway.SPStatus(status), gateway.SPStatus(status),
gateway.SPPhoto(photo), gateway.SPPhoto(photo),
gateway.SPResource(c.resource),
gateway.SPImmed(gateway.SPImmed.Get(oldArgs)), gateway.SPImmed(gateway.SPImmed.Get(oldArgs)),
} }
if presenceType != "" { if presenceType != "" {

View file

@ -88,6 +88,9 @@ var SPNickname = args.NewString()
// SPPhoto is a XEP-0153 hash of avatar in vCard // SPPhoto is a XEP-0153 hash of avatar in vCard
var SPPhoto = args.NewString() var SPPhoto = args.NewString()
// SPResource is an optional resource
var SPResource = args.NewString()
// SPImmed skips queueing // SPImmed skips queueing
var SPImmed = args.NewBool(args.Default(true)) var SPImmed = args.NewBool(args.Default(true))
@ -95,6 +98,12 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
var presenceFrom string var presenceFrom string
if SPFrom.IsSet(args) { if SPFrom.IsSet(args) {
presenceFrom = SPFrom.Get(args) + "@" + bareJid presenceFrom = SPFrom.Get(args) + "@" + bareJid
if SPResource.IsSet(args) {
resource := SPResource.Get(args)
if resource != "" {
presenceFrom += "/" + resource
}
}
} else { } else {
presenceFrom = bareJid presenceFrom = bareJid
} }