Notify user when a group message is sent to a group they have not yet joined

Before messages sent to groups the user had not joined were lost. Now
the message is sent via the bot to the user. The bot suggests that the
user join the group and also relays the contents of the message.
This commit is contained in:
moyamo 2015-11-23 17:06:14 +02:00
parent 1cec0a4e30
commit 8e08efabc9
3 changed files with 32 additions and 8 deletions

View file

@ -29,6 +29,7 @@ class Group():
self.subject = subject
self.subjectOwner = subjectOwner
self.owner = owner
self.joined = False
self.nick = "me"
self.participants = { }

View file

@ -91,9 +91,9 @@ class Session(YowsupApp):
self.bot = Bot(self)
self.imgMsgId = None
self.imgPath = ""
self.imgBuddy = None
self.imgType = ""
self.imgPath = ""
self.imgBuddy = None
self.imgType = ""
def __del__(self): # handleLogoutRequest
@ -223,9 +223,18 @@ class Session(YowsupApp):
self.backend.handleRoomNicknameChanged(
self.user, self._shortenGroupId(room), group.subject
)
group.joined = True
else:
self.logger.warn("Room doesn't exist: %s", room)
def leaveRoom(self, room):
if room in self.groups:
self.logger.info("Leaving room: %s room=%s", self.legacyName, room)
group = self.groups[room]
group.joined = False
else:
self.logger.warn("Room doesn't exist: %s. Unable to leave.", room)
def _refreshParticipants(self, room):
group = self.groups[room]
for jid in group.participants:
@ -681,8 +690,21 @@ class Session(YowsupApp):
else:
self.logger.debug("Group message sent from %s (%s) to %s: %s",
buddy, nick, room, messageContent)
self.backend.handleMessage(self.user, self._shortenGroupId(room),
messageContent, nick, "", timestamp)
try:
group = self.groups[room]
if group.joined:
self.backend.handleMessage(self.user,room, messageContent,
nick, "", timestamp)
else:
self.bot.send("You have received a message in group: %s@%s"
% (room, self.backend.spectrum_jid))
self.bot.send("Join the group in order to reply")
self.bot.send("%s: %s" % (nick, messageContent))
except KeyError:
self.logger.warn("Group is not in group list")
self.backend.handleMessage(self.user, self._shortenGroupId(room),
messageContent, nick, "", timestamp)
def changeStatus(self, status):
if status != self.status:

View file

@ -78,6 +78,10 @@ class WhatsAppBackend(SpectrumBackend):
self.logger.debug("handleJoinRoomRequest(user=%s, room=%s, nickname=%s)", user, room, nickname)
self.sessions[user].joinRoom(room, nickname)
def handleLeaveRoomRequest(self, user, room):
self.logger.debug("handleLeaveRoomRequest(user=%s, room=%s)", user, room)
self.sessions[user].leaveRoom(room)
def handleStatusChangeRequest(self, user, status, statusMessage):
self.logger.debug("handleStatusChangeRequest(user=%s, status=%d, statusMessage=%s)", user, status, statusMessage)
self.sessions[user].changeStatusMessage(statusMessage)
@ -112,9 +116,6 @@ class WhatsAppBackend(SpectrumBackend):
def handleBuddyBlockToggled(self, user, buddy, blocked):
pass
def handleLeaveRoomRequest(self, user, room):
pass
def handleVCardUpdatedRequest(self, user, photo, nickname):
pass