# HG changeset patch # User souliane # Date 1386190350 -3600 # Node ID 1ccdc34cfb60dd0ae71f8e3d46137381ae897070 # Parent 2d6bd975a72d3f5b7fde0392c4956d9ad7d226af browser_side: changes related to the implementation of XEP-0033 (addressing) diff -r 2d6bd975a72d -r 1ccdc34cfb60 browser_side/richtext.py --- 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() diff -r 2d6bd975a72d -r 1ccdc34cfb60 libervia.py --- 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__':