Add functionality to receive broadcast messages

This commit is contained in:
moyamo 2016-01-06 18:31:42 +02:00
parent 8e1be86319
commit 7b327c2d0f

View file

@ -54,6 +54,7 @@ class MsgIDs:
class Session(YowsupApp):
broadcast_prefix = u'\U0001F4E2 '
def __init__(self, backend, user, legacyName, extra):
super(Session, self).__init__()
@ -276,20 +277,18 @@ class Session(YowsupApp):
self.sendReceipt(_id, _from, None, participant)
self.logger.info("Message received from %s to %s: %s (at ts=%s)",
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]
if _from.split('@')[1] == 'broadcast': # Broadcast message
message = self.broadcast_prefix + messageContent
self.sendMessageToXMPP(partname, message, timestamp)
else: # Group message
if notify is None:
notify = ""
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
timestamp, notify)
else:
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
def onImage(self, image):
@ -301,9 +300,12 @@ class Session(YowsupApp):
message = image.url + ' ' + image.caption
if participant is not None: # Group message
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)
else:
self.sendMessageToXMPP(buddy, message, image.timestamp)
self.sendReceipt(image._id, image._from, None, image.participant)
@ -315,9 +317,12 @@ class Session(YowsupApp):
message = audio.url
if participant is not None: # Group message
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)
else:
self.sendMessageToXMPP(buddy, message, audio.timestamp)
self.sendReceipt(audio._id, audio._from, None, audio.participant)
@ -330,9 +335,12 @@ class Session(YowsupApp):
message = video.url
if participant is not None: # Group message
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)
else:
self.sendMessageToXMPP(buddy, message, video.timestamp)
self.sendReceipt(video._id, video._from, None, video.participant)
@ -340,23 +348,30 @@ class Session(YowsupApp):
buddy = location._from.split('@')[0]
latitude = location.getLatitude()
longitude = location.getLongitude()
url = location.getLocationUrl()
url = location.getLocationURL()
participant = location.participant
latlong = 'geo:' + latitude + ',' + longitude
self.logger.debug("Location received from %s: %s, %s",
buddy, latitude, longitude)
if participant is not None: # Group message
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, 'geo:' + latitude + ',' + longitude,
location.timestamp)
self.sendGroupMessageToXMPP(buddy, partname, latlong, location.timestamp)
else:
if url is not None:
self.sendMessageToXMPP(buddy, url, location.timestamp)
self.sendMessageToXMPP(buddy, 'geo:' + latitude + ',' + longitude,
location.timestamp)
self.sendReceipt(location._id, location._from, None, location.participant, location.timestamp)
self.sendMessageToXMPP(buddy, latlong, location.timestamp)
self.sendReceipt(location._id, location._from, None, location.participant)
# Called by superclass
@ -366,13 +381,17 @@ class Session(YowsupApp):
_id, _from, name, card_data, to, notify, timestamp, participant
]))
)
message = "Received VCard (not implemented yet)"
buddy = _from.split("@")[0]
if participant is not None: # Group message
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:
self.sendMessageToXMPP(buddy, "Received VCard (not implemented yet)")
self.sendMessageToXMPP(buddy, message, timestamp)
# self.sendMessageToXMPP(buddy, card_data)
#self.transferFile(buddy, str(name), card_data)
self.sendReceipt(_id, _from, None, participant)