Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 468:c97640c90a94
D-Bus Bridge: use inspection to name attribute + fix asynchronous calls for dynamically added method, it now use deferred return value instead of callback/errback attributes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 30 Mar 2012 09:23:23 +0200 |
parents | 78e67a59d51d |
children | 2a072735e459 |
comparison
equal
deleted
inserted
replaced
467:47af60767013 | 468:c97640c90a94 |
---|---|
144 return 3 | 144 return 3 |
145 item = self.data2entry(data, profile) | 145 item = self.data2entry(data, profile) |
146 self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile) | 146 self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile) |
147 return 0 | 147 return 0 |
148 | 148 |
149 def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None): | 149 def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'): |
150 """Get the last published microblogs | 150 """Get the last published microblogs |
151 @param pub_jid: jid of the publisher | 151 @param pub_jid: jid of the publisher |
152 @param max_items: how many microblogs we want to get | 152 @param max_items: how many microblogs we want to get |
153 @param profile_key: profile key | 153 @param profile_key: profile key |
154 @param callback: used for the async answer | 154 @param callback: used for the async answer |
155 @param errback: used for the async answer | 155 @param errback: used for the async answer |
156 """ | 156 """ |
157 assert(callback) | 157 assert(callback) |
158 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) | 158 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) |
159 d.addCallbacks(lambda items: callback(map(self.item2mbdata, items)), errback) | 159 d.addCallback(lambda items: map(self.item2mbdata, items)) |
160 | 160 |
161 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): | 161 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'): |
162 """Create a microblog node on PEP with given access | 162 """Create a microblog node on PEP with given access |
163 If the node already exists, it change options | 163 If the node already exists, it change options |
164 @param access: Node access model, according to xep-0060 #4.5 | 164 @param access: Node access model, according to xep-0060 #4.5 |
165 @param profile_key: profile key""" | 165 @param profile_key: profile key""" |
166 | 166 |
171 _options = {OPT_ACCESS_MODEL:access, OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1, OPT_DELIVER_PAYLOADS:1, OPT_SEND_ITEM_SUBSCRIBE: 1} | 171 _options = {OPT_ACCESS_MODEL:access, OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1, OPT_DELIVER_PAYLOADS:1, OPT_SEND_ITEM_SUBSCRIBE: 1} |
172 | 172 |
173 def cb(result): | 173 def cb(result): |
174 #Node is created with right permission | 174 #Node is created with right permission |
175 debug(_("Microblog node has now access %s") % access) | 175 debug(_("Microblog node has now access %s") % access) |
176 callback() | |
177 | 176 |
178 def fatal_err(s_error): | 177 def fatal_err(s_error): |
179 #Something went wrong | 178 #Something went wrong |
180 error(_("Can't set microblog access")) | 179 error(_("Can't set microblog access")) |
181 errback(NodeAccessChangeException()) | 180 raise NodeAccessChangeException() |
182 | 181 |
183 def err_cb(s_error): | 182 def err_cb(s_error): |
184 #If the node already exists, the condition is "conflict", | 183 #If the node already exists, the condition is "conflict", |
185 #else we have an unmanaged error | 184 #else we have an unmanaged error |
186 if s_error.value.condition=='conflict': | 185 if s_error.value.condition=='conflict': |