aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Khramtsov <ekhramtsov@process-one.net>2018-12-07 11:06:26 +0300
committerEvgeny Khramtsov <ekhramtsov@process-one.net>2018-12-07 11:06:26 +0300
commit6afefd7bbf1128c28e6b62be639db02929ea7baf (patch)
tree6fe0470065bde3472fd605537ad0afed33bb4109
parentBump xmpp version (diff)
Fix submission-id and channel resource
-rw-r--r--rebar.config2
-rw-r--r--src/mod_mix.erl56
2 files changed, 35 insertions, 23 deletions
diff --git a/rebar.config b/rebar.config
index 019b1b0a0..a464c9345 100644
--- a/rebar.config
+++ b/rebar.config
@@ -24,7 +24,7 @@
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.26"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.14"}}},
{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"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
diff --git a/src/mod_mix.erl b/src/mod_mix.erl
index e9b91202b..9eebe21c4 100644
--- a/src/mod_mix.erl
+++ b/src/mod_mix.erl
@@ -128,7 +128,8 @@ process_disco_info(#iq{type = get, to = #jid{luser = <<>>} = To,
identities = [Identity],
xdata = X});
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),
ServerHost = ejabberd_router:host_of_route(Host),
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,
?NS_MIX_CORE_0, ?NS_MAM_2],
xmpp:make_iq_result(
- IQ, #disco_info{node = <<"mix">>,
+ IQ, #disco_info{node = Node,
features = Features,
identities = [Identity]});
{error, notfound} ->
@@ -170,15 +171,16 @@ process_disco_items(#iq{type = get, to = #jid{luser = <<>>} = To,
xmpp:make_error(IQ, db_error(IQ))
end;
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),
ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
case Mod:get_channel(ServerHost, Chan, Host) of
{ok, _} ->
BTo = jid:remove_resource(To),
- Items = [#disco_item{jid = BTo, node = Node} || Node <- known_nodes()],
- xmpp:make_iq_result(IQ, #disco_items{node = <<"mix">>, items = Items});
+ Items = [#disco_item{jid = BTo, node = N} || N <- known_nodes()],
+ xmpp:make_iq_result(IQ, #disco_items{node = Node, items = Items});
{error, notfound} ->
xmpp:make_error(IQ, no_channel_error(IQ));
{error, db_failure} ->
@@ -438,29 +440,36 @@ process_mix_setnick(#iq{to = To, from = From,
process_mix_message(#message{from = From, to = To,
id = SubmissionID} = Msg) ->
{Chan, Host, _} = jid:tolower(To),
+ {FUser, FServer, _} = jid:tolower(From),
ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
case Mod:get_channel(ServerHost, Chan, Host) of
{ok, _} ->
BFrom = jid:remove_resource(From),
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
- {ok, {_ID, Nick}} ->
+ {ok, {StableID, Nick}} ->
MamID = mod_mam:make_id(),
- Msg1 = xmpp:put_meta(
- xmpp:set_subtag(
- Msg#message{from = jid:remove_resource(To),
- to = undefined,
- id = integer_to_binary(MamID)},
- #mix{jid = BFrom,
- nick = Nick,
- submission_id = SubmissionID}),
- stanza_id, MamID),
+ Msg1 = xmpp:set_subtag(
+ Msg#message{from = jid:replace_resource(To, StableID),
+ to = undefined,
+ id = integer_to_binary(MamID)},
+ #mix{jid = BFrom, nick = Nick}),
+ Msg2 = xmpp:put_meta(Msg1, stanza_id, MamID),
case ejabberd_hooks:run_fold(
- store_mam_message, ServerHost, Msg1,
+ store_mam_message, ServerHost, Msg2,
[Chan, Host, BFrom, Nick, groupchat, recv]) of
- #message{} = Msg2 ->
+ #message{} ->
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
end;
@@ -529,13 +538,14 @@ filter_nodes(Nodes) ->
end, known_nodes()).
-spec multicast(module(), binary(), binary(),
- binary(), binary(), message()) -> ok.
-multicast(Mod, LServer, Chan, Service, Node, Msg) ->
+ binary(), binary(), fun((jid()) -> message())) -> ok.
+multicast(Mod, LServer, Chan, Service, Node, F) ->
case Mod:get_subscribed(LServer, Chan, Service, Node) of
{ok, Subscribers} ->
lists:foreach(
fun(To) ->
- ejabberd_router:route(Msg#message{to = To})
+ Msg = xmpp:set_to(F(To), To),
+ ejabberd_router:route(Msg)
end, Subscribers);
{error, db_failure} ->
ok
@@ -555,7 +565,9 @@ notify_participant_joined(Mod, LServer, To, From, ID, Nick) ->
Msg = #message{from = jid:remove_resource(To),
id = p1_rand:get_string(),
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.
notify_participant_left(Mod, LServer, To, ID) ->