MCPcopy
hub / github.com/conversejs/converse.js / waitUntilBookmarksReturned

Function waitUntilBookmarksReturned

src/headless/tests/mock.js:180–245  ·  view source on GitHub ↗
(
    _converse,
    bookmarks = [],
    features = [
        'http://jabber.org/protocol/pubsub#publish-options',
        'http://jabber.org/protocol/pubsub#config-node-max',
        'urn:xmpp:bookmarks:1#compat',
    ],
    node = 'urn:xmpp:bookmarks:1',
)

Source from the content-addressed store, hash-verified

178}
179
180export async function waitUntilBookmarksReturned(
181 _converse,
182 bookmarks = [],
183 features = [
184 'http://jabber.org/protocol/pubsub#publish-options',
185 'http://jabber.org/protocol/pubsub#config-node-max',
186 'urn:xmpp:bookmarks:1#compat',
187 ],
188 node = 'urn:xmpp:bookmarks:1',
189) {
190 const { u, sizzle, stx, Strophe } = _converse.env;
191 await waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [{ 'category': 'pubsub', 'type': 'pep' }], features);
192 const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
193 const sent_stanza = await u.waitUntil(() =>
194 IQ_stanzas.filter((s) => sizzle(`items[node="${node}"]`, s).length).pop(),
195 );
196
197 let stanza;
198 if (node === 'storage:bookmarks') {
199 stanza = stx`
200 <iq to="${_converse.api.connection.get().jid}"
201 type="result"
202 id="${sent_stanza.getAttribute('id')}"
203 xmlns="jabber:client">
204 <pubsub xmlns="${Strophe.NS.PUBSUB}">
205 <items node="storage:bookmarks">
206 <item id="current">
207 <storage xmlns="storage:bookmarks">
208 </storage>
209 </item>
210 ${bookmarks.map(
211 (b) => stx`
212 <conference name="${b.name}" autojoin="${b.autojoin}" jid="${b.jid}">
213 ${b.nick ? stx`<nick>${b.nick}</nick>` : ''}
214 </conference>`,
215 )}
216 </items>
217 </pubsub>
218 </iq>`;
219 } else {
220 stanza = stx`
221 <iq type="result"
222 to="${_converse.jid}"
223 id="${sent_stanza.getAttribute('id')}"
224 xmlns="jabber:client">
225 <pubsub xmlns="${Strophe.NS.PUBSUB}">
226 <items node="urn:xmpp:bookmarks:1">
227 ${bookmarks.map(
228 (b) => stx`
229 <item id="${b.jid}">
230 <conference xmlns="urn:xmpp:bookmarks:1"
231 name="${b.name}"
232 autojoin="${b.autojoin ?? false}">
233 ${b.nick ? stx`<nick>${b.nick}</nick>` : ''}
234 ${b.password ? stx`<password>${b.password}</password>` : ''}
235 </conference>
236 </item>`,
237 )};

Callers

nothing calls this directly

Calls 5

waitUntilDiscoConfirmedFunction · 0.85
createRequestFunction · 0.85
mapMethod · 0.80
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected