Add functionality to receive broadcast messages
This commit is contained in:
parent
8e1be86319
commit
7b327c2d0f
59
session.py
59
session.py
|
@ -54,6 +54,7 @@ class MsgIDs:
|
||||||
|
|
||||||
|
|
||||||
class Session(YowsupApp):
|
class Session(YowsupApp):
|
||||||
|
broadcast_prefix = u'\U0001F4E2 '
|
||||||
|
|
||||||
def __init__(self, backend, user, legacyName, extra):
|
def __init__(self, backend, user, legacyName, extra):
|
||||||
super(Session, self).__init__()
|
super(Session, self).__init__()
|
||||||
|
@ -276,20 +277,18 @@ class Session(YowsupApp):
|
||||||
self.sendReceipt(_id, _from, None, participant)
|
self.sendReceipt(_id, _from, None, participant)
|
||||||
self.logger.info("Message received from %s to %s: %s (at ts=%s)",
|
self.logger.info("Message received from %s to %s: %s (at ts=%s)",
|
||||||
buddy, self.legacyName, messageContent, timestamp)
|
buddy, self.legacyName, messageContent, timestamp)
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message or broadcast
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
if _from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
message = self.broadcast_prefix + messageContent
|
||||||
|
self.sendMessageToXMPP(partname, message, timestamp)
|
||||||
|
else: # Group message
|
||||||
if notify is None:
|
if notify is None:
|
||||||
notify = ""
|
notify = ""
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
|
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
|
||||||
timestamp, notify)
|
timestamp, notify)
|
||||||
else:
|
else:
|
||||||
self.sendMessageToXMPP(buddy, messageContent, timestamp)
|
self.sendMessageToXMPP(buddy, messageContent, timestamp)
|
||||||
# isBroadcast always returns false, I'm not sure how to get a broadcast
|
|
||||||
# message.
|
|
||||||
#if messageEntity.isBroadcast():
|
|
||||||
# self.logger.info("Broadcast received from %s to %s: %s (at ts=%s)",\
|
|
||||||
# buddy, self.legacyName, messageContent, timestamp)
|
|
||||||
# messageContent = "[Broadcast] " + messageContent
|
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onImage(self, image):
|
def onImage(self, image):
|
||||||
|
@ -301,9 +300,12 @@ class Session(YowsupApp):
|
||||||
message = image.url + ' ' + image.caption
|
message = image.url + ' ' + image.caption
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
if image._from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, image.timestamp)
|
||||||
|
self.sendMessageToXMPP(partname, message, image.timestamp)
|
||||||
|
else: # Group message
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, message, image.timestamp)
|
self.sendGroupMessageToXMPP(buddy, partname, message, image.timestamp)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
self.sendMessageToXMPP(buddy, message, image.timestamp)
|
self.sendMessageToXMPP(buddy, message, image.timestamp)
|
||||||
self.sendReceipt(image._id, image._from, None, image.participant)
|
self.sendReceipt(image._id, image._from, None, image.participant)
|
||||||
|
|
||||||
|
@ -315,9 +317,12 @@ class Session(YowsupApp):
|
||||||
message = audio.url
|
message = audio.url
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
if audio._from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, audio.timestamp)
|
||||||
|
self.sendMessageToXMPP(partname, message, audio.timestamp)
|
||||||
|
else: # Group message
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, message, audio.timestamp)
|
self.sendGroupMessageToXMPP(buddy, partname, message, audio.timestamp)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
self.sendMessageToXMPP(buddy, message, audio.timestamp)
|
self.sendMessageToXMPP(buddy, message, audio.timestamp)
|
||||||
self.sendReceipt(audio._id, audio._from, None, audio.participant)
|
self.sendReceipt(audio._id, audio._from, None, audio.participant)
|
||||||
|
|
||||||
|
@ -330,9 +335,12 @@ class Session(YowsupApp):
|
||||||
message = video.url
|
message = video.url
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
if video._from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, video.timestamp)
|
||||||
|
self.sendMessageToXMPP(partname, message, video.timestamp)
|
||||||
|
else: # Group message
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, message, video.timestamp)
|
self.sendGroupMessageToXMPP(buddy, partname, message, video.timestamp)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
self.sendMessageToXMPP(buddy, message, video.timestamp)
|
self.sendMessageToXMPP(buddy, message, video.timestamp)
|
||||||
self.sendReceipt(video._id, video._from, None, video.participant)
|
self.sendReceipt(video._id, video._from, None, video.participant)
|
||||||
|
|
||||||
|
@ -340,23 +348,30 @@ class Session(YowsupApp):
|
||||||
buddy = location._from.split('@')[0]
|
buddy = location._from.split('@')[0]
|
||||||
latitude = location.getLatitude()
|
latitude = location.getLatitude()
|
||||||
longitude = location.getLongitude()
|
longitude = location.getLongitude()
|
||||||
url = location.getLocationUrl()
|
url = location.getLocationURL()
|
||||||
participant = location.participant
|
participant = location.participant
|
||||||
|
latlong = 'geo:' + latitude + ',' + longitude
|
||||||
|
|
||||||
self.logger.debug("Location received from %s: %s, %s",
|
self.logger.debug("Location received from %s: %s, %s",
|
||||||
buddy, latitude, longitude)
|
buddy, latitude, longitude)
|
||||||
|
|
||||||
|
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
if location._from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, location.timestamp)
|
||||||
|
if url is not None:
|
||||||
|
self.sendMessageToXMPP(partname, url, location.timestamp)
|
||||||
|
self.sendMessageToXMPP(partname, latlong, location.timestamp)
|
||||||
|
else: # Group message
|
||||||
|
if url is not None:
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, url, location.timestamp)
|
self.sendGroupMessageToXMPP(buddy, partname, url, location.timestamp)
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, 'geo:' + latitude + ',' + longitude,
|
self.sendGroupMessageToXMPP(buddy, partname, latlong, location.timestamp)
|
||||||
location.timestamp)
|
|
||||||
else:
|
else:
|
||||||
|
if url is not None:
|
||||||
self.sendMessageToXMPP(buddy, url, location.timestamp)
|
self.sendMessageToXMPP(buddy, url, location.timestamp)
|
||||||
self.sendMessageToXMPP(buddy, 'geo:' + latitude + ',' + longitude,
|
self.sendMessageToXMPP(buddy, latlong, location.timestamp)
|
||||||
location.timestamp)
|
self.sendReceipt(location._id, location._from, None, location.participant)
|
||||||
self.sendReceipt(location._id, location._from, None, location.participant, location.timestamp)
|
|
||||||
|
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
|
@ -366,13 +381,17 @@ class Session(YowsupApp):
|
||||||
_id, _from, name, card_data, to, notify, timestamp, participant
|
_id, _from, name, card_data, to, notify, timestamp, participant
|
||||||
]))
|
]))
|
||||||
)
|
)
|
||||||
|
message = "Received VCard (not implemented yet)"
|
||||||
buddy = _from.split("@")[0]
|
buddy = _from.split("@")[0]
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, "Received VCard (not implemented yet)", timestamp)
|
if _from.split('@')[1] == 'broadcast': # Broadcast message
|
||||||
|
message = self.broadcast_prefix + message
|
||||||
|
self.sendMessageToXMPP(partname, message, timestamp)
|
||||||
|
else: # Group message
|
||||||
|
self.sendGroupMessageToXMPP(buddy, partname, message, timestamp)
|
||||||
else:
|
else:
|
||||||
|
self.sendMessageToXMPP(buddy, message, timestamp)
|
||||||
self.sendMessageToXMPP(buddy, "Received VCard (not implemented yet)")
|
|
||||||
# self.sendMessageToXMPP(buddy, card_data)
|
# self.sendMessageToXMPP(buddy, card_data)
|
||||||
#self.transferFile(buddy, str(name), card_data)
|
#self.transferFile(buddy, str(name), card_data)
|
||||||
self.sendReceipt(_id, _from, None, participant)
|
self.sendReceipt(_id, _from, None, participant)
|
||||||
|
|
Loading…
Reference in a new issue