25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Only care about pep bookmarks options when creating node from scratch

This commit is contained in:
Paweł Chmielowski 2023-10-19 19:16:49 +02:00
parent aa369de280
commit f48275bc11

View File

@ -230,7 +230,7 @@ set_data(JID, Data, PublishPepStorageBookmarks, PublishPepXmppBookmarks) ->
false -> ok
end,
case PublishPepXmppBookmarks of
true -> publish_pep_xmpp_bookmarks(JID, Data);
true -> publish_pep_native_bookmarks(JID, Data);
false -> ok
end;
{error, _} = Err ->
@ -299,6 +299,8 @@ publish_pep_storage_bookmarks(JID, Data) ->
case lists:keyfind(?NS_STORAGE_BOOKMARKS, 1, Data) of
false -> ok;
{_, El} ->
case mod_pubsub:get_items(LBJID, ?NS_STORAGE_BOOKMARKS) of
{error, #stanza_error{reason = 'item-not-found'}} ->
PubOpts = [{persist_items, true},
{access_model, whitelist}],
case mod_pubsub:publish_item(
@ -306,14 +308,22 @@ publish_pep_storage_bookmarks(JID, Data) ->
<<"current">>, [El], PubOpts, all) of
{result, _} -> ok;
{error, _} = Err -> Err
end;
_ ->
case mod_pubsub:publish_item(
LBJID, LServer, ?NS_STORAGE_BOOKMARKS, JID,
<<"current">>, [El], [], all) of
{result, _} -> ok;
{error, _} = Err -> Err
end
end
end;
false ->
ok
end.
-spec publish_pep_xmpp_bookmarks(jid(), [{binary(), xmlel()}]) -> ok | {error, stanza_error()}.
publish_pep_xmpp_bookmarks(JID, Data) ->
-spec publish_pep_native_bookmarks(jid(), [{binary(), xmlel()}]) -> ok | {error, stanza_error()}.
publish_pep_native_bookmarks(JID, Data) ->
{_, LServer, _} = LBJID = jid:remove_resource(jid:tolower(JID)),
case gen_mod:is_loaded(LServer, mod_pubsub) of
true ->
@ -323,12 +333,7 @@ publish_pep_xmpp_bookmarks(JID, Data) ->
#bookmark_storage{conference = C} -> C;
_ -> []
end,
PubOpts = [{persist_items, true},
{access_model, whitelist},
{max_items, max},
{notify_retract,true},
{notify_delete,true},
{send_last_published_item, never}],
PubOpts = [{persist_items, true}, {access_model, whitelist}, {max_items, max}, {notify_retract,true}, {notify_delete,true}, {send_last_published_item, never}],
case mod_pubsub:get_items(LBJID, ?NS_PEP_BOOKMARKS) of
PepBookmarks when is_list(PepBookmarks) ->
put(mod_private_pep_update, true),
@ -344,12 +349,12 @@ publish_pep_xmpp_bookmarks(JID, Data) ->
{Map4,
err_ret(Ret2, mod_pubsub:publish_item(
LBJID, LServer, ?NS_PEP_BOOKMARKS, JID,
jid:encode(BookmarkJID), [xmpp:encode(PB)], PubOpts, all))};
jid:encode(BookmarkJID), [xmpp:encode(PB)], [], all))};
_ ->
{Map2,
err_ret(Ret2, mod_pubsub:publish_item(
LBJID, LServer, ?NS_PEP_BOOKMARKS, JID,
jid:encode(BookmarkJID), [xmpp:encode(PB)], PubOpts, all))}
jid:encode(BookmarkJID), [xmpp:encode(PB)], [], all))}
end
end, {PepBookmarksMap, ok}, Bookmarks),
Ret4 =
@ -471,7 +476,6 @@ storage_bookmark_to_xmpp_bookmark(#bookmark_conference{name = Name, autojoin = A
-spec pubsub_item_to_map(#pubsub_item{}, map()) -> map().
pubsub_item_to_map(#pubsub_item{itemid = {Id, _}, payload = [#xmlel{} = B | _]}, Map) ->
?INFO_MSG("DECODING ~p", [B]),
case xmpp:decode(B) of
#pep_bookmarks_conference{} = B2 ->
try jid:decode(Id) of
@ -523,7 +527,7 @@ bookmarks_to_pep(User, Server) ->
Data = [{?NS_STORAGE_BOOKMARKS, El}],
case publish_pep_storage_bookmarks(jid:make(User, Server), Data) of
ok ->
case publish_pep_xmpp_bookmarks(jid:make(User, Server), Data) of
case publish_pep_native_bookmarks(jid:make(User, Server), Data) of
ok ->
{ok, <<"Bookmarks exported to PEP node">>};
{error, Err} ->