Mercurial > libervia-backend
comparison src/plugins/plugin_misc_groupblog.py @ 916:1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 16:27:09 +0100 |
parents | 58107179cd97 |
children | fc7e0828b18e |
comparison
equal
deleted
inserted
replaced
915:6f96ee4d8cc0 | 916:1a759096ccbd |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | |
21 from logging import debug, info, warning, error | 22 from logging import debug, info, warning, error |
22 from twisted.internet import defer | 23 from twisted.internet import defer |
23 from twisted.words.protocols.jabber import jid | 24 from twisted.words.protocols.jabber import jid |
24 from twisted.words.xish.domish import Element | 25 from twisted.words.xish.domish import Element |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
355 | 356 |
356 def _mblogPublicationFailed(self, failure): | 357 def _mblogPublicationFailed(self, failure): |
357 #TODO | 358 #TODO |
358 return failure | 359 return failure |
359 | 360 |
360 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key='@NONE@'): | 361 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key=C.PROF_KEY_NONE): |
361 """Publish a microblog with given item access | 362 """Publish a microblog with given item access |
362 @param access_type: one of "PUBLIC", "GROUP", "JID" | 363 @param access_type: one of "PUBLIC", "GROUP", "JID" |
363 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, | 364 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, |
364 list of groups or list of jids) for this item | 365 list of groups or list of jids) for this item |
365 @param message: microblog | 366 @param message: microblog |
386 error(_("Unknown access type")) | 387 error(_("Unknown access type")) |
387 raise BadAccessTypeError | 388 raise BadAccessTypeError |
388 | 389 |
389 return self._initialise(profile_key).addCallback(initialised) | 390 return self._initialise(profile_key).addCallback(initialised) |
390 | 391 |
391 def deleteGroupBlog(self, pub_data, comments, profile_key='@NONE@'): | 392 def deleteGroupBlog(self, pub_data, comments, profile_key=C.PROF_KEY_NONE): |
392 """Delete a microblog item from a node. | 393 """Delete a microblog item from a node. |
393 @param pub_data: a tuple (service, node identifier, item identifier) | 394 @param pub_data: a tuple (service, node identifier, item identifier) |
394 @param comments: comments node identifier (for main item) or empty string | 395 @param comments: comments node identifier (for main item) or empty string |
395 @param profile_key: %(doc_profile_key)s | 396 @param profile_key: %(doc_profile_key)s |
396 """ | 397 """ |
423 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG_DELETE", gbdatum, profile) | 424 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG_DELETE", gbdatum, profile) |
424 return d | 425 return d |
425 | 426 |
426 return self._initialise(profile_key).addCallback(initialised).addCallback(notify) | 427 return self._initialise(profile_key).addCallback(initialised).addCallback(notify) |
427 | 428 |
428 def updateGroupBlog(self, pub_data, comments, message, extra, profile_key='@NONE@'): | 429 def updateGroupBlog(self, pub_data, comments, message, extra, profile_key=C.PROF_KEY_NONE): |
429 """Modify a microblog node | 430 """Modify a microblog node |
430 @param pub_data: a tuple (service, node identifier, item identifier) | 431 @param pub_data: a tuple (service, node identifier, item identifier) |
431 @param comments: comments node identifier (for main item) or empty string | 432 @param comments: comments node identifier (for main item) or empty string |
432 @param message: new message | 433 @param message: new message |
433 @param extra: dict which option name as key, which can be: | 434 @param extra: dict which option name as key, which can be: |
460 entry_d.addErrback(lambda failure: error("Modification of %s failed: %s" % (pub_data, failure.getErrorMessage()))) | 461 entry_d.addErrback(lambda failure: error("Modification of %s failed: %s" % (pub_data, failure.getErrorMessage()))) |
461 return entry_d | 462 return entry_d |
462 | 463 |
463 return self._initialise(profile_key).addCallback(initialised) | 464 return self._initialise(profile_key).addCallback(initialised) |
464 | 465 |
465 def sendGroupBlogComment(self, node_url, message, extra, profile_key='@NONE@'): | 466 def sendGroupBlogComment(self, node_url, message, extra, profile_key=C.PROF_KEY_NONE): |
466 """Publish a comment in the given node | 467 """Publish a comment in the given node |
467 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key | 468 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key |
468 @param message: comment | 469 @param message: comment |
469 @param extra: dict which option name as key, which can be: | 470 @param extra: dict which option name as key, which can be: |
470 - allow_comments: True to accept an other level of comments, False else (default: False) | 471 - allow_comments: True to accept an other level of comments, False else (default: False) |
512 profile_key=client.profile) | 513 profile_key=client.profile) |
513 except KeyError: | 514 except KeyError: |
514 warning("Missing key for comments") | 515 warning("Missing key for comments") |
515 defer.returnValue(ret) | 516 defer.returnValue(ret) |
516 | 517 |
517 def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key='@NONE@'): | 518 def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key=C.PROF_KEY_NONE): |
518 """Retrieve previously published items from a publish subscribe node. | 519 """Retrieve previously published items from a publish subscribe node. |
519 @param pub_jid_s: jid of the publisher | 520 @param pub_jid_s: jid of the publisher |
520 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) | 521 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
521 @param item_ids: list of microblogs items IDs | 522 @param item_ids: list of microblogs items IDs |
522 @param profile_key: profile key | 523 @param profile_key: profile key |
533 return d | 534 return d |
534 | 535 |
535 #TODO: we need to use the server corresponding the the host of the jid | 536 #TODO: we need to use the server corresponding the the host of the jid |
536 return self._initialise(profile_key).addCallback(initialised) | 537 return self._initialise(profile_key).addCallback(initialised) |
537 | 538 |
538 def getGroupBlogs(self, pub_jid_s, item_ids=None, profile_key='@NONE@'): | 539 def getGroupBlogs(self, pub_jid_s, item_ids=None, profile_key=C.PROF_KEY_NONE): |
539 """Get the published microblogs of the specified IDs. If item_ids is | 540 """Get the published microblogs of the specified IDs. If item_ids is |
540 None, the result would be the same than calling getLastGroupBlogs | 541 None, the result would be the same than calling getLastGroupBlogs |
541 with the default value for the attribute max_items. | 542 with the default value for the attribute max_items. |
542 @param pub_jid_s: jid of the publisher | 543 @param pub_jid_s: jid of the publisher |
543 @param item_ids: list of microblogs items IDs | 544 @param item_ids: list of microblogs items IDs |
544 @param profile_key: profile key | 545 @param profile_key: profile key |
545 @return: list of microblog data (dict) | 546 @return: list of microblog data (dict) |
546 """ | 547 """ |
547 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) | 548 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) |
548 | 549 |
549 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key='@NONE@'): | 550 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key=C.PROF_KEY_NONE): |
550 """Get the published microblogs of the specified IDs and their comments. If | 551 """Get the published microblogs of the specified IDs and their comments. If |
551 item_ids is None, returns the last published microblogs and their comments. | 552 item_ids is None, returns the last published microblogs and their comments. |
552 @param pub_jid_s: jid of the publisher | 553 @param pub_jid_s: jid of the publisher |
553 @param item_ids: list of microblogs items IDs | 554 @param item_ids: list of microblogs items IDs |
554 @param profile_key: profile key | 555 @param profile_key: profile key |
570 d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) | 571 d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) |
571 d.addCallback(get_comments) | 572 d.addCallback(get_comments) |
572 return d | 573 return d |
573 | 574 |
574 | 575 |
575 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'): | 576 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key=C.PROF_KEY_NONE): |
576 """Get the last published microblogs | 577 """Get the last published microblogs |
577 @param pub_jid_s: jid of the publisher | 578 @param pub_jid_s: jid of the publisher |
578 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) | 579 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
579 @param profile_key: profile key | 580 @param profile_key: profile key |
580 @return: list of microblog data (dict) | 581 @return: list of microblog data (dict) |
581 """ | 582 """ |
582 return self.__getGroupBlogs(pub_jid_s, max_items=max_items, profile_key=profile_key) | 583 return self.__getGroupBlogs(pub_jid_s, max_items=max_items, profile_key=profile_key) |
583 | 584 |
584 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'): | 585 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key=C.PROF_KEY_NONE): |
585 """Get the atom feed of the last published microblogs | 586 """Get the atom feed of the last published microblogs |
586 @param pub_jid: jid of the publisher | 587 @param pub_jid: jid of the publisher |
587 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) | 588 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
588 @param profile_key: profile key | 589 @param profile_key: profile key |
589 @return: atom XML feed (unicode) | 590 @return: atom XML feed (unicode) |
626 return d | 627 return d |
627 | 628 |
628 #TODO: we need to use the server corresponding the the host of the jid | 629 #TODO: we need to use the server corresponding the the host of the jid |
629 return self._initialise(profile_key).addCallback(initialised) | 630 return self._initialise(profile_key).addCallback(initialised) |
630 | 631 |
631 def getGroupBlogComments(self, service_s, node, profile_key='@NONE@'): | 632 def getGroupBlogComments(self, service_s, node, profile_key=C.PROF_KEY_NONE): |
632 """Get all comments of given node | 633 """Get all comments of given node |
633 @param service_s: service hosting the node | 634 @param service_s: service hosting the node |
634 @param node: comments node | 635 @param node: comments node |
635 @param profile_key: profile key | 636 @param profile_key: profile key |
636 @return: list of microblog data (dict) | 637 @return: list of microblog data (dict) |
646 return d | 647 return d |
647 | 648 |
648 #TODO: we need to use the server corresponding the the host of the jid | 649 #TODO: we need to use the server corresponding the the host of the jid |
649 return self._initialise(profile_key).addCallback(initialised) | 650 return self._initialise(profile_key).addCallback(initialised) |
650 | 651 |
651 def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'): | 652 def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key=C.PROF_KEY_NONE): |
652 if publishers_type == 'JID': | 653 if publishers_type == 'JID': |
653 publishers_jids = [jid.JID(publisher) for publisher in publishers] | 654 publishers_jids = [jid.JID(publisher) for publisher in publishers] |
654 else: | 655 else: |
655 publishers_jids = publishers | 656 publishers_jids = publishers |
656 return self.getMassiveLastGroupBlogs(publishers_type, publishers_jids, max_items, profile_key) | 657 return self.getMassiveLastGroupBlogs(publishers_type, publishers_jids, max_items, profile_key) |
657 | 658 |
658 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'): | 659 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key=C.PROF_KEY_NONE): |
659 """Get the last published microblogs for a list of groups or jids | 660 """Get the last published microblogs for a list of groups or jids |
660 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") | 661 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
661 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) | 662 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) |
662 @param max_items: how many microblogs we want to get | 663 @param max_items: how many microblogs we want to get |
663 @param profile_key: profile key | 664 @param profile_key: profile key |
713 if publishers_type == "ALL" and publishers: | 714 if publishers_type == "ALL" and publishers: |
714 raise Exception("Publishers list must be empty when getting microblogs for all contacts") | 715 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
715 return self._initialise(profile_key).addCallback(initialised) | 716 return self._initialise(profile_key).addCallback(initialised) |
716 #TODO: we need to use the server corresponding the the host of the jid | 717 #TODO: we need to use the server corresponding the the host of the jid |
717 | 718 |
718 def subscribeGroupBlog(self, pub_jid, profile_key='@NONE@'): | 719 def subscribeGroupBlog(self, pub_jid, profile_key=C.PROF_KEY_NONE): |
719 def initialised(result): | 720 def initialised(result): |
720 profile, client = result | 721 profile, client = result |
721 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), | 722 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), |
722 profile_key=profile_key) | 723 profile_key=profile_key) |
723 return d | 724 return d |
724 | 725 |
725 #TODO: we need to use the server corresponding the the host of the jid | 726 #TODO: we need to use the server corresponding the the host of the jid |
726 return self._initialise(profile_key).addCallback(initialised) | 727 return self._initialise(profile_key).addCallback(initialised) |
727 | 728 |
728 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'): | 729 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE): |
729 if publishers_type == 'JID': | 730 if publishers_type == 'JID': |
730 publishers_jids = [jid.JID(publisher) for publisher in publishers] | 731 publishers_jids = [jid.JID(publisher) for publisher in publishers] |
731 else: | 732 else: |
732 publishers_jids = publishers | 733 publishers_jids = publishers |
733 return self.massiveSubscribeGroupBlogs(publishers_type, publishers_jids, profile_key) | 734 return self.massiveSubscribeGroupBlogs(publishers_type, publishers_jids, profile_key) |
734 | 735 |
735 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'): | 736 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE): |
736 """Subscribe microblogs for a list of groups or jids | 737 """Subscribe microblogs for a list of groups or jids |
737 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") | 738 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
738 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) | 739 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) |
739 @param profile_key: profile key | 740 @param profile_key: profile key |
740 """ | 741 """ |