mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
Terminology clarification (member -> occupant wherever applicable)
This commit is contained in:
parent
b1ecfc29cd
commit
67c960da25
4 changed files with 49 additions and 48 deletions
|
|
@ -24,11 +24,11 @@ type DelayedStatus struct {
|
|||
// MUCState holds MUC metadata
|
||||
type MUCState struct {
|
||||
Resources map[string]bool
|
||||
Members map[int64]*MUCMember
|
||||
Occupants map[int64]*MUCOccupant
|
||||
}
|
||||
|
||||
// MUCMember represents a MUC member
|
||||
type MUCMember struct {
|
||||
// MUCOccupant represents a MUC occupant
|
||||
type MUCOccupant struct {
|
||||
Nickname string
|
||||
Affiliation string
|
||||
Role string
|
||||
|
|
@ -37,7 +37,7 @@ type MUCMember struct {
|
|||
func NewMUCState() *MUCState {
|
||||
return &MUCState{
|
||||
Resources: make(map[string]bool),
|
||||
Members: make(map[int64]*MUCMember),
|
||||
Occupants: make(map[int64]*MUCOccupant),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -489,8 +489,8 @@ func (c *Client) updateBasicGroupFullInfo(update *client.UpdateBasicGroupFullInf
|
|||
|
||||
mucState, ok := c.mucCache[chatID]
|
||||
if ok && mucState != nil {
|
||||
mucState.Members = make(map[int64]*MUCMember)
|
||||
c.updateMUCMembers(mucState, chatID, update.BasicGroupFullInfo.Members)
|
||||
mucState.Occupants = make(map[int64]*MUCOccupant)
|
||||
c.updateMUCOccupants(mucState, chatID, update.BasicGroupFullInfo.Members)
|
||||
}
|
||||
|
||||
c.locks.mucCacheLock.Unlock()
|
||||
|
|
|
|||
|
|
@ -518,14 +518,14 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
|||
c.locks.mucCacheLock.Lock()
|
||||
chatJid := gateway.CHATJID(chatID, true)
|
||||
for mucId, state := range c.mucCache {
|
||||
member, ok := state.Members[chatID]
|
||||
occupant, ok := state.Occupants[chatID]
|
||||
if ok {
|
||||
newMucArgs := append(
|
||||
newArgs,
|
||||
gateway.SPFrom(gateway.MUCNODE(mucId)),
|
||||
gateway.SPResource(member.Nickname),
|
||||
gateway.SPMUCAffiliation(member.Affiliation),
|
||||
gateway.SPMUCRole(member.Role),
|
||||
gateway.SPResource(occupant.Nickname),
|
||||
gateway.SPMUCAffiliation(occupant.Affiliation),
|
||||
gateway.SPMUCRole(occupant.Role),
|
||||
gateway.SPMUCJid(chatJid),
|
||||
)
|
||||
err := c.sendPresence(newMucArgs...)
|
||||
|
|
@ -610,10 +610,10 @@ func (c *Client) sendMUCStatuses(chatID int64) {
|
|||
Limit: 200,
|
||||
Filter: &client.ChatMembersFilterMembers{},
|
||||
})
|
||||
c.updateMUCMembers(mucState, chatID, members.Members)
|
||||
c.updateMUCOccupants(mucState, chatID, members.Members)
|
||||
}
|
||||
|
||||
func (c *Client) updateMUCMembers(mucState *MUCState, chatID int64, members []*client.ChatMember) {
|
||||
func (c *Client) updateMUCOccupants(mucState *MUCState, chatID int64, members []*client.ChatMember) {
|
||||
sChatId := gateway.MUCNODE(chatID)
|
||||
myNickname := "me"
|
||||
if c.me != nil {
|
||||
|
|
@ -623,8 +623,8 @@ func (c *Client) updateMUCMembers(mucState *MUCState, chatID int64, members []*c
|
|||
myRole := "participant"
|
||||
|
||||
for _, member := range members {
|
||||
senderId, nickname, affiliation, role := c.TgMemberToMUCMember(member)
|
||||
mucState.Members[senderId] = &MUCMember{
|
||||
senderId, nickname, affiliation, role := c.TgMemberToMUCOccupant(member)
|
||||
mucState.Occupants[senderId] = &MUCOccupant{
|
||||
Nickname: nickname,
|
||||
Affiliation: affiliation,
|
||||
Role: role,
|
||||
|
|
@ -647,7 +647,7 @@ func (c *Client) updateMUCMembers(mucState *MUCState, chatID int64, members []*c
|
|||
)
|
||||
}
|
||||
|
||||
// according to the spec, own member entry should be sent the last
|
||||
// according to the spec, own occupant entry should be sent the last
|
||||
c.sendPresence(
|
||||
gateway.SPFrom(sChatId),
|
||||
gateway.SPResource(myNickname),
|
||||
|
|
@ -658,7 +658,7 @@ func (c *Client) updateMUCMembers(mucState *MUCState, chatID int64, members []*c
|
|||
)
|
||||
}
|
||||
|
||||
func (c *Client) mucCacheHasMember(mucID int64, memberID int64) bool {
|
||||
func (c *Client) mucCacheHasOccupant(mucID int64, memberID int64) bool {
|
||||
c.locks.mucCacheLock.Lock()
|
||||
defer c.locks.mucCacheLock.Unlock()
|
||||
mucState, ok := c.mucCache[mucID]
|
||||
|
|
@ -666,11 +666,11 @@ func (c *Client) mucCacheHasMember(mucID int64, memberID int64) bool {
|
|||
return false // no MUC to be added to
|
||||
}
|
||||
|
||||
_, ok = mucState.Members[memberID]
|
||||
_, ok = mucState.Occupants[memberID]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (c *Client) addMUCMember(mucID int64, memberID int64, affiliation, role string) bool {
|
||||
func (c *Client) addMUCOccupant(mucID int64, memberID int64, affiliation, role string) bool {
|
||||
c.locks.mucCacheLock.Lock()
|
||||
defer c.locks.mucCacheLock.Unlock()
|
||||
mucState, ok := c.mucCache[mucID]
|
||||
|
|
@ -690,7 +690,7 @@ func (c *Client) addMUCMember(mucID int64, memberID int64, affiliation, role str
|
|||
)
|
||||
|
||||
if err == nil {
|
||||
mucState.Members[memberID] = &MUCMember{
|
||||
mucState.Occupants[memberID] = &MUCOccupant{
|
||||
Nickname: nickname,
|
||||
Affiliation: affiliation,
|
||||
Role: role,
|
||||
|
|
@ -721,7 +721,7 @@ func (c *Client) sendMUCSubject(chatID int64, resource string) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetMUCNickname generates a unique nickname for a MUC member
|
||||
// GetMUCNickname generates a unique nickname for a MUC occupant
|
||||
func (c *Client) GetMUCNickname(chatID int64) string {
|
||||
if chatID == 0 {
|
||||
if c.me != nil {
|
||||
|
|
@ -739,11 +739,12 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
|||
|
||||
realJid := gateway.CHATJID(memberID, true)
|
||||
for mucId, state := range c.mucCache {
|
||||
oldMember, ok := state.Members[memberID]
|
||||
oldOccupant, ok := state.Occupants[memberID]
|
||||
if ok {
|
||||
state.Members[memberID] = &MUCMember{
|
||||
state.Occupants[memberID] = &MUCOccupant{
|
||||
Nickname: newNickname,
|
||||
Affiliation: oldMember.Affiliation,
|
||||
Affiliation: oldOccupant.Affiliation,
|
||||
Role: oldOccupant.Role,
|
||||
}
|
||||
|
||||
sMucId := gateway.MUCNODE(mucId)
|
||||
|
|
@ -756,10 +757,10 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
|||
c.sendPresence(
|
||||
gateway.SPType("unavailable"),
|
||||
gateway.SPFrom(sMucId),
|
||||
gateway.SPResource(oldMember.Nickname),
|
||||
gateway.SPResource(oldOccupant.Nickname),
|
||||
gateway.SPImmed(true),
|
||||
gateway.SPMUCAffiliation(oldMember.Affiliation),
|
||||
gateway.SPMUCRole(oldMember.Role),
|
||||
gateway.SPMUCAffiliation(oldOccupant.Affiliation),
|
||||
gateway.SPMUCRole(oldOccupant.Role),
|
||||
gateway.SPMUCNick(newNickname),
|
||||
gateway.SPMUCStatusCodes(unavailableStatusCodes),
|
||||
gateway.SPMUCJid(realJid),
|
||||
|
|
@ -768,8 +769,8 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
|
|||
gateway.SPFrom(sMucId),
|
||||
gateway.SPResource(newNickname),
|
||||
gateway.SPImmed(true),
|
||||
gateway.SPMUCAffiliation(oldMember.Affiliation),
|
||||
gateway.SPMUCRole(oldMember.Role),
|
||||
gateway.SPMUCAffiliation(oldOccupant.Affiliation),
|
||||
gateway.SPMUCRole(oldOccupant.Role),
|
||||
gateway.SPMUCStatusCodes(availableStatusCodes),
|
||||
gateway.SPMUCJid(realJid),
|
||||
)
|
||||
|
|
@ -821,14 +822,14 @@ func (c *Client) GetMyMUCNickname(chatID int64) (string, bool) {
|
|||
if !ok || mucState == nil {
|
||||
return "", false
|
||||
}
|
||||
member, ok := mucState.Members[c.me.Id]
|
||||
occupant, ok := mucState.Occupants[c.me.Id]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return member.Nickname, true
|
||||
return occupant.Nickname, true
|
||||
}
|
||||
|
||||
// GetMUCMemberIdByNickname looks up the telegram ID by the MUC nickname (slow yet!)
|
||||
// GetMUCMemberIdByNickname looks up the telegram ID by the MUC nickname (slow yet! (TODO))
|
||||
func (c *Client) GetMUCMemberIdByNickname(chatID int64, nickname string) int64 {
|
||||
c.locks.mucCacheLock.Lock()
|
||||
defer c.locks.mucCacheLock.Unlock()
|
||||
|
|
@ -838,8 +839,8 @@ func (c *Client) GetMUCMemberIdByNickname(chatID int64, nickname string) int64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
for memberId, member := range mucState.Members {
|
||||
if member.Nickname == nickname {
|
||||
for memberId, occupant := range mucState.Occupants {
|
||||
if occupant.Nickname == nickname {
|
||||
return memberId
|
||||
}
|
||||
}
|
||||
|
|
@ -1638,18 +1639,18 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
|||
|
||||
switch message.Content.MessageContentType() {
|
||||
case client.TypeMessageChatJoinByLink:
|
||||
c.mucMemberRolePresence(chatId, senderId, ChatMemberStatusUnmuted, c.GetMUCNickname(senderId))
|
||||
c.mucOccupantRolePresence(chatId, senderId, ChatMemberStatusUnmuted, c.GetMUCNickname(senderId))
|
||||
case client.TypeMessageChatAddMembers:
|
||||
addMembers, _ := message.Content.(*client.MessageChatAddMembers)
|
||||
for _, memberId := range addMembers.MemberUserIds {
|
||||
c.mucMemberRolePresence(chatId, memberId, ChatMemberStatusUnmuted, c.GetMUCNickname(memberId))
|
||||
c.mucOccupantRolePresence(chatId, memberId, ChatMemberStatusUnmuted, c.GetMUCNickname(memberId))
|
||||
}
|
||||
case client.TypeMessageChatDeleteMember:
|
||||
deleteMember, _ := message.Content.(*client.MessageChatDeleteMember)
|
||||
c.mucMemberRolePresence(chatId, deleteMember.UserId, ChatMemberStatusKicked, c.GetMUCNickname(deleteMember.UserId))
|
||||
c.mucOccupantRolePresence(chatId, deleteMember.UserId, ChatMemberStatusKicked, c.GetMUCNickname(deleteMember.UserId))
|
||||
}
|
||||
|
||||
if !c.mucCacheHasMember(chatId, senderId) {
|
||||
if !c.mucCacheHasOccupant(chatId, senderId) {
|
||||
chatMember, err := c.client.GetChatMember(&client.GetChatMemberRequest{
|
||||
ChatId: chatId,
|
||||
MemberId: message.SenderId,
|
||||
|
|
@ -1659,7 +1660,7 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
|||
status = chatMember.Status
|
||||
}
|
||||
affiliation, role := c.memberStatusToAffiliationAndRole(status)
|
||||
safeToSend = c.addMUCMember(chatId, senderId, affiliation, role)
|
||||
safeToSend = c.addMUCOccupant(chatId, senderId, affiliation, role)
|
||||
}
|
||||
|
||||
groupChatFrom = gateway.MUCJID(chatId) + "/" + c.GetMUCNickname(senderId)
|
||||
|
|
@ -2485,8 +2486,8 @@ func (c *Client) memberStatusToAffiliationAndRole(memberStatus client.ChatMember
|
|||
return "member", "participant"
|
||||
}
|
||||
|
||||
// TgMemberToMUCMember resolves useful data to generate a MUC member
|
||||
func (c *Client) TgMemberToMUCMember(member *client.ChatMember) (senderId int64, nickname, affiliation, role string) {
|
||||
// TgMemberToMUCMember resolves useful data to generate a MUC occupant
|
||||
func (c *Client) TgMemberToMUCOccupant(member *client.ChatMember) (senderId int64, nickname, affiliation, role string) {
|
||||
senderId = c.GetSenderId(member.MemberId)
|
||||
nickname = c.GetMUCNickname(senderId)
|
||||
affiliation, role = c.memberStatusToAffiliationAndRole(member.Status)
|
||||
|
|
@ -2669,12 +2670,12 @@ func (c *Client) SetChatMemberStatus(chatID, userID int64, status ChatMemberStat
|
|||
Status: chatMemberStatus,
|
||||
})
|
||||
if err == nil && nickname != "" {
|
||||
c.mucMemberRolePresence(chatID, userID, status, nickname)
|
||||
c.mucOccupantRolePresence(chatID, userID, status, nickname)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) mucMemberRolePresence(chatID, userID int64, status ChatMemberStatus, nickname string) {
|
||||
func (c *Client) mucOccupantRolePresence(chatID, userID int64, status ChatMemberStatus, nickname string) {
|
||||
args := []args.V{
|
||||
gateway.SPFrom(gateway.MUCNODE(chatID)),
|
||||
gateway.SPResource(nickname),
|
||||
|
|
@ -2723,12 +2724,12 @@ func (c *Client) mucMemberRolePresence(chatID, userID int64, status ChatMemberSt
|
|||
mucState, ok := c.mucCache[chatID]
|
||||
if ok && mucState != nil {
|
||||
if status == ChatMemberStatusKicked || status == ChatMemberStatusBanned {
|
||||
delete(mucState.Members, userID)
|
||||
delete(mucState.Occupants, userID)
|
||||
} else {
|
||||
member, ok := mucState.Members[userID]
|
||||
occupant, ok := mucState.Occupants[userID]
|
||||
if ok {
|
||||
member.Affiliation = newAffiliation
|
||||
member.Role = newRole
|
||||
occupant.Affiliation = newAffiliation
|
||||
occupant.Role = newRole
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
|
|||
if isGroupchat {
|
||||
gateway.SendErrorMessageWithBody(msg.From, msg.To, msg.Body, "", msg.Id, 400, true, component)
|
||||
} else {
|
||||
gateway.SendErrorMessage(msg.From, msg.To, "PMing room members is not supported, use the real JID", 406, true, component)
|
||||
gateway.SendErrorMessage(msg.From, msg.To, "PMing room occupants is not supported, use the real JID", 406, true, component)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1213,7 +1213,7 @@ func handleGetQueryMucAdmin(s xmpp.Sender, iq *stanza.IQ, query *extensions.Quer
|
|||
members, err := session.GetChatMembers(toID, false, "", membersList)
|
||||
if err == nil {
|
||||
for _, member := range members {
|
||||
senderId, nickname, affiliation, role := session.TgMemberToMUCMember(member)
|
||||
senderId, nickname, affiliation, role := session.TgMemberToMUCOccupant(member)
|
||||
if item.Role != "" && role != item.Role {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue