mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
Prepare version 0.6.1 of XEP-0313 (MAM) support
This commit is contained in:
parent
74749f5dbb
commit
902c6d476b
@ -25,7 +25,7 @@
|
|||||||
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.16"}}},
|
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.16"}}},
|
||||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
|
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
|
||||||
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.24"}}},
|
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.24"}}},
|
||||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "3289a6b4e3f3d82e5be513524d2293c0c2b3e7fd"}},
|
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "43676e1"}},
|
||||||
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.11"}}},
|
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.11"}}},
|
||||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
||||||
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
|
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(mod_mam).
|
-module(mod_mam).
|
||||||
|
|
||||||
-protocol({xep, 313, '0.5.1'}).
|
-protocol({xep, 313, '0.6.1'}).
|
||||||
-protocol({xep, 334, '0.2'}).
|
-protocol({xep, 334, '0.2'}).
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
@ -218,6 +218,10 @@ register_iq_handlers(Host, IQDisc) ->
|
|||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_1,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_1,
|
||||||
?MODULE, process_iq_v0_3, IQDisc),
|
?MODULE, process_iq_v0_3, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_1,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_1,
|
||||||
|
?MODULE, process_iq_v0_3, IQDisc),
|
||||||
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MAM_2,
|
||||||
|
?MODULE, process_iq_v0_3, IQDisc),
|
||||||
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_2,
|
||||||
?MODULE, process_iq_v0_3, IQDisc).
|
?MODULE, process_iq_v0_3, IQDisc).
|
||||||
|
|
||||||
-spec unregister_iq_handlers(binary()) -> ok.
|
-spec unregister_iq_handlers(binary()) -> ok.
|
||||||
@ -227,7 +231,9 @@ unregister_iq_handlers(Host) ->
|
|||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_0),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_0),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_0),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_0),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_1),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_1),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_1).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_1),
|
||||||
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MAM_2),
|
||||||
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_2).
|
||||||
|
|
||||||
-spec remove_user(binary(), binary()) -> ok.
|
-spec remove_user(binary(), binary()) -> ok.
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
@ -372,7 +378,7 @@ muc_process_iq(#iq{type = T, lang = Lang,
|
|||||||
from = From,
|
from = From,
|
||||||
sub_els = [#mam_query{xmlns = NS}]} = IQ,
|
sub_els = [#mam_query{xmlns = NS}]} = IQ,
|
||||||
MUCState)
|
MUCState)
|
||||||
when (T == set andalso (NS == ?NS_MAM_0 orelse NS == ?NS_MAM_1)) orelse
|
when (T == set andalso (NS /= ?NS_MAM_TMP)) orelse
|
||||||
(T == get andalso NS == ?NS_MAM_TMP) ->
|
(T == get andalso NS == ?NS_MAM_TMP) ->
|
||||||
case may_enter_room(From, MUCState) of
|
case may_enter_room(From, MUCState) of
|
||||||
true ->
|
true ->
|
||||||
@ -385,7 +391,7 @@ muc_process_iq(#iq{type = T, lang = Lang,
|
|||||||
end;
|
end;
|
||||||
muc_process_iq(#iq{type = get,
|
muc_process_iq(#iq{type = get,
|
||||||
sub_els = [#mam_query{xmlns = NS}]} = IQ,
|
sub_els = [#mam_query{xmlns = NS}]} = IQ,
|
||||||
MUCState) when NS == ?NS_MAM_0; NS == ?NS_MAM_1 ->
|
MUCState) when NS /= ?NS_MAM_TMP ->
|
||||||
LServer = MUCState#state.server_host,
|
LServer = MUCState#state.server_host,
|
||||||
process_iq(LServer, IQ);
|
process_iq(LServer, IQ);
|
||||||
muc_process_iq(IQ, _MUCState) ->
|
muc_process_iq(IQ, _MUCState) ->
|
||||||
@ -415,7 +421,7 @@ disco_sm_features(empty, From, To, Node, Lang) ->
|
|||||||
disco_sm_features({result, OtherFeatures},
|
disco_sm_features({result, OtherFeatures},
|
||||||
#jid{luser = U, lserver = S},
|
#jid{luser = U, lserver = S},
|
||||||
#jid{luser = U, lserver = S}, <<"">>, _Lang) ->
|
#jid{luser = U, lserver = S}, <<"">>, _Lang) ->
|
||||||
{result, [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1 | OtherFeatures]};
|
{result, [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1, ?NS_MAM_2 | OtherFeatures]};
|
||||||
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
@ -940,13 +946,13 @@ send(Msgs, Count, IsComplete,
|
|||||||
#mam_fin{xmlns = NS, id = QID, rsm = RSMOut,
|
#mam_fin{xmlns = NS, id = QID, rsm = RSMOut,
|
||||||
complete = IsComplete}
|
complete = IsComplete}
|
||||||
end,
|
end,
|
||||||
if NS == ?NS_MAM_TMP; NS == ?NS_MAM_1 ->
|
if NS /= ?NS_MAM_0 ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(El) ->
|
fun(El) ->
|
||||||
ejabberd_router:route(El)
|
ejabberd_router:route(El)
|
||||||
end, Els),
|
end, Els),
|
||||||
xmpp:make_iq_result(IQ, Result);
|
xmpp:make_iq_result(IQ, Result);
|
||||||
NS == ?NS_MAM_0 ->
|
true ->
|
||||||
ejabberd_router:route(xmpp:make_iq_result(IQ)),
|
ejabberd_router:route(xmpp:make_iq_result(IQ)),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(El) ->
|
fun(El) ->
|
||||||
|
@ -516,7 +516,7 @@ process_disco_info(#iq{type = get, to = To, lang = Lang,
|
|||||||
X = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
|
X = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
|
||||||
[ServerHost, ?MODULE, <<"">>, Lang]),
|
[ServerHost, ?MODULE, <<"">>, Lang]),
|
||||||
MAMFeatures = case gen_mod:is_loaded(ServerHost, mod_mam) of
|
MAMFeatures = case gen_mod:is_loaded(ServerHost, mod_mam) of
|
||||||
true -> [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1];
|
true -> [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1, ?NS_MAM_2];
|
||||||
false -> []
|
false -> []
|
||||||
end,
|
end,
|
||||||
RSMFeatures = case RMod:rsm_supported() of
|
RSMFeatures = case RMod:rsm_supported() of
|
||||||
|
@ -3643,7 +3643,7 @@ process_iq_disco_info(_From, #iq{type = get, lang = Lang}, StateData) ->
|
|||||||
++ case {gen_mod:is_loaded(StateData#state.server_host, mod_mam),
|
++ case {gen_mod:is_loaded(StateData#state.server_host, mod_mam),
|
||||||
Config#config.mam} of
|
Config#config.mam} of
|
||||||
{true, true} ->
|
{true, true} ->
|
||||||
[?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1];
|
[?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1, ?NS_MAM_2];
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
muc_jid/1, is_feature_advertised/3, get_event/1, put_event/2]).
|
muc_jid/1, is_feature_advertised/3, get_event/1, put_event/2]).
|
||||||
|
|
||||||
-include("suite.hrl").
|
-include("suite.hrl").
|
||||||
-define(VERSIONS, [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1]).
|
-define(VERSIONS, [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1, ?NS_MAM_2]).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
@ -58,6 +58,7 @@ feature_enabled(Config) ->
|
|||||||
true = sets:is_subset(RequiredFeatures, UserFeatures),
|
true = sets:is_subset(RequiredFeatures, UserFeatures),
|
||||||
ct:comment("Checking if all MAM conference service features are enabled"),
|
ct:comment("Checking if all MAM conference service features are enabled"),
|
||||||
true = lists:member(?NS_MAM_1, MUCFeatures),
|
true = lists:member(?NS_MAM_1, MUCFeatures),
|
||||||
|
true = lists:member(?NS_MAM_2, MUCFeatures),
|
||||||
clean(disconnect(Config)).
|
clean(disconnect(Config)).
|
||||||
|
|
||||||
fake_by(Config) ->
|
fake_by(Config) ->
|
||||||
@ -259,6 +260,7 @@ muc_master(Config) ->
|
|||||||
%% MAM feature should not be advertised at this point,
|
%% MAM feature should not be advertised at this point,
|
||||||
%% because MAM is not enabled so far
|
%% because MAM is not enabled so far
|
||||||
false = is_feature_advertised(Config, ?NS_MAM_1, Room),
|
false = is_feature_advertised(Config, ?NS_MAM_1, Room),
|
||||||
|
false = is_feature_advertised(Config, ?NS_MAM_2, Room),
|
||||||
%% Fill in some history
|
%% Fill in some history
|
||||||
send_messages_to_room(Config, lists:seq(1, 21)),
|
send_messages_to_room(Config, lists:seq(1, 21)),
|
||||||
%% We now should be able to retrieve those via MAM, even though
|
%% We now should be able to retrieve those via MAM, even though
|
||||||
@ -284,6 +286,7 @@ muc_master(Config) ->
|
|||||||
sub_els = [#muc_user{status_codes = [104]}]} = recv_message(Config),
|
sub_els = [#muc_user{status_codes = [104]}]} = recv_message(Config),
|
||||||
%% Check if MAM has been enabled
|
%% Check if MAM has been enabled
|
||||||
true = is_feature_advertised(Config, ?NS_MAM_1, Room),
|
true = is_feature_advertised(Config, ?NS_MAM_1, Room),
|
||||||
|
true = is_feature_advertised(Config, ?NS_MAM_2, Room),
|
||||||
%% We now sending some messages again
|
%% We now sending some messages again
|
||||||
send_messages_to_room(Config, lists:seq(1, 5)),
|
send_messages_to_room(Config, lists:seq(1, 5)),
|
||||||
%% And retrieve them via MAM again.
|
%% And retrieve them via MAM again.
|
||||||
@ -377,7 +380,7 @@ send_query(Config, #mam_query{xmlns = NS} = Query) ->
|
|||||||
maybe_recv_iq_result(Config, NS, I),
|
maybe_recv_iq_result(Config, NS, I),
|
||||||
I.
|
I.
|
||||||
|
|
||||||
recv_fin(Config, I, QueryID, ?NS_MAM_1 = NS, IsComplete) ->
|
recv_fin(Config, I, QueryID, NS, IsComplete) when NS == ?NS_MAM_1; NS == ?NS_MAM_2 ->
|
||||||
ct:comment("Receiving fin iq for namespace '~s'", [NS]),
|
ct:comment("Receiving fin iq for namespace '~s'", [NS]),
|
||||||
#iq{type = result, id = I,
|
#iq{type = result, id = I,
|
||||||
sub_els = [#mam_fin{xmlns = NS,
|
sub_els = [#mam_fin{xmlns = NS,
|
||||||
@ -427,7 +430,7 @@ recv_messages_from_room(Config, Range) ->
|
|||||||
QID = randoms:get_string(),
|
QID = randoms:get_string(),
|
||||||
Count = length(Range),
|
Count = length(Range),
|
||||||
I = send(Config, #iq{type = set, to = Room,
|
I = send(Config, #iq{type = set, to = Room,
|
||||||
sub_els = [#mam_query{xmlns = ?NS_MAM_1, id = QID}]}),
|
sub_els = [#mam_query{xmlns = ?NS_MAM_2, id = QID}]}),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(N) ->
|
fun(N) ->
|
||||||
Body = xmpp:mk_text(integer_to_binary(N)),
|
Body = xmpp:mk_text(integer_to_binary(N)),
|
||||||
@ -435,7 +438,7 @@ recv_messages_from_room(Config, Range) ->
|
|||||||
to = MyJID, from = Room,
|
to = MyJID, from = Room,
|
||||||
sub_els =
|
sub_els =
|
||||||
[#mam_result{
|
[#mam_result{
|
||||||
xmlns = ?NS_MAM_1,
|
xmlns = ?NS_MAM_2,
|
||||||
queryid = QID,
|
queryid = QID,
|
||||||
sub_els =
|
sub_els =
|
||||||
[#forwarded{
|
[#forwarded{
|
||||||
@ -446,7 +449,7 @@ recv_messages_from_room(Config, Range) ->
|
|||||||
body = Body} = xmpp:decode(El)
|
body = Body} = xmpp:decode(El)
|
||||||
end, Range),
|
end, Range),
|
||||||
#iq{from = Room, id = I, type = result,
|
#iq{from = Room, id = I, type = result,
|
||||||
sub_els = [#mam_fin{xmlns = ?NS_MAM_1,
|
sub_els = [#mam_fin{xmlns = ?NS_MAM_2,
|
||||||
id = QID,
|
id = QID,
|
||||||
rsm = #rsm_set{count = Count},
|
rsm = #rsm_set{count = Count},
|
||||||
complete = true}]} = recv_iq(Config).
|
complete = true}]} = recv_iq(Config).
|
||||||
|
Loading…
Reference in New Issue
Block a user