@@ -257,4 +257,105 @@ describe("A bookmark", function () {
257257 </pubsub>
258258 </iq>` ) ;
259259 } ) ) ;
260+
261+ it ( "can be removed and republishes all remaining bookmarks as per XEP-0048" , mock . initConverse (
262+ [ 'connected' , 'chatBoxesFetched' ] , { } , async function ( _converse ) {
263+
264+ await mock . waitForRoster ( _converse , 'current' , 0 ) ;
265+ await mock . waitUntilBookmarksReturned (
266+ _converse ,
267+ [ ] ,
268+ [ 'http://jabber.org/protocol/pubsub#publish-options' , 'http://jabber.org/protocol/pubsub#config-node-max' ] ,
269+ 'storage:bookmarks'
270+ ) ;
271+
272+ const bare_jid = _converse . session . get ( 'bare_jid' ) ;
273+ const muc1_jid = '[email protected] ' ; 274+ const muc2_jid = '[email protected] ' ; 275+ const { bookmarks } = _converse . state ;
276+
277+ // First create two bookmarks
278+ bookmarks . setBookmark ( {
279+ jid : muc1_jid ,
280+ autojoin : true ,
281+ name : 'Hamlet' ,
282+ nick : ''
283+ } ) ;
284+
285+ const IQ_stanzas = _converse . api . connection . get ( ) . IQ_stanzas ;
286+ let sent_stanza = await u . waitUntil (
287+ ( ) => IQ_stanzas . filter ( s => sizzle ( 'item[id="current"]' , s ) . length ) . pop ( ) ) ;
288+
289+ // Server acknowledges successful storage
290+ const result_stanza = stx `
291+ <iq xmlns="jabber:client"
292+ to="${ _converse . api . connection . get ( ) . jid } "
293+ type="result"
294+ id="${ sent_stanza . getAttribute ( 'id' ) } "/>` ;
295+ _converse . api . connection . get ( ) . _dataRecv ( mock . createRequest ( result_stanza ) ) ;
296+
297+ bookmarks . setBookmark ( {
298+ jid : muc2_jid ,
299+ autojoin : true ,
300+ name : 'Balcony' ,
301+ nick : 'romeo'
302+ } ) ;
303+
304+ sent_stanza = await u . waitUntil (
305+ ( ) => IQ_stanzas . filter ( s => sizzle ( 'item[id="current"] conference[name="Balcony"]' , s ) . length ) . pop ( ) ) ;
306+
307+ // Server acknowledges successful storage
308+ const result_stanza2 = stx `
309+ <iq xmlns="jabber:client"
310+ to="${ _converse . api . connection . get ( ) . jid } "
311+ type="result"
312+ id="${ sent_stanza . getAttribute ( 'id' ) } "/>` ;
313+ _converse . api . connection . get ( ) . _dataRecv ( mock . createRequest ( result_stanza2 ) ) ;
314+
315+ // Clear previous stanzas
316+ while ( IQ_stanzas . length ) { IQ_stanzas . pop ( ) ; }
317+
318+ // Now remove one bookmark
319+ const bookmark = bookmarks . findWhere ( { jid : muc1_jid } ) ;
320+ expect ( bookmark ) . toBeTruthy ( ) ;
321+ bookmarks . remove ( bookmark ) ;
322+
323+ // Check that a stanza is sent with all remaining bookmarks (XEP-0048 style)
324+ sent_stanza = await u . waitUntil (
325+ ( ) => IQ_stanzas . filter ( s => sizzle ( 'publish[node="storage:bookmarks"]' , s ) . length ) . pop ( ) ) ;
326+
327+ expect ( sent_stanza ) . toEqualStanza ( stx `
328+ <iq from="${ bare_jid } " to="${ bare_jid } " id="${ sent_stanza . getAttribute ( 'id' ) } " type="set" xmlns="jabber:client">
329+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
330+ <publish node="storage:bookmarks">
331+ <item id="current">
332+ <storage xmlns="storage:bookmarks">
333+ <conference autojoin="true" jid="${ muc2_jid } " name="Balcony">
334+ <nick>romeo</nick>
335+ </conference>
336+ </storage>
337+ </item>
338+ </publish>
339+ <publish-options>
340+ <x type="submit" xmlns="jabber:x:data">
341+ <field type="hidden" var="FORM_TYPE">
342+ <value>http://jabber.org/protocol/pubsub#publish-options</value>
343+ </field>
344+ <field var='pubsub#persist_items'>
345+ <value>true</value>
346+ </field>
347+ <field var='pubsub#max_items'>
348+ <value>max</value>
349+ </field>
350+ <field var='pubsub#send_last_published_item'>
351+ <value>never</value>
352+ </field>
353+ <field var='pubsub#access_model'>
354+ <value>whitelist</value>
355+ </field>
356+ </x>
357+ </publish-options>
358+ </pubsub>
359+ </iq>` ) ;
360+ } ) ) ;
260361} ) ;
0 commit comments