diff options
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 08c45d2..3ab6b88 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -217,6 +217,10 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o return err } + if chat != nil && c.Session.MUC && c.IsGroup(chat) { + return nil + } + var photo string if chat != nil && chat.Photo != nil { file, path, err := c.ForceOpenFile(chat.Photo.Small, 1) @@ -290,6 +294,35 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o ) } +func (c *Client) SendMUCStatuses(chatID int64) { + members, err := c.client.SearchChatMembers(&client.SearchChatMembersRequest{ + ChatId: chatID, + Limit: 200, + Filter: &client.ChatMembersFilterMembers{}, + }) + if err == nil { + for _, member := range members.Members { + var senderId int64 + switch member.MemberId.MessageSenderType() { + case client.TypeMessageSenderUser: + memberUser, _ := member.MemberId.(*client.MessageSenderUser) + senderId = memberUser.UserId + case client.TypeMessageSenderChat: + memberChat, _ := member.MemberId.(*client.MessageSenderChat) + senderId = memberChat.ChatId + } + gateway.SendPresence( + c.xmpp, + c.jid, + gateway.SPFrom(strconv.FormatInt(chatID, 10)), + gateway.SPResource(c.formatContact(senderId)), + gateway.SPImmed(true), + gateway.SPAffiliation(c.memberStatusToAffiliation(member.Status)), + ) + } + } +} + func (c *Client) formatContact(chatID int64) string { if chatID == 0 { return "" @@ -1434,6 +1467,10 @@ func (c *Client) UpdateChatNicknames() { for _, id := range c.cache.ChatsKeys() { chat, ok := c.cache.GetChat(id) if ok { + if c.Session.MUC && c.IsGroup(chat) { + continue + } + newArgs := []args.V{ gateway.SPFrom(strconv.FormatInt(id, 10)), gateway.SPNickname(chat.Title), @@ -1560,3 +1597,21 @@ func (c *Client) usernamesToString(usernames []string) string { } return strings.Join(atUsernames, ", ") } + +func (c *Client) memberStatusToAffiliation(memberStatus client.ChatMemberStatus) string { + switch memberStatus.ChatMemberStatusType() { + case client.TypeChatMemberStatusCreator: + return "owner" + case client.TypeChatMemberStatusAdministrator: + return "admin" + case client.TypeChatMemberStatusMember: + return "member" + case client.TypeChatMemberStatusRestricted: + return "outcast" + case client.TypeChatMemberStatusLeft: + return "none" + case client.TypeChatMemberStatusBanned: + return "outcast" + } + return "member" +} |