plugin xep-0277: bridge data is now converted in pubsub item in a separate function
This commit is contained in:
parent
c665864404
commit
1a579d9087
1 changed files with 23 additions and 15 deletions
|
|
@ -107,18 +107,12 @@ class XEP_0277():
|
|||
microblog_data = self._item2mbdata(item)
|
||||
self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile)
|
||||
|
||||
def sendMicroblog(self, data, profile):
|
||||
"""Send XEP-0277's microblog data
|
||||
@param data: must include content
|
||||
@param profile: profile which send the mood"""
|
||||
if not data.has_key('content'):
|
||||
error(_("Microblog data must contain at least 'content' key"))
|
||||
return 3
|
||||
content = data['content']
|
||||
if not content:
|
||||
error(_("Microblog data's content value must not be empty"))
|
||||
return 3
|
||||
def data2entry(self, data, profile):
|
||||
"""Convert a data dict to en entry usable to create an item
|
||||
@param data: data dict as given by bridge method
|
||||
@return: domish.Element"""
|
||||
_uuid = unicode(uuid.uuid1())
|
||||
content = data['content']
|
||||
_entry = Entry()
|
||||
#FIXME: need to escape html
|
||||
_entry.title = unicode(content).encode('utf-8')
|
||||
|
|
@ -129,6 +123,20 @@ class XEP_0277():
|
|||
_entry_elt = ElementParser()(str(_entry).decode('utf-8'))
|
||||
item = pubsub.Item(payload=_entry_elt)
|
||||
item['id'] = _uuid
|
||||
return item
|
||||
|
||||
def sendMicroblog(self, data, profile):
|
||||
"""Send XEP-0277's microblog data
|
||||
@param data: must include content
|
||||
@param profile: profile which send the mood"""
|
||||
if not data.has_key('content'):
|
||||
error(_("Microblog data must contain at least 'content' key"))
|
||||
return 3
|
||||
content = data['content']
|
||||
if not content.has_key("content"):
|
||||
error(_("Microblog data's content value must not be empty"))
|
||||
return 3
|
||||
item = self.data2entry(data, profile)
|
||||
self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile)
|
||||
return 0
|
||||
|
||||
|
|
@ -150,7 +158,7 @@ class XEP_0277():
|
|||
@param access: Node access model, according to xep-0060 #4.5
|
||||
@param profile_key: profile key"""
|
||||
|
||||
jid, xmlstream = self.host.getJidNStream(profile_key)
|
||||
_jid, xmlstream = self.host.getJidNStream(profile_key)
|
||||
_options = {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1}
|
||||
def cb(result):
|
||||
#Node is created with right permission
|
||||
|
|
@ -164,17 +172,17 @@ class XEP_0277():
|
|||
#If the node already exists, the condition is "conflict",
|
||||
#else we have an unmanaged error
|
||||
if s_error.value.condition=='conflict':
|
||||
#d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
|
||||
#d = self.host.plugins["XEP-0060"].deleteNode(_jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
|
||||
#d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
|
||||
change_node_options().addCallback(cb).addErrback(fatal_err)
|
||||
else:
|
||||
fatal_err(s_error)
|
||||
|
||||
def create_node():
|
||||
return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
|
||||
return self.host.plugins["XEP-0060"].createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
|
||||
|
||||
def change_node_options():
|
||||
return self.host.plugins["XEP-0060"].setOptions(jid.userhostJID(), NS_MICROBLOG, jid.userhostJID(), _options, profile_key=profile_key)
|
||||
return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
|
||||
|
||||
create_node().addCallback(cb).addErrback(err_cb)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue