comparison sat/plugins/plugin_xep_0048.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 32d714a8ea51
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
55 URL_ATTRS = ("name",) 55 URL_ATTRS = ("name",)
56 56
57 def __init__(self, host): 57 def __init__(self, host):
58 log.info(_("Bookmarks plugin initialization")) 58 log.info(_("Bookmarks plugin initialization"))
59 self.host = host 59 self.host = host
60 # self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True) 60 # self.__menu_id = host.register_callback(self._bookmarks_menu, with_data=True)
61 self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True) 61 self.__bm_save_id = host.register_callback(self._bookmarks_save_cb, with_data=True)
62 host.importMenu( 62 host.import_menu(
63 (D_("Groups"), D_("Bookmarks")), 63 (D_("Groups"), D_("Bookmarks")),
64 self._bookmarksMenu, 64 self._bookmarks_menu,
65 security_limit=0, 65 security_limit=0,
66 help_string=D_("Use and manage bookmarks"), 66 help_string=D_("Use and manage bookmarks"),
67 ) 67 )
68 self.__selected_id = host.registerCallback( 68 self.__selected_id = host.register_callback(
69 self._bookmarkSelectedCb, with_data=True 69 self._bookmark_selected_cb, with_data=True
70 ) 70 )
71 host.bridge.addMethod( 71 host.bridge.add_method(
72 "bookmarksList", 72 "bookmarks_list",
73 ".plugin", 73 ".plugin",
74 in_sign="sss", 74 in_sign="sss",
75 out_sign="a{sa{sa{ss}}}", 75 out_sign="a{sa{sa{ss}}}",
76 method=self._bookmarksList, 76 method=self._bookmarks_list,
77 async_=True, 77 async_=True,
78 ) 78 )
79 host.bridge.addMethod( 79 host.bridge.add_method(
80 "bookmarksRemove", 80 "bookmarks_remove",
81 ".plugin", 81 ".plugin",
82 in_sign="ssss", 82 in_sign="ssss",
83 out_sign="", 83 out_sign="",
84 method=self._bookmarksRemove, 84 method=self._bookmarks_remove,
85 async_=True, 85 async_=True,
86 ) 86 )
87 host.bridge.addMethod( 87 host.bridge.add_method(
88 "bookmarksAdd", 88 "bookmarks_add",
89 ".plugin", 89 ".plugin",
90 in_sign="ssa{ss}ss", 90 in_sign="ssa{ss}ss",
91 out_sign="", 91 out_sign="",
92 method=self._bookmarksAdd, 92 method=self._bookmarks_add,
93 async_=True, 93 async_=True,
94 ) 94 )
95 try: 95 try:
96 self.private_plg = self.host.plugins["XEP-0049"] 96 self.private_plg = self.host.plugins["XEP-0049"]
97 except KeyError: 97 except KeyError:
98 self.private_plg = None 98 self.private_plg = None
99 try: 99 try:
100 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) 100 self.host.plugins[C.TEXT_CMDS].register_text_commands(self)
101 except KeyError: 101 except KeyError:
102 log.info(_("Text commands not available")) 102 log.info(_("Text commands not available"))
103 103
104 async def profileConnected(self, client): 104 async def profile_connected(self, client):
105 local = client.bookmarks_local = PersistentBinaryDict( 105 local = client.bookmarks_local = PersistentBinaryDict(
106 NS_BOOKMARKS, client.profile 106 NS_BOOKMARKS, client.profile
107 ) 107 )
108 await local.load() 108 await local.load()
109 if not local: 109 if not local:
110 local[XEP_0048.MUC_TYPE] = dict() 110 local[XEP_0048.MUC_TYPE] = dict()
111 local[XEP_0048.URL_TYPE] = dict() 111 local[XEP_0048.URL_TYPE] = dict()
112 private = await self._getServerBookmarks("private", client.profile) 112 private = await self._get_server_bookmarks("private", client.profile)
113 pubsub = client.bookmarks_pubsub = None 113 pubsub = client.bookmarks_pubsub = None
114 114
115 for bookmarks in (local, private, pubsub): 115 for bookmarks in (local, private, pubsub):
116 if bookmarks is not None: 116 if bookmarks is not None:
117 for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()): 117 for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()):
123 123
124 # we don't use a DeferredList to gather result here, as waiting for all room would 124 # we don't use a DeferredList to gather result here, as waiting for all room would
125 # slow down a lot the connection process, and result in a bad user experience. 125 # slow down a lot the connection process, and result in a bad user experience.
126 126
127 @defer.inlineCallbacks 127 @defer.inlineCallbacks
128 def _getServerBookmarks(self, storage_type, profile): 128 def _get_server_bookmarks(self, storage_type, profile):
129 """Get distants bookmarks 129 """Get distants bookmarks
130 130
131 update also the client.bookmarks_[type] key, with None if service is not available 131 update also the client.bookmarks_[type] key, with None if service is not available
132 @param storage_type: storage type, can be: 132 @param storage_type: storage type, can be:
133 - 'private': XEP-0049 storage 133 - 'private': XEP-0049 storage
134 - 'pubsub': XEP-0223 storage 134 - 'pubsub': XEP-0223 storage
135 @param profile: %(doc_profile)s 135 @param profile: %(doc_profile)s
136 @return: data dictionary, or None if feature is not available 136 @return: data dictionary, or None if feature is not available
137 """ 137 """
138 client = self.host.getClient(profile) 138 client = self.host.get_client(profile)
139 if storage_type == "private": 139 if storage_type == "private":
140 try: 140 try:
141 bookmarks_private_xml = yield self.private_plg.privateXMLGet( 141 bookmarks_private_xml = yield self.private_plg.private_xml_get(
142 "storage", NS_BOOKMARKS, profile 142 "storage", NS_BOOKMARKS, profile
143 ) 143 )
144 data = client.bookmarks_private = self._bookmarkElt2Dict( 144 data = client.bookmarks_private = self._bookmark_elt_2_dict(
145 bookmarks_private_xml 145 bookmarks_private_xml
146 ) 146 )
147 except (StanzaError, AttributeError): 147 except (StanzaError, AttributeError):
148 log.info(_("Private XML storage not available")) 148 log.info(_("Private XML storage not available"))
149 data = client.bookmarks_private = None 149 data = client.bookmarks_private = None
152 else: 152 else:
153 raise ValueError("storage_type must be 'private' or 'pubsub'") 153 raise ValueError("storage_type must be 'private' or 'pubsub'")
154 defer.returnValue(data) 154 defer.returnValue(data)
155 155
156 @defer.inlineCallbacks 156 @defer.inlineCallbacks
157 def _setServerBookmarks(self, storage_type, bookmarks_elt, profile): 157 def _set_server_bookmarks(self, storage_type, bookmarks_elt, profile):
158 """Save bookmarks on server 158 """Save bookmarks on server
159 159
160 @param storage_type: storage type, can be: 160 @param storage_type: storage type, can be:
161 - 'private': XEP-0049 storage 161 - 'private': XEP-0049 storage
162 - 'pubsub': XEP-0223 storage 162 - 'pubsub': XEP-0223 storage
163 @param bookmarks_elt (domish.Element): bookmarks XML 163 @param bookmarks_elt (domish.Element): bookmarks XML
164 @param profile: %(doc_profile)s 164 @param profile: %(doc_profile)s
165 """ 165 """
166 if storage_type == "private": 166 if storage_type == "private":
167 yield self.private_plg.privateXMLStore(bookmarks_elt, profile) 167 yield self.private_plg.private_xml_store(bookmarks_elt, profile)
168 elif storage_type == "pubsub": 168 elif storage_type == "pubsub":
169 raise NotImplementedError 169 raise NotImplementedError
170 else: 170 else:
171 raise ValueError("storage_type must be 'private' or 'pubsub'") 171 raise ValueError("storage_type must be 'private' or 'pubsub'")
172 172
173 def _bookmarkElt2Dict(self, storage_elt): 173 def _bookmark_elt_2_dict(self, storage_elt):
174 """Parse bookmarks to get dictionary 174 """Parse bookmarks to get dictionary
175 @param storage_elt (domish.Element): bookmarks storage 175 @param storage_elt (domish.Element): bookmarks storage
176 @return (dict): bookmark data (key: bookmark type, value: list) where key can be: 176 @return (dict): bookmark data (key: bookmark type, value: list) where key can be:
177 - XEP_0048.MUC_TYPE 177 - XEP_0048.MUC_TYPE
178 - XEP_0048.URL_TYPE 178 - XEP_0048.URL_TYPE
179 - value (dict): data as for addBookmark 179 - value (dict): data as for add_bookmark
180 """ 180 """
181 conf_data = {} 181 conf_data = {}
182 url_data = {} 182 url_data = {}
183 183
184 conference_elts = storage_elt.elements(NS_BOOKMARKS, "conference") 184 conference_elts = storage_elt.elements(NS_BOOKMARKS, "conference")
216 if url_elt.hasAttribute(attr): 216 if url_elt.hasAttribute(attr):
217 data[attr] = url_elt[attr] 217 data[attr] = url_elt[attr]
218 218
219 return {XEP_0048.MUC_TYPE: conf_data, XEP_0048.URL_TYPE: url_data} 219 return {XEP_0048.MUC_TYPE: conf_data, XEP_0048.URL_TYPE: url_data}
220 220
221 def _dict2BookmarkElt(self, type_, data): 221 def _dict_2_bookmark_elt(self, type_, data):
222 """Construct a bookmark element from a data dict 222 """Construct a bookmark element from a data dict
223 @param data (dict): bookmark data (key: bookmark type, value: list) where key can be: 223 @param data (dict): bookmark data (key: bookmark type, value: list) where key can be:
224 - XEP_0048.MUC_TYPE 224 - XEP_0048.MUC_TYPE
225 - XEP_0048.URL_TYPE 225 - XEP_0048.URL_TYPE
226 - value (dict): data as for addBookmark 226 - value (dict): data as for add_bookmark
227 @return (domish.Element): bookmark element 227 @return (domish.Element): bookmark element
228 """ 228 """
229 rooms_data = data.get(XEP_0048.MUC_TYPE, {}) 229 rooms_data = data.get(XEP_0048.MUC_TYPE, {})
230 urls_data = data.get(XEP_0048.URL_TYPE, {}) 230 urls_data = data.get(XEP_0048.URL_TYPE, {})
231 storage_elt = domish.Element((NS_BOOKMARKS, "storage")) 231 storage_elt = domish.Element((NS_BOOKMARKS, "storage"))
251 except KeyError: 251 except KeyError:
252 pass 252 pass
253 253
254 return storage_elt 254 return storage_elt
255 255
256 def _bookmarkSelectedCb(self, data, profile): 256 def _bookmark_selected_cb(self, data, profile):
257 try: 257 try:
258 room_jid_s, nick = data["index"].split(" ", 1) 258 room_jid_s, nick = data["index"].split(" ", 1)
259 room_jid = jid.JID(room_jid_s) 259 room_jid = jid.JID(room_jid_s)
260 except (KeyError, RuntimeError): 260 except (KeyError, RuntimeError):
261 log.warning(_("No room jid selected")) 261 log.warning(_("No room jid selected"))
262 return {} 262 return {}
263 263
264 client = self.host.getClient(profile) 264 client = self.host.get_client(profile)
265 d = self.host.plugins["XEP-0045"].join(client, room_jid, nick, {}) 265 d = self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
266 266
267 def join_eb(failure): 267 def join_eb(failure):
268 log.warning("Error while trying to join room: {}".format(failure)) 268 log.warning("Error while trying to join room: {}".format(failure))
269 # FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here 269 # FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here
270 return {} 270 return {}
271 271
272 d.addCallbacks(lambda __: {}, join_eb) 272 d.addCallbacks(lambda __: {}, join_eb)
273 return d 273 return d
274 274
275 def _bookmarksMenu(self, data, profile): 275 def _bookmarks_menu(self, data, profile):
276 """ XMLUI activated by menu: return Gateways UI 276 """ XMLUI activated by menu: return Gateways UI
277 @param profile: %(doc_profile)s 277 @param profile: %(doc_profile)s
278 278
279 """ 279 """
280 client = self.host.getClient(profile) 280 client = self.host.get_client(profile)
281 xmlui = xml_tools.XMLUI(title=_("Bookmarks manager")) 281 xmlui = xml_tools.XMLUI(title=_("Bookmarks manager"))
282 adv_list = xmlui.changeContainer( 282 adv_list = xmlui.change_container(
283 "advanced_list", 283 "advanced_list",
284 columns=3, 284 columns=3,
285 selectable="single", 285 selectable="single",
286 callback_id=self.__selected_id, 286 callback_id=self.__selected_id,
287 ) 287 )
295 for (room_jid, data) in sorted( 295 for (room_jid, data) in sorted(
296 list(bookmarks[XEP_0048.MUC_TYPE].items()), 296 list(bookmarks[XEP_0048.MUC_TYPE].items()),
297 key=lambda item: item[1].get("name", item[0].user), 297 key=lambda item: item[1].get("name", item[0].user),
298 ): 298 ):
299 room_jid_s = room_jid.full() 299 room_jid_s = room_jid.full()
300 adv_list.setRowIndex( 300 adv_list.set_row_index(
301 "%s %s" % (room_jid_s, data.get("nick") or client.jid.user) 301 "%s %s" % (room_jid_s, data.get("nick") or client.jid.user)
302 ) 302 )
303 xmlui.addText(data.get("name", "")) 303 xmlui.addText(data.get("name", ""))
304 xmlui.addJid(room_jid) 304 xmlui.addJid(room_jid)
305 if C.bool(data.get("autojoin", C.BOOL_FALSE)): 305 if C.bool(data.get("autojoin", C.BOOL_FALSE)):
307 else: 307 else:
308 xmlui.addEmpty() 308 xmlui.addEmpty()
309 adv_list.end() 309 adv_list.end()
310 xmlui.addDivider("dash") 310 xmlui.addDivider("dash")
311 xmlui.addText(_("add a bookmark")) 311 xmlui.addText(_("add a bookmark"))
312 xmlui.changeContainer("pairs") 312 xmlui.change_container("pairs")
313 xmlui.addLabel(_("Name")) 313 xmlui.addLabel(_("Name"))
314 xmlui.addString("name") 314 xmlui.addString("name")
315 xmlui.addLabel(_("jid")) 315 xmlui.addLabel(_("jid"))
316 xmlui.addString("jid") 316 xmlui.addString("jid")
317 xmlui.addLabel(_("Nickname")) 317 xmlui.addLabel(_("Nickname"))
318 xmlui.addString("nick", client.jid.user) 318 xmlui.addString("nick", client.jid.user)
319 xmlui.addLabel(_("Autojoin")) 319 xmlui.addLabel(_("Autojoin"))
320 xmlui.addBool("autojoin") 320 xmlui.addBool("autojoin")
321 xmlui.changeContainer("vertical") 321 xmlui.change_container("vertical")
322 xmlui.addButton(self.__bm_save_id, _("Save"), ("name", "jid", "nick", "autojoin")) 322 xmlui.addButton(self.__bm_save_id, _("Save"), ("name", "jid", "nick", "autojoin"))
323 return {"xmlui": xmlui.toXml()} 323 return {"xmlui": xmlui.toXml()}
324 324
325 def _bookmarksSaveCb(self, data, profile): 325 def _bookmarks_save_cb(self, data, profile):
326 bm_data = xml_tools.XMLUIResult2DataFormResult(data) 326 bm_data = xml_tools.xmlui_result_2_data_form_result(data)
327 try: 327 try:
328 location = jid.JID(bm_data.pop("jid")) 328 location = jid.JID(bm_data.pop("jid"))
329 except KeyError: 329 except KeyError:
330 raise exceptions.InternalError("Can't find mandatory key") 330 raise exceptions.InternalError("Can't find mandatory key")
331 d = self.addBookmark(XEP_0048.MUC_TYPE, location, bm_data, profile_key=profile) 331 d = self.add_bookmark(XEP_0048.MUC_TYPE, location, bm_data, profile_key=profile)
332 d.addCallback(lambda __: {}) 332 d.addCallback(lambda __: {})
333 return d 333 return d
334 334
335 @defer.inlineCallbacks 335 @defer.inlineCallbacks
336 def addBookmark( 336 def add_bookmark(
337 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE 337 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE
338 ): 338 ):
339 """Store a new bookmark 339 """Store a new bookmark
340 340
341 @param type_: bookmark type, one of: 341 @param type_: bookmark type, one of:
355 @param profile_key: %(doc_profile_key)s 355 @param profile_key: %(doc_profile_key)s
356 """ 356 """
357 assert storage_type in ("auto", "pubsub", "private", "local") 357 assert storage_type in ("auto", "pubsub", "private", "local")
358 if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(list(data.keys())): 358 if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(list(data.keys())):
359 raise ValueError("autojoin or nick can't be used with URLs") 359 raise ValueError("autojoin or nick can't be used with URLs")
360 client = self.host.getClient(profile_key) 360 client = self.host.get_client(profile_key)
361 if storage_type == "auto": 361 if storage_type == "auto":
362 if client.bookmarks_pubsub is not None: 362 if client.bookmarks_pubsub is not None:
363 storage_type = "pubsub" 363 storage_type = "pubsub"
364 elif client.bookmarks_private is not None: 364 elif client.bookmarks_private is not None:
365 storage_type = "private" 365 storage_type = "private"
370 370
371 if storage_type == "local": 371 if storage_type == "local":
372 client.bookmarks_local[type_][location] = data 372 client.bookmarks_local[type_][location] = data
373 yield client.bookmarks_local.force(type_) 373 yield client.bookmarks_local.force(type_)
374 else: 374 else:
375 bookmarks = yield self._getServerBookmarks(storage_type, client.profile) 375 bookmarks = yield self._get_server_bookmarks(storage_type, client.profile)
376 bookmarks[type_][location] = data 376 bookmarks[type_][location] = data
377 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) 377 bookmark_elt = self._dict_2_bookmark_elt(type_, bookmarks)
378 yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) 378 yield self._set_server_bookmarks(storage_type, bookmark_elt, client.profile)
379 379
380 @defer.inlineCallbacks 380 @defer.inlineCallbacks
381 def removeBookmark( 381 def remove_bookmark(
382 self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE 382 self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE
383 ): 383 ):
384 """Remove a stored bookmark 384 """Remove a stored bookmark
385 385
386 @param type_: bookmark type, one of: 386 @param type_: bookmark type, one of:
393 - "private": Private XML storage (XEP-0049) 393 - "private": Private XML storage (XEP-0049)
394 - "local": Store in SàT database 394 - "local": Store in SàT database
395 @param profile_key: %(doc_profile_key)s 395 @param profile_key: %(doc_profile_key)s
396 """ 396 """
397 assert storage_type in ("all", "pubsub", "private", "local") 397 assert storage_type in ("all", "pubsub", "private", "local")
398 client = self.host.getClient(profile_key) 398 client = self.host.get_client(profile_key)
399 399
400 if storage_type in ("all", "local"): 400 if storage_type in ("all", "local"):
401 try: 401 try:
402 del client.bookmarks_local[type_][location] 402 del client.bookmarks_local[type_][location]
403 yield client.bookmarks_local.force(type_) 403 yield client.bookmarks_local.force(type_)
404 except KeyError: 404 except KeyError:
405 log.debug("Bookmark is not present in local storage") 405 log.debug("Bookmark is not present in local storage")
406 406
407 if storage_type in ("all", "private"): 407 if storage_type in ("all", "private"):
408 bookmarks = yield self._getServerBookmarks("private", client.profile) 408 bookmarks = yield self._get_server_bookmarks("private", client.profile)
409 try: 409 try:
410 del bookmarks[type_][location] 410 del bookmarks[type_][location]
411 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) 411 bookmark_elt = self._dict_2_bookmark_elt(type_, bookmarks)
412 yield self._setServerBookmarks("private", bookmark_elt, client.profile) 412 yield self._set_server_bookmarks("private", bookmark_elt, client.profile)
413 except KeyError: 413 except KeyError:
414 log.debug("Bookmark is not present in private storage") 414 log.debug("Bookmark is not present in private storage")
415 415
416 if storage_type == "pubsub": 416 if storage_type == "pubsub":
417 raise NotImplementedError 417 raise NotImplementedError
418 418
419 def _bookmarksList(self, type_, storage_location, profile_key=C.PROF_KEY_NONE): 419 def _bookmarks_list(self, type_, storage_location, profile_key=C.PROF_KEY_NONE):
420 """Return stored bookmarks 420 """Return stored bookmarks
421 421
422 @param type_: bookmark type, one of: 422 @param type_: bookmark type, one of:
423 - XEP_0048.MUC_TYPE: Multi-User chat room 423 - XEP_0048.MUC_TYPE: Multi-User chat room
424 - XEP_0048.URL_TYPE: web page URL 424 - XEP_0048.URL_TYPE: web page URL
429 - 'pubsub' 429 - 'pubsub'
430 @param profile_key: %(doc_profile_key)s 430 @param profile_key: %(doc_profile_key)s
431 @param return (dict): (key: storage_location, value dict) with: 431 @param return (dict): (key: storage_location, value dict) with:
432 - value (dict): (key: bookmark_location, value: bookmark data) 432 - value (dict): (key: bookmark_location, value: bookmark data)
433 """ 433 """
434 client = self.host.getClient(profile_key) 434 client = self.host.get_client(profile_key)
435 ret = {} 435 ret = {}
436 ret_d = defer.succeed(ret) 436 ret_d = defer.succeed(ret)
437 437
438 def fillBookmarks(__, _storage_location): 438 def fill_bookmarks(__, _storage_location):
439 bookmarks_ori = getattr(client, "bookmarks_" + _storage_location) 439 bookmarks_ori = getattr(client, "bookmarks_" + _storage_location)
440 if bookmarks_ori is None: 440 if bookmarks_ori is None:
441 return ret 441 return ret
442 data = bookmarks_ori[type_] 442 data = bookmarks_ori[type_]
443 for bookmark in data: 443 for bookmark in data:
450 for _storage_location in ("local", "private", "pubsub"): 450 for _storage_location in ("local", "private", "pubsub"):
451 if storage_location in ("all", _storage_location): 451 if storage_location in ("all", _storage_location):
452 ret[_storage_location] = {} 452 ret[_storage_location] = {}
453 if _storage_location in ("private",): 453 if _storage_location in ("private",):
454 # we update distant bookmarks, just in case an other client added something 454 # we update distant bookmarks, just in case an other client added something
455 d = self._getServerBookmarks(_storage_location, client.profile) 455 d = self._get_server_bookmarks(_storage_location, client.profile)
456 else: 456 else:
457 d = defer.succeed(None) 457 d = defer.succeed(None)
458 d.addCallback(fillBookmarks, _storage_location) 458 d.addCallback(fill_bookmarks, _storage_location)
459 ret_d.addCallback(lambda __: d) 459 ret_d.addCallback(lambda __: d)
460 460
461 return ret_d 461 return ret_d
462 462
463 def _bookmarksRemove( 463 def _bookmarks_remove(
464 self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE 464 self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE
465 ): 465 ):
466 """Return stored bookmarks 466 """Return stored bookmarks
467 467
468 @param type_: bookmark type, one of: 468 @param type_: bookmark type, one of:
476 - "local": Store in SàT database 476 - "local": Store in SàT database
477 @param profile_key: %(doc_profile_key)s 477 @param profile_key: %(doc_profile_key)s
478 """ 478 """
479 if type_ == XEP_0048.MUC_TYPE: 479 if type_ == XEP_0048.MUC_TYPE:
480 location = jid.JID(location) 480 location = jid.JID(location)
481 return self.removeBookmark(type_, location, storage_location, profile_key) 481 return self.remove_bookmark(type_, location, storage_location, profile_key)
482 482
483 def _bookmarksAdd( 483 def _bookmarks_add(
484 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE 484 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE
485 ): 485 ):
486 if type_ == XEP_0048.MUC_TYPE: 486 if type_ == XEP_0048.MUC_TYPE:
487 location = jid.JID(location) 487 location = jid.JID(location)
488 return self.addBookmark(type_, location, data, storage_type, profile_key) 488 return self.add_bookmark(type_, location, data, storage_type, profile_key)
489 489
490 def cmd_bookmark(self, client, mess_data): 490 def cmd_bookmark(self, client, mess_data):
491 """(Un)bookmark a MUC room 491 """(Un)bookmark a MUC room
492 492
493 @command (group): [autojoin | remove] 493 @command (group): [autojoin | remove]
496 """ 496 """
497 txt_cmd = self.host.plugins[C.TEXT_CMDS] 497 txt_cmd = self.host.plugins[C.TEXT_CMDS]
498 498
499 options = mess_data["unparsed"].strip().split() 499 options = mess_data["unparsed"].strip().split()
500 if options and options[0] not in ("autojoin", "remove"): 500 if options and options[0] not in ("autojoin", "remove"):
501 txt_cmd.feedBack(client, _("Bad arguments"), mess_data) 501 txt_cmd.feed_back(client, _("Bad arguments"), mess_data)
502 return False 502 return False
503 503
504 room_jid = mess_data["to"].userhostJID() 504 room_jid = mess_data["to"].userhostJID()
505 505
506 if "remove" in options: 506 if "remove" in options:
507 self.removeBookmark(XEP_0048.MUC_TYPE, room_jid, profile_key=client.profile) 507 self.remove_bookmark(XEP_0048.MUC_TYPE, room_jid, profile_key=client.profile)
508 txt_cmd.feedBack( 508 txt_cmd.feed_back(
509 client, 509 client,
510 _("All [%s] bookmarks are being removed") % room_jid.full(), 510 _("All [%s] bookmarks are being removed") % room_jid.full(),
511 mess_data, 511 mess_data,
512 ) 512 )
513 return False 513 return False
515 data = { 515 data = {
516 "name": room_jid.user, 516 "name": room_jid.user,
517 "nick": client.jid.user, 517 "nick": client.jid.user,
518 "autojoin": "true" if "autojoin" in options else "false", 518 "autojoin": "true" if "autojoin" in options else "false",
519 } 519 }
520 self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=client.profile) 520 self.add_bookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=client.profile)
521 txt_cmd.feedBack(client, _("Bookmark added"), mess_data) 521 txt_cmd.feed_back(client, _("Bookmark added"), mess_data)
522 522
523 return False 523 return False