Update group subject when notification received

This commit is contained in:
moyamo 2016-01-07 12:58:03 +02:00
parent f57b276665
commit 9c32dfbb38
2 changed files with 39 additions and 3 deletions

View file

@ -441,6 +441,24 @@ class Session(YowsupApp):
self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName)
self.groups[room].sendParticipantsToSpectrum(self.legacyName)
# Called by superclass
def onSubjectChanged(self, room, subject, subjectOwner, timestamp):
self.logger.debug(
"onSubjectChange(rrom=%s, subject=%s, subjectOwner=%s, timestamp=%s)",
room, subject, subjectOwner, timestamp)
try:
group = self.groups[room]
except KeyError:
self.logger.error("Subject of non-existant group (%s) changed", group)
else:
group.subject = subject
group.subjectOwner = subjectOwner
if not group.joined:
# We have not joined group so we should not send subject
return
self.backend.handleSubject(self.user, room, subject, subjectOwner)
self.backend.handleRoomNicknameChanged(self.user, room, subject)
# Called by superclass
def onParticipantsRemovedFromGroup(self, room, participants):
self.logger.debug("Participants removed from group: %s, %s",

View file

@ -539,19 +539,30 @@ class YowsupApp(object):
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 onSubjectChanged(self, group, subject, subjectOwner, timestamp):
"""Called when someone changes the grousp subject
Args:
- group: (str) id of the group (e.g. 27831788123-144024456)
- subject: (str) the new subject
- subjectOwner: (str) the number of the person who changed the subject
- timestamp: (str) time the subject was changed
"""
pass
def onContactStatusChanged(self, number, status):
"""Called when a contacts changes their status
Args:
number: (str) the number of the contact who changed their status
status: (str) the new status
number: (str) the number of the contact who changed their status
status: (str) the new status
"""
pass
@ -694,6 +705,13 @@ class YowsupAppLayer(YowInterfaceLayer):
entity.getGroupId().split('@')[0],
entity.getParticipants().keys()
)
elif isinstance(entity, SubjectGroupsNotificationProtocolEntity):
self.caller.onSubjectChanged(
entity.getGroupId().split('@')[0],
entity.getSubject(),
entity.getSubjectOwner(full=False),
entity.getSubjectTimestamp()
)
elif isinstance(entity, StatusNotificationProtocolEntity):
self.caller.onContactStatusChanged(
entity._from.split('@')[0],