plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
This commit is contained in:
parent
2dfae32542
commit
d3e86f4ba2
3 changed files with 62 additions and 23 deletions
|
|
@ -231,7 +231,8 @@ class Events(object):
|
||||||
raise exceptions.NotFound(_(u"No event with this id has been found"))
|
raise exceptions.NotFound(_(u"No event with this id has been found"))
|
||||||
defer.returnValue(event_elt)
|
defer.returnValue(event_elt)
|
||||||
|
|
||||||
def register(self, client, service, node, event_id, event_elt, creator=False):
|
def register(self, client, name, extra, service, node, event_id, event_elt,
|
||||||
|
creator=False):
|
||||||
"""register evenement in personal events list
|
"""register evenement in personal events list
|
||||||
|
|
||||||
@param service(jid.JID): pubsub service of the event
|
@param service(jid.JID): pubsub service of the event
|
||||||
|
|
@ -241,6 +242,7 @@ class Events(object):
|
||||||
note that this element will be modified in place
|
note that this element will be modified in place
|
||||||
@param creator(bool): True if client's profile is the creator of the node
|
@param creator(bool): True if client's profile is the creator of the node
|
||||||
"""
|
"""
|
||||||
|
# FIXME: name and extra are unused
|
||||||
link_elt = event_elt.addElement("link")
|
link_elt = event_elt.addElement("link")
|
||||||
link_elt["service"] = service.full()
|
link_elt["service"] = service.full()
|
||||||
link_elt["node"] = node
|
link_elt["node"] = node
|
||||||
|
|
@ -371,7 +373,8 @@ class Events(object):
|
||||||
yield self._p.publish(client, service, node, items=[item_elt])
|
yield self._p.publish(client, service, node, items=[item_elt])
|
||||||
|
|
||||||
if register:
|
if register:
|
||||||
yield self.register(client, service, node, event_id, event_elt, creator=True)
|
yield self.register(
|
||||||
|
client, service, None, {}, node, event_id, event_elt, creator=True)
|
||||||
defer.returnValue(node)
|
defer.returnValue(node)
|
||||||
|
|
||||||
def _eventModify(self, service, node, id_, timestamp_update, data_update,
|
def _eventModify(self, service, node, id_, timestamp_update, data_update,
|
||||||
|
|
@ -546,6 +549,9 @@ class Events(object):
|
||||||
@param node(unicode): event node
|
@param node(unicode): event node
|
||||||
@param item_id(unicode): event id
|
@param item_id(unicode): event id
|
||||||
"""
|
"""
|
||||||
|
# FIXME: handle name and extra
|
||||||
|
name = u''
|
||||||
|
extra = {}
|
||||||
if self._b is None:
|
if self._b is None:
|
||||||
raise exceptions.FeatureNotFound(
|
raise exceptions.FeatureNotFound(
|
||||||
_(u'"XEP-0277" (blog) plugin is needed for this feature')
|
_(u'"XEP-0277" (blog) plugin is needed for this feature')
|
||||||
|
|
@ -590,7 +596,7 @@ class Events(object):
|
||||||
# now we send the invitation
|
# now we send the invitation
|
||||||
pubsub_invitation = self.host.plugins[u'PUBSUB_INVITATION']
|
pubsub_invitation = self.host.plugins[u'PUBSUB_INVITATION']
|
||||||
pubsub_invitation.sendPubsubInvitation(client, invitee_jid, service, node,
|
pubsub_invitation.sendPubsubInvitation(client, invitee_jid, service, node,
|
||||||
item_id)
|
item_id, name, extra)
|
||||||
|
|
||||||
def _inviteByEmail(self, service, node, id_=NS_EVENT, email=u"", emails_extra=None,
|
def _inviteByEmail(self, service, node, id_=NS_EVENT, email=u"", emails_extra=None,
|
||||||
name=u"", host_name=u"", language=u"", url_template=u"",
|
name=u"", host_name=u"", language=u"", url_template=u"",
|
||||||
|
|
|
||||||
|
|
@ -68,19 +68,22 @@ class Invitation(object):
|
||||||
@param callback(callbable): method handling the invitation
|
@param callback(callbable): method handling the invitation
|
||||||
For pubsub invitation, it will be called with following arguments:
|
For pubsub invitation, it will be called with following arguments:
|
||||||
- client
|
- client
|
||||||
|
- name(unicode, None): name of the event
|
||||||
|
- extra(dict): extra data
|
||||||
- service(jid.JID): pubsub service jid
|
- service(jid.JID): pubsub service jid
|
||||||
- node(unicode): pubsub node
|
- node(unicode): pubsub node
|
||||||
- item_id(unicode, None): pubsub item id
|
- item_id(unicode, None): pubsub item id
|
||||||
- item_elt(domish.Element): item of the invitation
|
- item_elt(domish.Element): item of the invitation
|
||||||
For file sharing invitation, it will be called with following arguments:
|
For file sharing invitation, it will be called with following arguments:
|
||||||
- client
|
- client
|
||||||
|
- name(unicode, None): name of the repository
|
||||||
|
- extra(dict): extra data
|
||||||
- service(jid.JID): service jid of the file repository
|
- service(jid.JID): service jid of the file repository
|
||||||
- repos_type(unicode): type of the repository, can be:
|
- repos_type(unicode): type of the repository, can be:
|
||||||
- files: generic file sharing
|
- files: generic file sharing
|
||||||
- photos: photos album
|
- photos: photos album
|
||||||
- namespace(unicode, None): namespace of the repository
|
- namespace(unicode, None): namespace of the repository
|
||||||
- path(unicode, None): path of the repository
|
- path(unicode, None): path of the repository
|
||||||
- name(unicode, None): name of the repository
|
|
||||||
@raise exceptions.ConflictError: this namespace is already registered
|
@raise exceptions.ConflictError: this namespace is already registered
|
||||||
"""
|
"""
|
||||||
if namespace in self._ns_cb:
|
if namespace in self._ns_cb:
|
||||||
|
|
@ -89,10 +92,13 @@ class Invitation(object):
|
||||||
.format(namespace=namespace, callback=self._ns_cb[namespace]))
|
.format(namespace=namespace, callback=self._ns_cb[namespace]))
|
||||||
self._ns_cb[namespace] = callback
|
self._ns_cb[namespace] = callback
|
||||||
|
|
||||||
def _generateBaseInvitation(self, client, invitee_jid):
|
def _generateBaseInvitation(self, client, invitee_jid, name, extra):
|
||||||
"""Generate common mess_data end invitation_elt
|
"""Generate common mess_data end invitation_elt
|
||||||
|
|
||||||
@param invitee_jid(jid.JID): entitee to send invitation to
|
@param invitee_jid(jid.JID): entitee to send invitation to
|
||||||
|
@param name(unicode, None): name of the shared repository
|
||||||
|
@param extra(dict, None): extra data, where key can be:
|
||||||
|
- thumb_url: URL of a thumbnail
|
||||||
@return (tuple[dict, domish.Element): mess_data and invitation_elt
|
@return (tuple[dict, domish.Element): mess_data and invitation_elt
|
||||||
"""
|
"""
|
||||||
mess_data = {
|
mess_data = {
|
||||||
|
|
@ -106,18 +112,33 @@ class Invitation(object):
|
||||||
}
|
}
|
||||||
client.generateMessageXML(mess_data)
|
client.generateMessageXML(mess_data)
|
||||||
invitation_elt = mess_data["xml"].addElement("invitation", NS_INVITATION)
|
invitation_elt = mess_data["xml"].addElement("invitation", NS_INVITATION)
|
||||||
|
if name is not None:
|
||||||
|
invitation_elt[u"name"] = name
|
||||||
|
thumb_url = extra.get(u'thumb_url')
|
||||||
|
if thumb_url:
|
||||||
|
if not thumb_url.startswith(u'http'):
|
||||||
|
log.warning(
|
||||||
|
u"only http URLs are allowed for thumbnails, got {url}, ignoring"
|
||||||
|
.format(url=thumb_url))
|
||||||
|
else:
|
||||||
|
invitation_elt[u'thumb_url'] = thumb_url
|
||||||
return mess_data, invitation_elt
|
return mess_data, invitation_elt
|
||||||
|
|
||||||
def sendPubsubInvitation(self, client, invitee_jid, service, node,
|
def sendPubsubInvitation(self, client, invitee_jid, service, node,
|
||||||
item_id):
|
item_id, name, extra):
|
||||||
"""Send an pubsub invitation in a <message> stanza
|
"""Send an pubsub invitation in a <message> stanza
|
||||||
|
|
||||||
@param invitee_jid(jid.JID): entitee to send invitation to
|
@param invitee_jid(jid.JID): entitee to send invitation to
|
||||||
@param service(jid.JID): pubsub service
|
@param service(jid.JID): pubsub service
|
||||||
@param node(unicode): pubsub node
|
@param node(unicode): pubsub node
|
||||||
@param item_id(unicode): pubsub id
|
@param item_id(unicode): pubsub id
|
||||||
|
@param name(unicode, None): see [_generateBaseInvitation]
|
||||||
|
@param extra(dict, None): see [_generateBaseInvitation]
|
||||||
"""
|
"""
|
||||||
mess_data, invitation_elt = self._generateBaseInvitation(client, invitee_jid)
|
if extra is None:
|
||||||
|
extra = {}
|
||||||
|
mess_data, invitation_elt = self._generateBaseInvitation(
|
||||||
|
client, invitee_jid, name, extra)
|
||||||
pubsub_elt = invitation_elt.addElement(u"pubsub")
|
pubsub_elt = invitation_elt.addElement(u"pubsub")
|
||||||
pubsub_elt[u"service"] = service.full()
|
pubsub_elt[u"service"] = service.full()
|
||||||
pubsub_elt[u"node"] = node
|
pubsub_elt[u"node"] = node
|
||||||
|
|
@ -125,7 +146,7 @@ class Invitation(object):
|
||||||
return client.send(mess_data[u"xml"])
|
return client.send(mess_data[u"xml"])
|
||||||
|
|
||||||
def sendFileSharingInvitation(self, client, invitee_jid, service, repos_type=None,
|
def sendFileSharingInvitation(self, client, invitee_jid, service, repos_type=None,
|
||||||
namespace=None, path=None, name=None):
|
namespace=None, path=None, name=None, extra=None):
|
||||||
"""Send a file sharing invitation in a <message> stanza
|
"""Send a file sharing invitation in a <message> stanza
|
||||||
|
|
||||||
@param invitee_jid(jid.JID): entitee to send invitation to
|
@param invitee_jid(jid.JID): entitee to send invitation to
|
||||||
|
|
@ -135,14 +156,19 @@ class Invitation(object):
|
||||||
- "photos": photos album
|
- "photos": photos album
|
||||||
@param namespace(unicode, None): namespace of the shared repository
|
@param namespace(unicode, None): namespace of the shared repository
|
||||||
@param path(unicode, None): path of the shared repository
|
@param path(unicode, None): path of the shared repository
|
||||||
@param name(unicode, None): name of the shared repository
|
@param name(unicode, None): see [_generateBaseInvitation]
|
||||||
|
@param extra(dict, None): see [_generateBaseInvitation]
|
||||||
"""
|
"""
|
||||||
mess_data, invitation_elt = self._generateBaseInvitation(client, invitee_jid)
|
if extra is None:
|
||||||
|
extra = {}
|
||||||
|
mess_data, invitation_elt = self._generateBaseInvitation(
|
||||||
|
client, invitee_jid, name, extra)
|
||||||
file_sharing_elt = invitation_elt.addElement(u"file_sharing")
|
file_sharing_elt = invitation_elt.addElement(u"file_sharing")
|
||||||
file_sharing_elt[u"service"] = service.full()
|
file_sharing_elt[u"service"] = service.full()
|
||||||
if repos_type is not None:
|
if repos_type is not None:
|
||||||
if repos_type not in (u"files", "photos"):
|
if repos_type not in (u"files", "photos"):
|
||||||
msg = u"unknown repository type: {repos_type}".format(repos_type=repos_type)
|
msg = u"unknown repository type: {repos_type}".format(
|
||||||
|
repos_type=repos_type)
|
||||||
log.warning(msg)
|
log.warning(msg)
|
||||||
raise exceptions.DateError(msg)
|
raise exceptions.DateError(msg)
|
||||||
file_sharing_elt[u"type"] = repos_type
|
file_sharing_elt[u"type"] = repos_type
|
||||||
|
|
@ -150,8 +176,6 @@ class Invitation(object):
|
||||||
file_sharing_elt[u"namespace"] = namespace
|
file_sharing_elt[u"namespace"] = namespace
|
||||||
if path is not None:
|
if path is not None:
|
||||||
file_sharing_elt[u"path"] = path
|
file_sharing_elt[u"path"] = path
|
||||||
if name is not None:
|
|
||||||
file_sharing_elt[u"name"] = name
|
|
||||||
return client.send(mess_data[u"xml"])
|
return client.send(mess_data[u"xml"])
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
@ -195,8 +219,7 @@ class Invitation(object):
|
||||||
repos_type = file_sharing_elt.getAttribute(u"type", u"files")
|
repos_type = file_sharing_elt.getAttribute(u"type", u"files")
|
||||||
namespace = file_sharing_elt.getAttribute(u"namespace")
|
namespace = file_sharing_elt.getAttribute(u"namespace")
|
||||||
path = file_sharing_elt.getAttribute(u"path")
|
path = file_sharing_elt.getAttribute(u"path")
|
||||||
name = file_sharing_elt.getAttribute(u"name")
|
args = [service, repos_type, namespace, path]
|
||||||
args = [service, repos_type, namespace, path, name]
|
|
||||||
ns_fis = self.host.getNamespace(u"fis")
|
ns_fis = self.host.getNamespace(u"fis")
|
||||||
return ns_fis, args
|
return ns_fis, args
|
||||||
|
|
||||||
|
|
@ -204,6 +227,12 @@ class Invitation(object):
|
||||||
def onInvitation(self, message_elt, client):
|
def onInvitation(self, message_elt, client):
|
||||||
log.debug(u"invitation received [{profile}]".format(profile=client.profile))
|
log.debug(u"invitation received [{profile}]".format(profile=client.profile))
|
||||||
invitation_elt = message_elt.invitation
|
invitation_elt = message_elt.invitation
|
||||||
|
|
||||||
|
name = invitation_elt.getAttribute(u"name")
|
||||||
|
extra = {}
|
||||||
|
if invitation_elt.hasAttribute(u"thumb_url"):
|
||||||
|
extra[u'thumb_url'] = invitation_elt[u'thumb_url']
|
||||||
|
|
||||||
for elt in invitation_elt.elements():
|
for elt in invitation_elt.elements():
|
||||||
if elt.uri != NS_INVITATION:
|
if elt.uri != NS_INVITATION:
|
||||||
log.warning(u"unexpected element: {xml}".format(xml=elt.toXml()))
|
log.warning(u"unexpected element: {xml}".format(xml=elt.toXml()))
|
||||||
|
|
@ -226,10 +255,11 @@ class Invitation(object):
|
||||||
try:
|
try:
|
||||||
cb = self._ns_cb[namespace]
|
cb = self._ns_cb[namespace]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning(_(u'No handler for namespace "{namespace}", invitation ignored')
|
log.warning(_(
|
||||||
|
u'No handler for namespace "{namespace}", invitation ignored')
|
||||||
.format(namespace=namespace))
|
.format(namespace=namespace))
|
||||||
else:
|
else:
|
||||||
cb(client, *args)
|
cb(client, name, extra, *args)
|
||||||
|
|
||||||
|
|
||||||
class PubsubInvitationHandler(XMPPHandler):
|
class PubsubInvitationHandler(XMPPHandler):
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
from sat.core.i18n import _
|
from sat.core.i18n import _
|
||||||
from sat.core.constants import Const as C
|
from sat.core.constants import Const as C
|
||||||
from sat.core.log import getLogger
|
from sat.core.log import getLogger
|
||||||
|
from sat.tools.common import data_format
|
||||||
from twisted.words.protocols.jabber import jid
|
from twisted.words.protocols.jabber import jid
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
@ -48,22 +49,24 @@ class FileSharingInvitation(object):
|
||||||
host.bridge.addMethod(
|
host.bridge.addMethod(
|
||||||
"FISInvite",
|
"FISInvite",
|
||||||
".plugin",
|
".plugin",
|
||||||
in_sign="sssssss",
|
in_sign="ssssssss",
|
||||||
out_sign="",
|
out_sign="",
|
||||||
method=self._sendFileSharingInvitation,
|
method=self._sendFileSharingInvitation,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _sendFileSharingInvitation(
|
def _sendFileSharingInvitation(
|
||||||
self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None,
|
self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None,
|
||||||
name=None, profile_key=C.PROF_KEY_NONE):
|
name=None, extra_s=u'', profile_key=C.PROF_KEY_NONE):
|
||||||
client = self.host.getClient(profile_key)
|
client = self.host.getClient(profile_key)
|
||||||
invitee_jid = jid.JID(invitee_jid_s)
|
invitee_jid = jid.JID(invitee_jid_s)
|
||||||
service = jid.JID(service_s)
|
service = jid.JID(service_s)
|
||||||
|
extra = data_format.deserialise(extra_s)
|
||||||
return self.host.plugins[u"INVITATION"].sendFileSharingInvitation(
|
return self.host.plugins[u"INVITATION"].sendFileSharingInvitation(
|
||||||
client, invitee_jid, service, repos_type=None, namespace=None, path=None,
|
client, invitee_jid, service, repos_type=repos_type or None,
|
||||||
name=None)
|
namespace=namespace or None, path=path or None, name=name or None,
|
||||||
|
extra=extra)
|
||||||
|
|
||||||
def onInvitation(self, client, service, repos_type, namespace, path, name):
|
def onInvitation(self, client, name, extra, service, repos_type, namespace, path):
|
||||||
if repos_type == u"files":
|
if repos_type == u"files":
|
||||||
type_human = _(u"file sharing")
|
type_human = _(u"file sharing")
|
||||||
elif repos_type == u"photos":
|
elif repos_type == u"photos":
|
||||||
|
|
@ -79,4 +82,4 @@ class FileSharingInvitation(object):
|
||||||
profile=client.profile, type_human=type_human, namespace=namespace, path=path)
|
profile=client.profile, type_human=type_human, namespace=namespace, path=path)
|
||||||
)
|
)
|
||||||
return self.host.plugins[u'LIST_INTEREST'].registerFileSharing(
|
return self.host.plugins[u'LIST_INTEREST'].registerFileSharing(
|
||||||
client, service, repos_type, namespace, path, name)
|
client, service, repos_type, namespace, path, name, extra)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue