diff options
author | badlop <badlop@ono.com> | 2014-05-21 17:31:22 +0200 |
---|---|---|
committer | badlop <badlop@ono.com> | 2014-05-21 17:31:22 +0200 |
commit | 5d855f3723cc79817ac883f180d449c44d5e58a7 (patch) | |
tree | 361ce9a14adcbe10c5dc683c0b28e084782a33bb /src | |
parent | If log uses file:write, no need to double escape ~ in messages (EJAB-1696) (diff) | |
parent | Don't log MUC messages with <no-store/> hint (diff) |
Merge pull request #207 from weiss/xep-0334
Honor XEP-0334: Message Processing Hints
Diffstat (limited to 'src')
-rw-r--r-- | src/mod_carboncopy.erl | 37 | ||||
-rw-r--r-- | src/mod_muc_log.erl | 24 | ||||
-rw-r--r-- | src/mod_offline.erl | 39 |
3 files changed, 64 insertions, 36 deletions
diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 16f0c06fc..6f3101fcd 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -143,24 +143,29 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, <<"chat">> -> case xml:get_subtag(Packet, <<"private">>) of false -> - case xml:get_subtag(Packet,<<"received">>) of + case xml:get_subtag(Packet, <<"no-copy">>) of false -> - %% We must check if a packet contains "<sent><forwarded></sent></forwarded>" tags in order to avoid - %% receiving message back to original sender. - SubTag = xml:get_subtag(Packet,<<"sent">>), - if SubTag == false -> - send_copies(JID, To, Packet, Direction); - true -> - case xml:get_subtag(SubTag,<<"forwarded">>) of - false-> - send_copies(JID, To, Packet, Direction); - _ -> - stop - end - end; + case xml:get_subtag(Packet,<<"received">>) of + false -> + %% We must check if a packet contains "<sent><forwarded></sent></forwarded>" + %% tags in order to avoid receiving message back to original sender. + SubTag = xml:get_subtag(Packet,<<"sent">>), + if SubTag == false -> + send_copies(JID, To, Packet, Direction); + true -> + case xml:get_subtag(SubTag,<<"forwarded">>) of + false-> + send_copies(JID, To, Packet, Direction); + _ -> + stop + end + end; + _ -> + %% stop the hook chain, we don't want mod_logdb to register this message (duplicate) + stop + end; _ -> - %% stop the hook chain, we don't want mod_logdb to register this message (duplicate) - stop + ok end; _ -> ok diff --git a/src/mod_muc_log.erl b/src/mod_muc_log.erl index b4db67b3d..ac6bea4fa 100644 --- a/src/mod_muc_log.erl +++ b/src/mod_muc_log.erl @@ -233,16 +233,22 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. %%% Internal functions %%-------------------------------------------------------------------- add_to_log2(text, {Nick, Packet}, Room, Opts, State) -> - case {xml:get_subtag(Packet, <<"subject">>), - xml:get_subtag(Packet, <<"body">>)} + case {xml:get_subtag(Packet, <<"no-store">>), + xml:get_subtag(Packet, <<"no-permanent-store">>)} of - {false, false} -> ok; - {false, SubEl} -> - Message = {body, xml:get_tag_cdata(SubEl)}, - add_message_to_log(Nick, Message, Room, Opts, State); - {SubEl, _} -> - Message = {subject, xml:get_tag_cdata(SubEl)}, - add_message_to_log(Nick, Message, Room, Opts, State) + {false, false} -> + case {xml:get_subtag(Packet, <<"subject">>), + xml:get_subtag(Packet, <<"body">>)} + of + {false, false} -> ok; + {false, SubEl} -> + Message = {body, xml:get_tag_cdata(SubEl)}, + add_message_to_log(Nick, Message, Room, Opts, State); + {SubEl, _} -> + Message = {subject, xml:get_tag_cdata(SubEl)}, + add_message_to_log(Nick, Message, Room, Opts, State) + end; + {_, _} -> ok end; add_to_log2(roomconfig_change, _Occupants, Room, Opts, State) -> diff --git a/src/mod_offline.erl b/src/mod_offline.erl index fca227d31..f27d35830 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -237,22 +237,39 @@ store_packet(From, To, Packet) -> Type = xml:get_tag_attr_s(<<"type">>, Packet), if (Type /= <<"error">>) and (Type /= <<"groupchat">>) and (Type /= <<"headline">>) -> - case check_event(From, To, Packet) of - true -> - #jid{luser = LUser, lserver = LServer} = To, - TimeStamp = now(), - #xmlel{children = Els} = Packet, - Expire = find_x_expire(TimeStamp, Els), - gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) ! - #offline_msg{us = {LUser, LServer}, - timestamp = TimeStamp, expire = Expire, - from = From, to = To, packet = Packet}, - stop; + case has_no_storage_hint(Packet) of + false -> + case check_event(From, To, Packet) of + true -> + #jid{luser = LUser, lserver = LServer} = To, + TimeStamp = now(), + #xmlel{children = Els} = Packet, + Expire = find_x_expire(TimeStamp, Els), + gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) ! + #offline_msg{us = {LUser, LServer}, + timestamp = TimeStamp, expire = Expire, + from = From, to = To, packet = Packet}, + stop; + _ -> ok + end; _ -> ok end; true -> ok end. +has_no_storage_hint(Packet) -> + case xml:get_subtag(Packet, <<"no-store">>) of + #xmlel{attrs = Attrs} -> + case xml:get_attr_s(<<"xmlns">>, Attrs) of + ?NS_HINTS -> + true; + _ -> + false + end; + _ -> + false + end. + %% Check if the packet has any content about XEP-0022 or XEP-0085 check_event(From, To, Packet) -> #xmlel{name = Name, attrs = Attrs, children = Els} = |