Handle a user leaving a group chat.
This commit is contained in:
parent
bd74021ca6
commit
b34643a756
2
group.py
2
group.py
|
@ -32,4 +32,4 @@ class Group():
|
|||
self.joined = False
|
||||
|
||||
self.nick = "me"
|
||||
self.participants = { }
|
||||
self.participants = []
|
||||
|
|
23
session.py
23
session.py
|
@ -484,12 +484,34 @@ class Session(YowsupApp):
|
|||
self.bot.send("You have been added to group: %s@%s (%s)"
|
||||
% (self._shortenGroupId(room), subject, self.backend.spectrum_jid))
|
||||
|
||||
# Called by superclass
|
||||
def onParticipantsAddedToGroup(self, group):
|
||||
self.logger.debug("Participants added to group: %s", group)
|
||||
room = group.getGroupId().split('@')[0]
|
||||
self.groups[room].participants.extend(group.getParticipants())
|
||||
self._refreshParticipants(room)
|
||||
|
||||
# Called by superclass
|
||||
def onParticipantsRemovedFromGroup(self, room, participants):
|
||||
self.logger.debug("Participants removed from group: %s, %s",
|
||||
room, participants)
|
||||
group = self.groups[room]
|
||||
for jid in participants:
|
||||
group.participants.remove(jid)
|
||||
buddy = jid.split("@")[0]
|
||||
try:
|
||||
nick = self.buddies[buddy].nick
|
||||
except KeyError:
|
||||
nick = buddy
|
||||
if nick == "":
|
||||
nick = buddy
|
||||
if buddy == self.legacyName:
|
||||
nick = group.nick
|
||||
flags = protocol_pb2.PARTICIPANT_FLAG_NONE
|
||||
self.backend.handleParticipantChanged(
|
||||
self.user, nick, self._shortenGroupId(room), flags,
|
||||
protocol_pb2.STATUS_NONE, buddy)
|
||||
|
||||
def onPresenceReceived(self, _type, name, jid, lastseen):
|
||||
self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen)
|
||||
buddy = jid.split("@")[0]
|
||||
|
@ -643,7 +665,6 @@ class Session(YowsupApp):
|
|||
group = self.groups[room]
|
||||
for jid in group.participants:
|
||||
buddy = jid.split("@")[0]
|
||||
self.logger.info("Added %s to room %s", buddy, room)
|
||||
try:
|
||||
nick = self.buddies[buddy].nick
|
||||
except KeyError:
|
||||
|
|
|
@ -501,6 +501,15 @@ class YowsupApp(object):
|
|||
"""Called when participants have been added to a group"""
|
||||
pass
|
||||
|
||||
def onParticipantsRemovedFromGroup(self, group, participants):
|
||||
"""Called when participants have been removed from a group
|
||||
|
||||
Args:
|
||||
- group: (str) id of the group (e.g. 27831788123-144024456)
|
||||
- participants: (list) jids of participants that are removed
|
||||
"""
|
||||
pass
|
||||
|
||||
def sendEntity(self, entity):
|
||||
"""Sends an entity down the stack (as if YowsupAppLayer called toLower)"""
|
||||
self.stack.broadcastEvent(YowLayerEvent(YowsupAppLayer.TO_LOWER_EVENT,
|
||||
|
@ -596,12 +605,17 @@ class YowsupAppLayer(YowInterfaceLayer):
|
|||
"""
|
||||
Sends ack automatically
|
||||
"""
|
||||
self.logger.debug("Received notification: %s", entity)
|
||||
self.logger.debug("Received notification (%s): %s", type(entity), entity)
|
||||
self.toLower(entity.ack())
|
||||
if isinstance(entity, CreateGroupsNotificationProtocolEntity):
|
||||
self.caller.onAddedToGroup(entity)
|
||||
elif isinstance(entity, AddGroupsNotificationProtocolEntity):
|
||||
self.caller.onParticipantsAddedToGroup(entity)
|
||||
elif isinstance(entity, RemoveGroupsNotificationProtocolEntity):
|
||||
self.caller.onParticipantsRemovedFromGroup(
|
||||
entity.getGroupId().split('@')[0],
|
||||
entity.getParticipants().keys()
|
||||
)
|
||||
|
||||
@ProtocolEntityCallback('message')
|
||||
def onMessageReceived(self, entity):
|
||||
|
|
Loading…
Reference in a new issue