Mercurial > libervia-web
changeset 280:1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 04 Dec 2013 21:52:30 +0100 |
parents | 2d6bd975a72d |
children | 36ce989c73a5 |
files | browser_side/richtext.py libervia.py |
diffstat | 2 files changed, 25 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/richtext.py Sat Nov 23 14:46:03 2013 +0100 +++ b/browser_side/richtext.py Wed Dec 04 21:52:30 2013 +0100 @@ -181,10 +181,7 @@ self.textarea.setText(data if data else "") def syncToUniBox(self, recipients=None, emptyText=False): - """Synchronize to unibox if a maximum of one recipient is set, - and it is not set to for optional recipient type. That means - synchronization is not done if more then one recipients are set - or if a recipient is set to an optional type (Cc, Bcc). + """Synchronize to unibox if a maximum of one recipient is set. @return True if the sync could be done, False otherwise""" if recipients is None: recipients = self.recipient.getContacts() @@ -196,7 +193,7 @@ if count == 0: continue allowed -= count - if allowed < 0 or composition.RECIPIENT_TYPES[key]["optional"]: + if allowed < 0: return False # TODO: change this if later more then one recipients are allowed target = recipients[key][0] @@ -237,25 +234,21 @@ def sendMessage(self): """Send the message.""" recipients = self.recipient.getContacts() - for key in recipients: - if len(recipients[key]) > 0 and composition.RECIPIENT_TYPES[key]["optional"]: - InfoDialog("Feature in development", - "Sending a message to Cc or Bcc is not implemented yet!", Width="400px").center() - return text = self.textarea.getText() + targets = [] + for addr in recipients: + for recipient in recipients[addr]: + if recipient.startswith("@"): + targets.append(("PUBLIC", None, addr) if recipient == "@@" else ("GROUP", recipient[1:], addr)) + else: + targets.append(("chat", recipient, addr)) # check that we actually have a message target and data - if text == "" or len(recipients["To"]) == 0: + if text == "" or len(targets) == 0: InfoDialog("Missing information", "Some information are missing and the message hasn't been sent.", Width="400px").center() return self.syncToUniBox(recipients, emptyText=True) - targets = [] - for recipient in recipients["To"]: - if recipient.startswith("@"): - targets.append(("PUBLIC", None) if recipient == "@@" else ("GROUP", recipient[1:])) - else: - targets.append(("chat", recipient)) - self.host.send(targets, text, rich=True) + self.host.send(targets, text, extra={'rich': text}) self.__close()
--- a/libervia.py Sat Nov 23 14:46:03 2013 +0100 +++ b/libervia.py Wed Dec 04 21:52:30 2013 +0100 @@ -723,17 +723,19 @@ def _newAlert(self, message, title, alert_type): dialog.InfoDialog(title, message).show() - def send(self, targets, text, rich=False): + def send(self, targets, text, extra={}): """Send a message to any target type. - @param targets: list of couple (type, entities) with: + @param targets: list of tuples (type, entities, addr) with: - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat") - entities could be a JID, a list groups, a node hash... depending the target + - addr in ("To", "Cc", "Bcc") - ignore case @param text: the message content - @param rich: set to True if the message is sent as a rich text message. + @param extra: options """ # FIXME: too many magic strings, we should use constants instead - extra = {"rich": text} if rich else {} - for type_, entities in targets: + addresses = [] + for target in targets: + type_, entities, addr = target[0], target[1], 'to' if len(target) < 3 else target[2].lower() if type_ in ("PUBLIC", "GROUP"): self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra) elif type_ == "COMMENT": @@ -741,9 +743,15 @@ elif type_ == "STATUS": self.bridge.call('setStatus', None, self.status_panel.presence, text) elif type_ in ("groupchat", "chat"): - self.bridge.call('sendMessage', None, entities, text, '', type_, extra) + addresses.append((addr, entities)) else: print "ERROR: Unknown target type" + if addresses: + if len(addresses) == 1 and addresses[0][0] == 'to': + self.bridge.call('sendMessage', None, addresses[0][1], text, '', type_, extra) + else: + extra.update({'address': '\n'.join([('%s:%s' % entry) for entry in addresses])}) + self.bridge.call('sendMessage', None, self.whoami.domain, text, '', type_, extra) if __name__ == '__main__':