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