2
0

api.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import _converse from '../../shared/_converse.js';
  2. import promise_api from '../../shared/api/promise.js';
  3. const { waitUntil } = promise_api;
  4. /**
  5. * Groups methods relevant to XEP-0402 (and XEP-0048) MUC bookmarks.
  6. * @namespace api.bookmarks
  7. * @memberOf api
  8. */
  9. const bookmarks = {
  10. /**
  11. * Calling this function will result in an IQ stanza being sent out to set
  12. * the bookmark on the server.
  13. *
  14. * @method api.bookmarks.set
  15. * @param {import('./types').BookmarkAttrs} attrs - The room attributes
  16. * @param {boolean} [create=true] - Whether the bookmark should be created if it doesn't exist
  17. * @param {object} [options] - Skeletor set/add options
  18. * @returns {Promise<import('./model').default>}
  19. */
  20. async set(attrs, create = true, options = {}) {
  21. const bookmarks = await waitUntil('bookmarksInitialized');
  22. return bookmarks.setBookmark(attrs, create, options);
  23. },
  24. /**
  25. * @method api.bookmarks.get
  26. * @param {string} jid - The JID of the bookmark to return.
  27. * @returns {Promise<import('./model').default|undefined>}
  28. */
  29. async get(jid) {
  30. const bookmarks = await waitUntil('bookmarksInitialized');
  31. return bookmarks.get(jid);
  32. },
  33. };
  34. const bookmarks_api = { bookmarks };
  35. export default bookmarks_api;