comparison browser_side/richtext.py @ 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 aebb96bfa8d1
children 36ce989c73a5
comparison
equal deleted inserted replaced
279:2d6bd975a72d 280:1ccdc34cfb60
179 data, target = self.host.uni_box.getTargetAndData() 179 data, target = self.host.uni_box.getTargetAndData()
180 self.recipient.setContacts({"To": [target]} if target else {}) 180 self.recipient.setContacts({"To": [target]} if target else {})
181 self.textarea.setText(data if data else "") 181 self.textarea.setText(data if data else "")
182 182
183 def syncToUniBox(self, recipients=None, emptyText=False): 183 def syncToUniBox(self, recipients=None, emptyText=False):
184 """Synchronize to unibox if a maximum of one recipient is set, 184 """Synchronize to unibox if a maximum of one recipient is set.
185 and it is not set to for optional recipient type. That means
186 synchronization is not done if more then one recipients are set
187 or if a recipient is set to an optional type (Cc, Bcc).
188 @return True if the sync could be done, False otherwise""" 185 @return True if the sync could be done, False otherwise"""
189 if recipients is None: 186 if recipients is None:
190 recipients = self.recipient.getContacts() 187 recipients = self.recipient.getContacts()
191 target = "" 188 target = ""
192 # we could eventually allow more in the future 189 # we could eventually allow more in the future
194 for key in recipients: 191 for key in recipients:
195 count = len(recipients[key]) 192 count = len(recipients[key])
196 if count == 0: 193 if count == 0:
197 continue 194 continue
198 allowed -= count 195 allowed -= count
199 if allowed < 0 or composition.RECIPIENT_TYPES[key]["optional"]: 196 if allowed < 0:
200 return False 197 return False
201 # TODO: change this if later more then one recipients are allowed 198 # TODO: change this if later more then one recipients are allowed
202 target = recipients[key][0] 199 target = recipients[key][0]
203 self.host.uni_box.setText("" if emptyText else self.textarea.getText()) 200 self.host.uni_box.setText("" if emptyText else self.textarea.getText())
204 from panels import ChatPanel, MicroblogPanel 201 from panels import ChatPanel, MicroblogPanel
235 " from here.", Width="400px").center() 232 " from here.", Width="400px").center()
236 233
237 def sendMessage(self): 234 def sendMessage(self):
238 """Send the message.""" 235 """Send the message."""
239 recipients = self.recipient.getContacts() 236 recipients = self.recipient.getContacts()
240 for key in recipients:
241 if len(recipients[key]) > 0 and composition.RECIPIENT_TYPES[key]["optional"]:
242 InfoDialog("Feature in development",
243 "Sending a message to Cc or Bcc is not implemented yet!", Width="400px").center()
244 return
245 text = self.textarea.getText() 237 text = self.textarea.getText()
238 targets = []
239 for addr in recipients:
240 for recipient in recipients[addr]:
241 if recipient.startswith("@"):
242 targets.append(("PUBLIC", None, addr) if recipient == "@@" else ("GROUP", recipient[1:], addr))
243 else:
244 targets.append(("chat", recipient, addr))
246 # check that we actually have a message target and data 245 # check that we actually have a message target and data
247 if text == "" or len(recipients["To"]) == 0: 246 if text == "" or len(targets) == 0:
248 InfoDialog("Missing information", 247 InfoDialog("Missing information",
249 "Some information are missing and the message hasn't been sent.", Width="400px").center() 248 "Some information are missing and the message hasn't been sent.", Width="400px").center()
250 return 249 return
251 self.syncToUniBox(recipients, emptyText=True) 250 self.syncToUniBox(recipients, emptyText=True)
252 targets = [] 251 self.host.send(targets, text, extra={'rich': text})
253 for recipient in recipients["To"]:
254 if recipient.startswith("@"):
255 targets.append(("PUBLIC", None) if recipient == "@@" else ("GROUP", recipient[1:]))
256 else:
257 targets.append(("chat", recipient))
258 self.host.send(targets, text, rich=True)
259 self.__close() 252 self.__close()
260 253
261 254
262 class RecipientManager(ListManager): 255 class RecipientManager(ListManager):
263 """A manager for sub-panels to set the recipients for each recipient type.""" 256 """A manager for sub-panels to set the recipients for each recipient type."""