Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_events.py @ 3715:b9718216a1c0 0.9
merge bookmark 0.9
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Dec 2021 16:13:31 +0100 |
parents | 09f5ac48ffe3 |
children | 32b38dd3ac18 |
comparison
equal
deleted
inserted
replaced
3714:af09b5aaa5d7 | 3715:b9718216a1c0 |
---|---|
210 data["item"] = link_elt["item"] | 210 data["item"] = link_elt["item"] |
211 if event_elt.getAttribute("creator") == "true": | 211 if event_elt.getAttribute("creator") == "true": |
212 data["creator"] = True | 212 data["creator"] = True |
213 return timestamp, data | 213 return timestamp, data |
214 | 214 |
215 @defer.inlineCallbacks | 215 async def getEventElement(self, client, service, node, id_): |
216 def getEventElement(self, client, service, node, id_): | |
217 """Retrieve event element | 216 """Retrieve event element |
218 | 217 |
219 @param service(jid.JID): pubsub service | 218 @param service(jid.JID): pubsub service |
220 @param node(unicode): pubsub node | 219 @param node(unicode): pubsub node |
221 @param id_(unicode, None): event id | 220 @param id_(unicode, None): event id |
222 @return (domish.Element): event element | 221 @return (domish.Element): event element |
223 @raise exceptions.NotFound: no event element found | 222 @raise exceptions.NotFound: no event element found |
224 """ | 223 """ |
225 if not id_: | 224 if not id_: |
226 id_ = NS_EVENT | 225 id_ = NS_EVENT |
227 items, metadata = yield self._p.getItems(client, service, node, item_ids=[id_]) | 226 items, metadata = await self._p.getItems(client, service, node, item_ids=[id_]) |
228 try: | 227 try: |
229 event_elt = next(items[0].elements(NS_EVENT, "event")) | 228 event_elt = next(items[0].elements(NS_EVENT, "event")) |
230 except StopIteration: | 229 except StopIteration: |
231 raise exceptions.NotFound(_("No event element has been found")) | 230 raise exceptions.NotFound(_("No event element has been found")) |
232 except IndexError: | 231 except IndexError: |
233 raise exceptions.NotFound(_("No event with this id has been found")) | 232 raise exceptions.NotFound(_("No event with this id has been found")) |
234 defer.returnValue(event_elt) | 233 return event_elt |
235 | 234 |
236 def _eventGet(self, service, node, id_="", profile_key=C.PROF_KEY_NONE): | 235 def _eventGet(self, service, node, id_="", profile_key=C.PROF_KEY_NONE): |
237 service = jid.JID(service) if service else None | 236 service = jid.JID(service) if service else None |
238 node = node if node else NS_EVENT | 237 node = node if node else NS_EVENT |
239 client = self.host.getClient(profile_key) | 238 client = self.host.getClient(profile_key) |
240 return self.eventGet(client, service, node, id_) | 239 return defer.ensureDeferred( |
241 | 240 self.eventGet(client, service, node, id_) |
242 @defer.inlineCallbacks | 241 ) |
243 def eventGet(self, client, service, node, id_=NS_EVENT): | 242 |
243 async def eventGet(self, client, service, node, id_=NS_EVENT): | |
244 """Retrieve event data | 244 """Retrieve event data |
245 | 245 |
246 @param service(unicode, None): PubSub service | 246 @param service(unicode, None): PubSub service |
247 @param node(unicode): PubSub node of the event | 247 @param node(unicode): PubSub node of the event |
248 @param id_(unicode): id_ with even data | 248 @param id_(unicode): id_ with even data |
251 - event metadata where key can be: | 251 - event metadata where key can be: |
252 location: location of the event | 252 location: location of the event |
253 image: URL of a picture to use to represent event | 253 image: URL of a picture to use to represent event |
254 background-image: URL of a picture to use in background | 254 background-image: URL of a picture to use in background |
255 """ | 255 """ |
256 event_elt = yield self.getEventElement(client, service, node, id_) | 256 event_elt = await self.getEventElement(client, service, node, id_) |
257 | 257 |
258 defer.returnValue(self._parseEventElt(event_elt)) | 258 return self._parseEventElt(event_elt) |
259 | 259 |
260 def _eventCreate( | 260 def _eventCreate( |
261 self, timestamp, data, service, node, id_="", profile_key=C.PROF_KEY_NONE | 261 self, timestamp, data, service, node, id_="", profile_key=C.PROF_KEY_NONE |
262 ): | 262 ): |
263 service = jid.JID(service) if service else None | 263 service = jid.JID(service) if service else None |
435 def _eventInviteeGet(self, service, node, invitee_jid_s, profile_key): | 435 def _eventInviteeGet(self, service, node, invitee_jid_s, profile_key): |
436 service = jid.JID(service) if service else None | 436 service = jid.JID(service) if service else None |
437 node = node if node else NS_EVENT | 437 node = node if node else NS_EVENT |
438 client = self.host.getClient(profile_key) | 438 client = self.host.getClient(profile_key) |
439 invitee_jid = jid.JID(invitee_jid_s) if invitee_jid_s else None | 439 invitee_jid = jid.JID(invitee_jid_s) if invitee_jid_s else None |
440 return self.eventInviteeGet(client, service, node, invitee_jid) | 440 return defer.ensureDeferred( |
441 | 441 self.eventInviteeGet(client, service, node, invitee_jid) |
442 @defer.inlineCallbacks | 442 ) |
443 def eventInviteeGet(self, client, service, node, invitee_jid=None): | 443 |
444 async def eventInviteeGet(self, client, service, node, invitee_jid=None): | |
444 """Retrieve attendance from event node | 445 """Retrieve attendance from event node |
445 | 446 |
446 @param service(unicode, None): PubSub service | 447 @param service(unicode, None): PubSub service |
447 @param node(unicode): PubSub node of the event's invitees | 448 @param node(unicode): PubSub node of the event's invitees |
448 @param invitee_jid(jid.JId, None): jid of the invitee to retrieve (None to | 449 @param invitee_jid(jid.JId, None): jid of the invitee to retrieve (None to |
451 an empty dict is returned if nothing has been answered yed | 452 an empty dict is returned if nothing has been answered yed |
452 """ | 453 """ |
453 if invitee_jid is None: | 454 if invitee_jid is None: |
454 invitee_jid = client.jid | 455 invitee_jid = client.jid |
455 try: | 456 try: |
456 items, metadata = yield self._p.getItems( | 457 items, metadata = await self._p.getItems( |
457 client, service, node, item_ids=[invitee_jid.userhost()] | 458 client, service, node, item_ids=[invitee_jid.userhost()] |
458 ) | 459 ) |
459 event_elt = next(items[0].elements(NS_EVENT, "invitee")) | 460 event_elt = next(items[0].elements(NS_EVENT, "invitee")) |
460 except (exceptions.NotFound, IndexError): | 461 except (exceptions.NotFound, IndexError): |
461 # no item found, event data are not set yet | 462 # no item found, event data are not set yet |
462 defer.returnValue({}) | 463 return {} |
463 data = {} | 464 data = {} |
464 for key in ("attend", "guests"): | 465 for key in ("attend", "guests"): |
465 try: | 466 try: |
466 data[key] = event_elt[key] | 467 data[key] = event_elt[key] |
467 except KeyError: | 468 except KeyError: |
468 continue | 469 continue |
469 defer.returnValue(data) | 470 return data |
470 | 471 |
471 def _eventInviteeSet(self, service, node, event_data, profile_key): | 472 def _eventInviteeSet(self, service, node, event_data, profile_key): |
472 service = jid.JID(service) if service else None | 473 service = jid.JID(service) if service else None |
473 node = node if node else NS_EVENT | 474 node = node if node else NS_EVENT |
474 client = self.host.getClient(profile_key) | 475 client = self.host.getClient(profile_key) |
475 return self.eventInviteeSet(client, service, node, event_data) | 476 return defer.ensureDeferred( |
476 | 477 self.eventInviteeSet(client, service, node, event_data) |
477 def eventInviteeSet(self, client, service, node, data): | 478 ) |
479 | |
480 async def eventInviteeSet(self, client, service, node, data): | |
478 """Set or update attendance data in event node | 481 """Set or update attendance data in event node |
479 | 482 |
480 @param service(unicode, None): PubSub service | 483 @param service(unicode, None): PubSub service |
481 @param node(unicode): PubSub node of the event | 484 @param node(unicode): PubSub node of the event |
482 @param data(dict[unicode, unicode]): data to update | 485 @param data(dict[unicode, unicode]): data to update |
489 try: | 492 try: |
490 event_elt[key] = data.pop(key) | 493 event_elt[key] = data.pop(key) |
491 except KeyError: | 494 except KeyError: |
492 pass | 495 pass |
493 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt) | 496 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt) |
494 return self._p.publish(client, service, node, items=[item_elt]) | 497 return await self._p.publish(client, service, node, items=[item_elt]) |
495 | 498 |
496 def _eventInviteesList(self, service, node, profile_key): | 499 def _eventInviteesList(self, service, node, profile_key): |
497 service = jid.JID(service) if service else None | 500 service = jid.JID(service) if service else None |
498 node = node if node else NS_EVENT | 501 node = node if node else NS_EVENT |
499 client = self.host.getClient(profile_key) | 502 client = self.host.getClient(profile_key) |
500 return self.eventInviteesList(client, service, node) | 503 return defer.ensureDeferred( |
501 | 504 self.eventInviteesList(client, service, node) |
502 @defer.inlineCallbacks | 505 ) |
503 def eventInviteesList(self, client, service, node): | 506 |
507 async def eventInviteesList(self, client, service, node): | |
504 """Retrieve attendance from event node | 508 """Retrieve attendance from event node |
505 | 509 |
506 @param service(unicode, None): PubSub service | 510 @param service(unicode, None): PubSub service |
507 @param node(unicode): PubSub node of the event | 511 @param node(unicode): PubSub node of the event |
508 @return (dict): a dict with current attendance status, | 512 @return (dict): a dict with current attendance status, |
509 an empty dict is returned if nothing has been answered yed | 513 an empty dict is returned if nothing has been answered yed |
510 """ | 514 """ |
511 items, metadata = yield self._p.getItems(client, service, node) | 515 items, metadata = await self._p.getItems(client, service, node) |
512 invitees = {} | 516 invitees = {} |
513 for item in items: | 517 for item in items: |
514 try: | 518 try: |
515 event_elt = next(item.elements(NS_EVENT, "invitee")) | 519 event_elt = next(item.elements(NS_EVENT, "invitee")) |
516 except StopIteration: | 520 except StopIteration: |
524 try: | 528 try: |
525 data[key] = event_elt[key] | 529 data[key] = event_elt[key] |
526 except KeyError: | 530 except KeyError: |
527 continue | 531 continue |
528 invitees[item["id"]] = data | 532 invitees[item["id"]] = data |
529 defer.returnValue(invitees) | 533 return invitees |
530 | 534 |
531 async def invitePreflight( | 535 async def invitePreflight( |
532 self, | 536 self, |
533 client: SatXMPPEntity, | 537 client: SatXMPPEntity, |
534 invitee_jid: jid.JID, | 538 invitee_jid: jid.JID, |