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:
parent
1cec0a4e30
commit
8e08efabc9
1
group.py
1
group.py
|
@ -29,6 +29,7 @@ class Group():
|
|||
self.subject = subject
|
||||
self.subjectOwner = subjectOwner
|
||||
self.owner = owner
|
||||
self.joined = False
|
||||
|
||||
self.nick = "me"
|
||||
self.participants = { }
|
||||
|
|
22
session.py
22
session.py
|
@ -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,9 +690,22 @@ class Session(YowsupApp):
|
|||
else:
|
||||
self.logger.debug("Group message sent from %s (%s) to %s: %s",
|
||||
buddy, nick, room, messageContent)
|
||||
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:
|
||||
self.logger.info("Status changed: %s", status)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue