Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 304:e04ccf122bb6
microblog sending
- Bridge: added sendPersonalEvent to DBus frontend
- plugin XEP_0277: * fixed unicode issue
* node options are now changed instead of node being deleted/recreated for setMicroblogAccess
- xml_tools: fixed unicode issue
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Mar 2011 17:51:19 +0100 |
parents | 2b52a5da0978 |
children | 169e7386650a |
comparison
equal
deleted
inserted
replaced
303:2b52a5da0978 | 304:e04ccf122bb6 |
---|---|
115 error(_("Microblog data must contain at least 'content' key")) | 115 error(_("Microblog data must contain at least 'content' key")) |
116 return 3 | 116 return 3 |
117 content = data['content'] | 117 content = data['content'] |
118 if not content: | 118 if not content: |
119 error(_("Microblog data's content value must not be empty")) | 119 error(_("Microblog data's content value must not be empty")) |
120 return 3 | |
120 _uuid = unicode(uuid.uuid1()) | 121 _uuid = unicode(uuid.uuid1()) |
121 _entry = Entry() | 122 _entry = Entry() |
122 #FIXME: need to escape html | 123 #FIXME: need to escape html |
123 _entry.title = content.encode('utf-8') | 124 _entry.title = unicode(content).encode('utf-8') |
124 _entry.author = Author() | 125 _entry.author = Author() |
125 _entry.author.name = data.get('author',self.host.getJidNStream(profile)[0].userhost()).encode('utf-8') | 126 _entry.author.name = data.get('author',self.host.getJidNStream(profile)[0].userhost()).encode('utf-8') |
126 _entry.updated = float(data.get('timestamp',time())) | 127 _entry.updated = float(data.get('timestamp',time())) |
127 _entry.id = _uuid | 128 _entry.id = str(_uuid) |
128 _entry_elt = ElementParser()(str(_entry)) | 129 _entry_elt = ElementParser()(str(_entry).decode('utf-8')) |
129 item = pubsub.Item(payload=_entry_elt) | 130 item = pubsub.Item(payload=_entry_elt) |
130 item['id'] = _uuid | 131 item['id'] = _uuid |
131 self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile) | 132 self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile) |
132 return 0 | 133 return 0 |
133 | 134 |
143 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) | 144 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) |
144 d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback) | 145 d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback) |
145 | 146 |
146 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'): | 147 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'): |
147 """Create a microblog node on PEP with given access | 148 """Create a microblog node on PEP with given access |
148 If the node already exists, it is deleted and recreated | 149 If the node already exists, it change options |
149 @param access: Node access model, according to xep-0060 #4.5 | 150 @param access: Node access model, according to xep-0060 #4.5 |
150 @param profile_key: profile key""" | 151 @param profile_key: profile key""" |
151 | 152 |
152 jid, xmlstream = self.host.getJidNStream(profile_key) | 153 jid, xmlstream = self.host.getJidNStream(profile_key) |
154 _options = {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1} | |
153 def cb(result): | 155 def cb(result): |
154 #Node is created with right permission | 156 #Node is created with right permission |
155 debug(_("Microblog node created")) | 157 debug(_("Microblog node has now access %s") % access) |
156 | 158 |
157 def fatal_err(s_error): | 159 def fatal_err(s_error): |
158 #Something went wrong | 160 #Something went wrong |
159 error(_("Can't set microblog access")) | 161 error(_("Can't set microblog access")) |
160 | 162 |
161 def err_cb(s_error): | 163 def err_cb(s_error): |
162 #If the node already exists, the condition is "conflict", | 164 #If the node already exists, the condition is "conflict", |
163 #else we have an unmanaged error | 165 #else we have an unmanaged error |
164 if s_error.value.condition=='conflict': | 166 if s_error.value.condition=='conflict': |
165 d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key) | 167 #d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key) |
166 d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) | 168 #d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) |
167 d.addErrback(fatal_err) | 169 change_node_options().addCallback(cb).addErrback(fatal_err) |
168 else: | 170 else: |
169 fatal_err(s_error) | 171 fatal_err(s_error) |
170 | 172 |
171 def create_node(): | 173 def create_node(): |
172 return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1}, profile_key=profile_key) | 174 return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) |
175 | |
176 def change_node_options(): | |
177 return self.host.plugins["XEP-0060"].setOptions(jid.userhostJID(), NS_MICROBLOG, jid.userhostJID(), _options, profile_key=profile_key) | |
173 | 178 |
174 create_node().addCallback(cb).addErrback(err_cb) | 179 create_node().addCallback(cb).addErrback(err_cb) |
175 | 180 |
176 | 181 |
177 | 182 |