summaryrefslogtreecommitdiff
path: root/src/jlib.erl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2015-11-25 08:58:22 +0100
committerHolger Weiss <holger@zedat.fu-berlin.de>2015-11-26 08:35:49 +0100
commit44f5e411c52c89b7d544eefa7ced637a56e9648d (patch)
treeb4f0b76676a009e3bc7a99ba7bc1ea9657e07c02 /src/jlib.erl
parentAlways use occupant JID as 'from' for room subject (diff)
mod_offline: Support discarding chat states
XEP-0160 says that standalone chat state notifications should not be stored offline. By default, mod_offline discards them now. Closes #842.
Diffstat (limited to 'src/jlib.erl')
-rw-r--r--src/jlib.erl21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/jlib.erl b/src/jlib.erl
index edeb6cd0..32178121 100644
--- a/src/jlib.erl
+++ b/src/jlib.erl
@@ -43,6 +43,7 @@
get_iq_namespace/1, iq_query_info/1,
iq_query_or_response_info/1, is_iq_request_type/1,
iq_to_xml/1, parse_xdata_submit/1,
+ is_standalone_chat_state/1,
add_delay_info/3, add_delay_info/4,
timestamp_to_iso/1, timestamp_to_iso/2,
now_to_utc_string/1, now_to_local_string/1,
@@ -527,6 +528,26 @@ rsm_encode_count(Count, Arr) ->
children = [{xmlcdata, i2l(Count)}]}
| Arr].
+-spec is_standalone_chat_state(xmlel()) -> boolean().
+
+is_standalone_chat_state(#xmlel{name = <<"message">>} = El) ->
+ ChatStates = [<<"active">>, <<"inactive">>, <<"gone">>, <<"composing">>,
+ <<"paused">>],
+ Stripped =
+ lists:foldl(fun(ChatState, AccEl) ->
+ xml:remove_subtags(AccEl, ChatState,
+ {<<"xmlns">>, ?NS_CHATSTATES})
+ end, El, ChatStates),
+ case Stripped of
+ #xmlel{children = [#xmlel{name = <<"thread">>}]} ->
+ true;
+ #xmlel{children = []} ->
+ true;
+ _ ->
+ false
+ end;
+is_standalone_chat_state(_El) -> false.
+
-spec add_delay_info(xmlel(), jid() | ljid() | binary(), erlang:timestamp())
-> xmlel().