Fix submission-id and channel resource
This commit is contained in:
parent
c4858a7020
commit
6afefd7bbf
|
@ -24,7 +24,7 @@
|
||||||
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.26"}}},
|
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.26"}}},
|
||||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.14"}}},
|
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.14"}}},
|
||||||
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.34"}}},
|
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.34"}}},
|
||||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "4b74c17"}},
|
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "278ddf9"}},
|
||||||
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.17"}}},
|
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.17"}}},
|
||||||
{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.3"}}},
|
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
||||||
|
|
|
@ -128,7 +128,8 @@ process_disco_info(#iq{type = get, to = #jid{luser = <<>>} = To,
|
||||||
identities = [Identity],
|
identities = [Identity],
|
||||||
xdata = X});
|
xdata = X});
|
||||||
process_disco_info(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
process_disco_info(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
||||||
sub_els = [#disco_info{node = <<"mix">>}]} = IQ) ->
|
sub_els = [#disco_info{node = Node}]} = IQ)
|
||||||
|
when Node == <<"mix">>; Node == <<>> ->
|
||||||
{Chan, Host, _} = jid:tolower(To),
|
{Chan, Host, _} = jid:tolower(To),
|
||||||
ServerHost = ejabberd_router:host_of_route(Host),
|
ServerHost = ejabberd_router:host_of_route(Host),
|
||||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||||
|
@ -139,7 +140,7 @@ process_disco_info(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
||||||
Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
|
Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
|
||||||
?NS_MIX_CORE_0, ?NS_MAM_2],
|
?NS_MIX_CORE_0, ?NS_MAM_2],
|
||||||
xmpp:make_iq_result(
|
xmpp:make_iq_result(
|
||||||
IQ, #disco_info{node = <<"mix">>,
|
IQ, #disco_info{node = Node,
|
||||||
features = Features,
|
features = Features,
|
||||||
identities = [Identity]});
|
identities = [Identity]});
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
|
@ -170,15 +171,16 @@ process_disco_items(#iq{type = get, to = #jid{luser = <<>>} = To,
|
||||||
xmpp:make_error(IQ, db_error(IQ))
|
xmpp:make_error(IQ, db_error(IQ))
|
||||||
end;
|
end;
|
||||||
process_disco_items(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
process_disco_items(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
||||||
sub_els = [#disco_items{node = <<"mix">>}]} = IQ) ->
|
sub_els = [#disco_items{node = Node}]} = IQ)
|
||||||
|
when Node == <<"mix">>; Node == <<>> ->
|
||||||
{Chan, Host, _} = jid:tolower(To),
|
{Chan, Host, _} = jid:tolower(To),
|
||||||
ServerHost = ejabberd_router:host_of_route(Host),
|
ServerHost = ejabberd_router:host_of_route(Host),
|
||||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||||
case Mod:get_channel(ServerHost, Chan, Host) of
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
BTo = jid:remove_resource(To),
|
BTo = jid:remove_resource(To),
|
||||||
Items = [#disco_item{jid = BTo, node = Node} || Node <- known_nodes()],
|
Items = [#disco_item{jid = BTo, node = N} || N <- known_nodes()],
|
||||||
xmpp:make_iq_result(IQ, #disco_items{node = <<"mix">>, items = Items});
|
xmpp:make_iq_result(IQ, #disco_items{node = Node, items = Items});
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
xmpp:make_error(IQ, no_channel_error(IQ));
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
||||||
{error, db_failure} ->
|
{error, db_failure} ->
|
||||||
|
@ -438,29 +440,36 @@ process_mix_setnick(#iq{to = To, from = From,
|
||||||
process_mix_message(#message{from = From, to = To,
|
process_mix_message(#message{from = From, to = To,
|
||||||
id = SubmissionID} = Msg) ->
|
id = SubmissionID} = Msg) ->
|
||||||
{Chan, Host, _} = jid:tolower(To),
|
{Chan, Host, _} = jid:tolower(To),
|
||||||
|
{FUser, FServer, _} = jid:tolower(From),
|
||||||
ServerHost = ejabberd_router:host_of_route(Host),
|
ServerHost = ejabberd_router:host_of_route(Host),
|
||||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||||
case Mod:get_channel(ServerHost, Chan, Host) of
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
BFrom = jid:remove_resource(From),
|
BFrom = jid:remove_resource(From),
|
||||||
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
||||||
{ok, {_ID, Nick}} ->
|
{ok, {StableID, Nick}} ->
|
||||||
MamID = mod_mam:make_id(),
|
MamID = mod_mam:make_id(),
|
||||||
Msg1 = xmpp:put_meta(
|
Msg1 = xmpp:set_subtag(
|
||||||
xmpp:set_subtag(
|
Msg#message{from = jid:replace_resource(To, StableID),
|
||||||
Msg#message{from = jid:remove_resource(To),
|
to = undefined,
|
||||||
to = undefined,
|
id = integer_to_binary(MamID)},
|
||||||
id = integer_to_binary(MamID)},
|
#mix{jid = BFrom, nick = Nick}),
|
||||||
#mix{jid = BFrom,
|
Msg2 = xmpp:put_meta(Msg1, stanza_id, MamID),
|
||||||
nick = Nick,
|
|
||||||
submission_id = SubmissionID}),
|
|
||||||
stanza_id, MamID),
|
|
||||||
case ejabberd_hooks:run_fold(
|
case ejabberd_hooks:run_fold(
|
||||||
store_mam_message, ServerHost, Msg1,
|
store_mam_message, ServerHost, Msg2,
|
||||||
[Chan, Host, BFrom, Nick, groupchat, recv]) of
|
[Chan, Host, BFrom, Nick, groupchat, recv]) of
|
||||||
#message{} = Msg2 ->
|
#message{} ->
|
||||||
multicast(Mod, ServerHost, Chan, Host,
|
multicast(Mod, ServerHost, Chan, Host,
|
||||||
?NS_MIX_NODES_MESSAGES, Msg2);
|
?NS_MIX_NODES_MESSAGES,
|
||||||
|
fun(#jid{luser = U, lserver = S})
|
||||||
|
when U == FUser, S == FServer ->
|
||||||
|
xmpp:set_subtag(
|
||||||
|
Msg1, #mix{jid = BFrom,
|
||||||
|
nick = Nick,
|
||||||
|
submission_id = SubmissionID});
|
||||||
|
(_) ->
|
||||||
|
Msg1
|
||||||
|
end);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
|
@ -529,13 +538,14 @@ filter_nodes(Nodes) ->
|
||||||
end, known_nodes()).
|
end, known_nodes()).
|
||||||
|
|
||||||
-spec multicast(module(), binary(), binary(),
|
-spec multicast(module(), binary(), binary(),
|
||||||
binary(), binary(), message()) -> ok.
|
binary(), binary(), fun((jid()) -> message())) -> ok.
|
||||||
multicast(Mod, LServer, Chan, Service, Node, Msg) ->
|
multicast(Mod, LServer, Chan, Service, Node, F) ->
|
||||||
case Mod:get_subscribed(LServer, Chan, Service, Node) of
|
case Mod:get_subscribed(LServer, Chan, Service, Node) of
|
||||||
{ok, Subscribers} ->
|
{ok, Subscribers} ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(To) ->
|
fun(To) ->
|
||||||
ejabberd_router:route(Msg#message{to = To})
|
Msg = xmpp:set_to(F(To), To),
|
||||||
|
ejabberd_router:route(Msg)
|
||||||
end, Subscribers);
|
end, Subscribers);
|
||||||
{error, db_failure} ->
|
{error, db_failure} ->
|
||||||
ok
|
ok
|
||||||
|
@ -555,7 +565,9 @@ notify_participant_joined(Mod, LServer, To, From, ID, Nick) ->
|
||||||
Msg = #message{from = jid:remove_resource(To),
|
Msg = #message{from = jid:remove_resource(To),
|
||||||
id = p1_rand:get_string(),
|
id = p1_rand:get_string(),
|
||||||
sub_els = [Event]},
|
sub_els = [Event]},
|
||||||
multicast(Mod, LServer, Chan, Host, ?NS_MIX_NODES_PARTICIPANTS, Msg).
|
multicast(Mod, LServer, Chan, Host,
|
||||||
|
?NS_MIX_NODES_PARTICIPANTS,
|
||||||
|
fun(_) -> Msg end).
|
||||||
|
|
||||||
-spec notify_participant_left(module(), binary(), jid(), binary()) -> ok.
|
-spec notify_participant_left(module(), binary(), jid(), binary()) -> ok.
|
||||||
notify_participant_left(Mod, LServer, To, ID) ->
|
notify_participant_left(Mod, LServer, To, ID) ->
|
||||||
|
|
Loading…
Reference in New Issue