annotate sat/plugins/plugin_exp_list_of_interest.py @ 2913:672e6be3290f

plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
author Goffi <goffi@goffi.org>
date Sun, 14 Apr 2019 08:21:51 +0200
parents a3faf1c86596
children 47df940738a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin to detect language (experimental)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.log import getLogger
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from wokkel import disco, iwokkel, pubsub
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from zope.interface import implements
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.internet import defer
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber import error as jabber_error
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.words.xish import domish
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log = getLogger(__name__)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_NAME: "List of Interest",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_IMPORT_NAME: "LIST_INTEREST",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_TYPE: "EXP",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_PROTOCOLS: [],
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
38 C.PI_DEPENDENCIES: [u"XEP-0060", u"XEP-0329"],
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_RECOMMENDATIONS: [],
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_MAIN: "ListInterest",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_HANDLER: "yes",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_DESCRIPTION: _(u"Experimental handling of interesting XMPP locations"),
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 NS_LIST_INTEREST = "https://salut-a-toi/protocol/list-interest:0"
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 class ListInterest(object):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 namespace = NS_LIST_INTEREST
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def __init__(self, host):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 log.info(_(u"List of Interest plugin initialization"))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.host = host
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self._p = self.host.plugins["XEP-0060"]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def getHandler(self, client):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 return ListInterestHandler(self)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 @defer.inlineCallbacks
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def createNode(self, client):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 try:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 # TODO: check auto-create, no need to create node first if available
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST}
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 yield self._p.createNode(
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 client,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 client.jid.userhostJID(),
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 nodeIdentifier=NS_LIST_INTEREST,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 options=options,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 )
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 except jabber_error.StanzaError as e:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 if e.condition == u"conflict":
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 log.debug(_(u"requested node already exists"))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 @defer.inlineCallbacks
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def registerPubsub(self, client, namespace, service, node, item_id=None,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 creator=False, name=None, element=None):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 """Register an interesting element in personal list
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 @param namespace(unicode): namespace of the interest
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 this is used as a cache, to avoid the need to retrieve the item only to get
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 its namespace
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
82 @param service(jid.JID): target pubsub service
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 @param node(unicode): target pubsub node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 @param item_id(unicode, None): target pubsub id
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 @param creator(bool): True if client's profile is the creator of the node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 This is used a cache, to avoid the need to retrieve affiliations
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 @param name(unicode, None): name of the interest
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 @param element(domish.Element, None): element to attach
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 may be used to cache some extra data
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 """
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 yield self.createNode(client)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 interest_elt = domish.Element((NS_LIST_INTEREST, u"interest"))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 interest_elt[u"namespace"] = namespace
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 if name is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 interest_elt[u'name'] = name
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 pubsub_elt = interest_elt.addElement(u"pubsub")
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 pubsub_elt[u"service"] = service.full()
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 pubsub_elt[u"node"] = node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 if item_id is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 pubsub_elt[u"item"] = item_id
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 if creator:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 pubsub_elt[u"creator"] = C.BOOL_TRUE
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 if element is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 pubsub_elt.addChild(element)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 item_elt = pubsub.Item(payload=interest_elt)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 yield self._p.publish(
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 )
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 @defer.inlineCallbacks
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
111 def registerFileSharing(
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
112 self, client, service, repos_type=None, namespace=None, path=None, name=None):
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
113 """Register an interesting file repository in personal list
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
114
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
115 @param service(jid.JID): service of the file repository
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
116 @param repos_type(unicode): type of the repository
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
117 @param namespace(unicode, None): namespace of the repository
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
118 @param path(unicode, None): path of the repository
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
119 @param name(unicode, None): name of the repository
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
120 """
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
121 yield self.createNode(client)
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
122 interest_elt = domish.Element((NS_LIST_INTEREST, u"interest"))
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
123 interest_elt[u"namespace"] = self.host.getNamespace(u"fis")
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
124 if name is not None:
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
125 interest_elt[u'name'] = name
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
126 file_sharing_elt = interest_elt.addElement(u"file_sharing")
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
127 file_sharing_elt[u"service"] = service.full()
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
128 if repos_type is not None:
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
129 file_sharing_elt[u"type"] = repos_type
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
130 if namespace is not None:
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
131 file_sharing_elt[u"namespace"] = namespace
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
132 if path is not None:
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
133 file_sharing_elt[u"path"] = path
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
134 item_elt = pubsub.Item(payload=interest_elt)
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
135 yield self._p.publish(
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
136 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt]
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
137 )
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
138
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
139 @defer.inlineCallbacks
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 def listInterests(self, client, service=None, node=None, namespace=None):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 """Retrieve list of interests
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @param service(jid.JID, None): service to use
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 None to use own PEP
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 @param node(unicode, None): node to use
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 None to use default node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 @param namespace(unicode, None): filter interests of this namespace
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 None to retrieve all interests
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 @return: same as [XEP_0060.getItems]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 """
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 # TODO: if a MAM filter were available, it would improve performances
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if not node:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 node = NS_LIST_INTEREST
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 items, metadata = yield self._p.getItems(client, service, node)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if namespace is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 filtered_items = []
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 for item in items:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 try:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 interest_elt = next(item.elements(NS_LIST_INTEREST, u"interest"))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 except StopIteration:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 log.warning(_(u"Missing interest element: {xml}").format(
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 xml=interest_elt.toXml()))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 continue
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if interest_elt.getAttribute(u"namespace") == namespace:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 filtered_items.append(item)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 items = filtered_items
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
167
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 defer.returnValue((items, metadata))
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
169
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 class ListInterestHandler(XMPPHandler):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 implements(iwokkel.IDisco)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
173
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 def __init__(self, plugin_parent):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 self.plugin_parent = plugin_parent
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
176
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 return [
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 disco.DiscoFeature(NS_LIST_INTEREST),
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 ]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
181
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 return []