Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 339:b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 May 2011 16:48:23 +0200 |
parents | 0aa6ca6cdbdd |
children | 6fe6ae70904a |
comparison
equal
deleted
inserted
replaced
338:6dcdc4cf8622 | 339:b0b773f432e5 |
---|---|
46 "main": "XEP_0277", | 46 "main": "XEP_0277", |
47 "handler": "no", | 47 "handler": "no", |
48 "description": _("""Implementation of microblogging Protocol""") | 48 "description": _("""Implementation of microblogging Protocol""") |
49 } | 49 } |
50 | 50 |
51 class NodeAccessChangeException(Exception): | |
52 pass | |
53 | |
51 class XEP_0277(): | 54 class XEP_0277(): |
52 | 55 |
53 def __init__(self, host): | 56 def __init__(self, host): |
54 info(_("Microblogging plugin initialization")) | 57 info(_("Microblogging plugin initialization")) |
55 self.host = host | 58 self.host = host |
64 'param_2':'%(doc_profile)s', | 67 'param_2':'%(doc_profile)s', |
65 'return':'list of microblog data (dict)' | 68 'return':'list of microblog data (dict)' |
66 }) | 69 }) |
67 host.bridge.addMethod("setMicroblogAccess", ".communication", in_sign='ss', out_sign='', | 70 host.bridge.addMethod("setMicroblogAccess", ".communication", in_sign='ss', out_sign='', |
68 method=self.setMicroblogAccess, | 71 method=self.setMicroblogAccess, |
72 async = True, | |
69 doc = { | 73 doc = { |
70 }) | 74 }) |
71 | 75 |
72 def _item2mbdata(self, item): | 76 def _item2mbdata(self, item): |
73 """Convert an XML Item to microblog data used in bridge API | 77 """Convert an XML Item to microblog data used in bridge API |
150 """ | 154 """ |
151 assert(callback) | 155 assert(callback) |
152 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) | 156 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) |
153 d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback) | 157 d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback) |
154 | 158 |
155 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'): | 159 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): |
156 """Create a microblog node on PEP with given access | 160 """Create a microblog node on PEP with given access |
157 If the node already exists, it change options | 161 If the node already exists, it change options |
158 @param access: Node access model, according to xep-0060 #4.5 | 162 @param access: Node access model, according to xep-0060 #4.5 |
159 @param profile_key: profile key""" | 163 @param profile_key: profile key""" |
160 | 164 |
164 return | 168 return |
165 _options = {OPT_ACCESS_MODEL:access, OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1} | 169 _options = {OPT_ACCESS_MODEL:access, OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1} |
166 def cb(result): | 170 def cb(result): |
167 #Node is created with right permission | 171 #Node is created with right permission |
168 debug(_("Microblog node has now access %s") % access) | 172 debug(_("Microblog node has now access %s") % access) |
173 callback() | |
169 | 174 |
170 def fatal_err(s_error): | 175 def fatal_err(s_error): |
171 #Something went wrong | 176 #Something went wrong |
172 error(_("Can't set microblog access")) | 177 error(_("Can't set microblog access")) |
178 errback(NodeAccessChangeException()) | |
173 | 179 |
174 def err_cb(s_error): | 180 def err_cb(s_error): |
175 #If the node already exists, the condition is "conflict", | 181 #If the node already exists, the condition is "conflict", |
176 #else we have an unmanaged error | 182 #else we have an unmanaged error |
177 if s_error.value.condition=='conflict': | 183 if s_error.value.condition=='conflict': |