mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 12:17:06 +00:00
Assure all MUC presences are sent to a full JID
This commit is contained in:
parent
f5a6cbf199
commit
19d602a99b
3 changed files with 24 additions and 12 deletions
|
|
@ -519,6 +519,7 @@ func (c *Client) updateChatPermissions(update *client.UpdateChatPermissions) {
|
||||||
|
|
||||||
mucState, ok := c.mucCache[update.ChatId]
|
mucState, ok := c.mucCache[update.ChatId]
|
||||||
if ok && mucState != nil {
|
if ok && mucState != nil {
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(update.ChatId, mucState, false)
|
||||||
for memberID, occupant := range mucState.Occupants {
|
for memberID, occupant := range mucState.Occupants {
|
||||||
affiliation, role := c.memberStatusToAffiliationAndRole(occupant.Status, chat)
|
affiliation, role := c.memberStatusToAffiliationAndRole(occupant.Status, chat)
|
||||||
if affiliation != occupant.Affiliation || role != occupant.Role {
|
if affiliation != occupant.Affiliation || role != occupant.Role {
|
||||||
|
|
@ -532,6 +533,7 @@ func (c *Client) updateChatPermissions(update *client.UpdateChatPermissions) {
|
||||||
gateway.SPMUCJid(gateway.CHATJID(memberID, true)),
|
gateway.SPMUCJid(gateway.CHATJID(memberID, true)),
|
||||||
gateway.SPMUCAffiliation(affiliation),
|
gateway.SPMUCAffiliation(affiliation),
|
||||||
gateway.SPMUCRole(role),
|
gateway.SPMUCRole(role),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -567,6 +567,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
for mucId, state := range c.mucCache {
|
for mucId, state := range c.mucCache {
|
||||||
occupant, ok := state.Occupants[chatID]
|
occupant, ok := state.Occupants[chatID]
|
||||||
if ok {
|
if ok {
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(mucId, state, false)
|
||||||
newMucArgs := append(
|
newMucArgs := append(
|
||||||
newArgs,
|
newArgs,
|
||||||
gateway.SPFrom(gateway.MUCNODE(mucId)),
|
gateway.SPFrom(gateway.MUCNODE(mucId)),
|
||||||
|
|
@ -574,6 +575,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
gateway.SPMUCAffiliation(occupant.Affiliation),
|
gateway.SPMUCAffiliation(occupant.Affiliation),
|
||||||
gateway.SPMUCRole(occupant.Role),
|
gateway.SPMUCRole(occupant.Role),
|
||||||
gateway.SPMUCJid(chatJid),
|
gateway.SPMUCJid(chatJid),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
err := c.sendPresence(newMucArgs...)
|
err := c.sendPresence(newMucArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -691,6 +693,8 @@ func (c *Client) updateMUCOccupants(mucState *MUCState, chatID int64, members []
|
||||||
|
|
||||||
chat, _, _ := c.GetContactByID(chatID, nil)
|
chat, _, _ := c.GetContactByID(chatID, nil)
|
||||||
|
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(chatID, mucState, false)
|
||||||
|
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
senderId, nickname, affiliation, role := c.TgMemberToMUCOccupant(member, chat)
|
senderId, nickname, affiliation, role := c.TgMemberToMUCOccupant(member, chat)
|
||||||
mucState.Occupants[senderId] = &MUCOccupant{
|
mucState.Occupants[senderId] = &MUCOccupant{
|
||||||
|
|
@ -714,6 +718,7 @@ func (c *Client) updateMUCOccupants(mucState *MUCState, chatID int64, members []
|
||||||
gateway.SPMUCAffiliation(affiliation),
|
gateway.SPMUCAffiliation(affiliation),
|
||||||
gateway.SPMUCRole(role),
|
gateway.SPMUCRole(role),
|
||||||
gateway.SPMUCJid(gateway.CHATJID(senderId, true)),
|
gateway.SPMUCJid(gateway.CHATJID(senderId, true)),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -726,6 +731,7 @@ func (c *Client) updateMUCOccupants(mucState *MUCState, chatID int64, members []
|
||||||
gateway.SPMUCRole(myRole),
|
gateway.SPMUCRole(myRole),
|
||||||
gateway.SPMUCJid(myJid),
|
gateway.SPMUCJid(myJid),
|
||||||
gateway.SPMUCStatusCodes([]uint16{100, 110, 210}),
|
gateway.SPMUCStatusCodes([]uint16{100, 110, 210}),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -751,6 +757,8 @@ func (c *Client) addMUCOccupant(mucID int64, memberID int64, affiliation, role s
|
||||||
|
|
||||||
nickname := c.GetMUCNickname(memberID)
|
nickname := c.GetMUCNickname(memberID)
|
||||||
|
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(mucID, mucState, false)
|
||||||
|
|
||||||
err := c.sendPresence(
|
err := c.sendPresence(
|
||||||
gateway.SPFrom(gateway.MUCNODE(mucID)),
|
gateway.SPFrom(gateway.MUCNODE(mucID)),
|
||||||
gateway.SPResource(nickname),
|
gateway.SPResource(nickname),
|
||||||
|
|
@ -758,6 +766,7 @@ func (c *Client) addMUCOccupant(mucID int64, memberID int64, affiliation, role s
|
||||||
gateway.SPMUCAffiliation(affiliation),
|
gateway.SPMUCAffiliation(affiliation),
|
||||||
gateway.SPMUCRole(role),
|
gateway.SPMUCRole(role),
|
||||||
gateway.SPMUCJid(gateway.CHATJID(memberID, true)),
|
gateway.SPMUCJid(gateway.CHATJID(memberID, true)),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -827,6 +836,7 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
||||||
unavailableStatusCodes = append(unavailableStatusCodes, 110)
|
unavailableStatusCodes = append(unavailableStatusCodes, 110)
|
||||||
availableStatusCodes = append(availableStatusCodes, 110)
|
availableStatusCodes = append(availableStatusCodes, 110)
|
||||||
}
|
}
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(mucId, state, false)
|
||||||
c.sendPresence(
|
c.sendPresence(
|
||||||
gateway.SPType("unavailable"),
|
gateway.SPType("unavailable"),
|
||||||
gateway.SPFrom(sMucId),
|
gateway.SPFrom(sMucId),
|
||||||
|
|
@ -837,6 +847,7 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
||||||
gateway.SPMUCNick(newNickname),
|
gateway.SPMUCNick(newNickname),
|
||||||
gateway.SPMUCStatusCodes(unavailableStatusCodes),
|
gateway.SPMUCStatusCodes(unavailableStatusCodes),
|
||||||
gateway.SPMUCJid(realJid),
|
gateway.SPMUCJid(realJid),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
c.sendPresence(
|
c.sendPresence(
|
||||||
gateway.SPFrom(sMucId),
|
gateway.SPFrom(sMucId),
|
||||||
|
|
@ -846,6 +857,7 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
||||||
gateway.SPMUCRole(oldOccupant.Role),
|
gateway.SPMUCRole(oldOccupant.Role),
|
||||||
gateway.SPMUCStatusCodes(availableStatusCodes),
|
gateway.SPMUCStatusCodes(availableStatusCodes),
|
||||||
gateway.SPMUCJid(realJid),
|
gateway.SPMUCJid(realJid),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2793,6 +2805,7 @@ func (c *Client) kickMeFromMUC(chatID int64, statusCodes []uint16, destroy bool,
|
||||||
if c.me != nil {
|
if c.me != nil {
|
||||||
myJid = gateway.CHATJID(c.me.Id, true)
|
myJid = gateway.CHATJID(c.me.Id, true)
|
||||||
}
|
}
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(chatID, mucState, false)
|
||||||
args := []args.V{
|
args := []args.V{
|
||||||
gateway.SPFrom(gateway.MUCNODE(chatID)),
|
gateway.SPFrom(gateway.MUCNODE(chatID)),
|
||||||
gateway.SPResource(c.GetMUCNickname(0)),
|
gateway.SPResource(c.GetMUCNickname(0)),
|
||||||
|
|
@ -2800,14 +2813,10 @@ func (c *Client) kickMeFromMUC(chatID int64, statusCodes []uint16, destroy bool,
|
||||||
gateway.SPMUCRole("none"),
|
gateway.SPMUCRole("none"),
|
||||||
gateway.SPMUCJid(myJid),
|
gateway.SPMUCJid(myJid),
|
||||||
gateway.SPMUCStatusCodes(statusCodes),
|
gateway.SPMUCStatusCodes(statusCodes),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
}
|
}
|
||||||
if destroy {
|
if destroy {
|
||||||
_, toResources := c.getMUCJoinedJIDs(chatID, mucState, false)
|
args = append(args, gateway.SPMUCDestroy(""))
|
||||||
args = append(
|
|
||||||
args,
|
|
||||||
gateway.SPMUCDestroy(""),
|
|
||||||
gateway.SPToResources(toResources),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
args = append(args, gateway.SPType("unavailable"))
|
args = append(args, gateway.SPType("unavailable"))
|
||||||
}
|
}
|
||||||
|
|
@ -2949,12 +2958,15 @@ func CloneChatPermissions(permissions *client.ChatPermissions) *client.ChatPermi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) mucOccupantRolePresence(chatID, userID int64, status ChatMemberStatus, nickname string) {
|
func (c *Client) mucOccupantRolePresence(chatID, userID int64, status ChatMemberStatus, nickname string) {
|
||||||
|
_, toJids := c.getMUCJoinedJIDs(chatID, nil, true)
|
||||||
args := []args.V{
|
args := []args.V{
|
||||||
gateway.SPFrom(gateway.MUCNODE(chatID)),
|
gateway.SPFrom(gateway.MUCNODE(chatID)),
|
||||||
gateway.SPResource(nickname),
|
gateway.SPResource(nickname),
|
||||||
gateway.SPImmed(true),
|
gateway.SPImmed(true),
|
||||||
gateway.SPMUCJid(gateway.CHATJID(userID, true)),
|
gateway.SPMUCJid(gateway.CHATJID(userID, true)),
|
||||||
|
gateway.SPToJids(toJids),
|
||||||
}
|
}
|
||||||
|
|
||||||
var statusCodes []uint16
|
var statusCodes []uint16
|
||||||
var newAffiliation, newRole string
|
var newAffiliation, newRole string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -469,8 +469,8 @@ var SPMUCStatusCodes = args.New()
|
||||||
// SPMUCDestroy is a XEP-0045 room destruction element
|
// SPMUCDestroy is a XEP-0045 room destruction element
|
||||||
var SPMUCDestroy = args.NewString()
|
var SPMUCDestroy = args.NewString()
|
||||||
|
|
||||||
// SPToResources achieves to send the presence to certain resources only
|
// SPToJids achieves to send the presence to certain full jids only
|
||||||
var SPToResources = args.New()
|
var SPToJids = args.New()
|
||||||
|
|
||||||
func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
|
func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
|
||||||
var presenceFrom string
|
var presenceFrom string
|
||||||
|
|
@ -589,10 +589,8 @@ func SendPresence(component *xmpp.Component, to string, args ...args.V) error {
|
||||||
}).Info("Got presence")
|
}).Info("Got presence")
|
||||||
|
|
||||||
var tos []string
|
var tos []string
|
||||||
if SPToResources.IsSet(args) {
|
if SPToJids.IsSet(args) {
|
||||||
for _, toResource := range SPToResources.Get(args).([]string) {
|
tos = SPToJids.Get(args).([]string)
|
||||||
tos = append(tos, to + "/" + toResource)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
tos = []string{to}
|
tos = []string{to}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue