]> granicus.if.org Git - ejabberd/commitdiff
Support XEP-0085 Chat State Notifications (EJAB-961)
authorBadlop <badlop@process-one.net>
Tue, 30 Jun 2009 19:32:22 +0000 (19:32 +0000)
committerBadlop <badlop@process-one.net>
Tue, 30 Jun 2009 19:32:22 +0000 (19:32 +0000)
SVN Revision: 2350

src/jlib.hrl
src/mod_offline.erl
src/mod_offline_odbc.erl

index 0a01a7b752aa76cb518ed9b84c0fe47c2f1c15b2..32765e08a48ecdf3914dc1e0f873c8a1041f9e9a 100644 (file)
@@ -39,6 +39,7 @@
 -define(NS_DELAY,        "urn:xmpp:delay").
 -define(NS_EXPIRE,       "jabber:x:expire").
 -define(NS_EVENT,        "jabber:x:event").
+-define(NS_CHATSTATES,   "http://jabber.org/protocol/chatstates").
 -define(NS_XCONFERENCE,  "jabber:x:conference").
 -define(NS_STATS,        "http://jabber.org/protocol/stats").
 -define(NS_MUC,          "http://jabber.org/protocol/muc").
index 9c375997add2644dba4940081463d3216b70e26f..78c3b2eca792ec303a6ee02092e316d5ff27f2f0 100644 (file)
@@ -181,7 +181,7 @@ store_packet(From, To, Packet) ->
     if
        (Type /= "error") and (Type /= "groupchat") and
        (Type /= "headline") ->
-           case check_event(From, To, Packet) of
+           case check_event_chatstates(From, To, Packet) of
                true ->
                    #jid{luser = LUser, lserver = LServer} = To,
                    TimeStamp = now(),
@@ -202,12 +202,22 @@ store_packet(From, To, Packet) ->
            ok
     end.
 
-check_event(From, To, Packet) ->
+%% Check if the packet has any content about XEP-0022 or XEP-0085
+check_event_chatstates(From, To, Packet) ->
     {xmlelement, Name, Attrs, Els} = Packet,
-    case find_x_event(Els) of
-       false ->
+    case find_x_event_chatstates(Els, {false, false, false}) of
+       %% There wasn't any x:event or chatstates subelements
+       {false, false, _} ->
+           true;
+       %% There a chatstates subelement and other stuff, but no x:event
+       {false, CEl, true} when CEl /= false ->
            true;
-       El ->
+       %% There was only a subelement: a chatstates
+       {false, CEl, false} when CEl /= false ->
+           %% Don't allow offline storage
+           false;
+       %% There was an x:event element, and maybe also other stuff
+       {El, _, _} when El /= false ->
            case xml:get_subtag(El, "id") of
                false ->
                    case xml:get_subtag(El, "offline") of
@@ -235,16 +245,19 @@ check_event(From, To, Packet) ->
            end
     end.
 
-find_x_event([]) ->
-    false;
-find_x_event([{xmlcdata, _} | Els]) ->
-    find_x_event(Els);
-find_x_event([El | Els]) ->
+%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
+find_x_event_chatstates([], Res) ->
+    Res;
+find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
+    find_x_event_chatstates(Els, Res);
+find_x_event_chatstates([El | Els], {A, B, C}) ->
     case xml:get_tag_attr_s("xmlns", El) of
        ?NS_EVENT ->
-           El;
+           find_x_event_chatstates(Els, {El, B, C});
+       ?NS_CHATSTATES ->
+           find_x_event_chatstates(Els, {A, El, C});
        _ ->
-           find_x_event(Els)
+           find_x_event_chatstates(Els, {A, B, true})
     end.
 
 find_x_expire(_, []) ->
index 891ec6419598dea020074f78b34cce944c40b8b0..d7bbd3bf3c959f9c481e8374dd1822a70797f70e 100644 (file)
@@ -199,7 +199,7 @@ store_packet(From, To, Packet) ->
     if
        (Type /= "error") and (Type /= "groupchat") and
        (Type /= "headline") ->
-           case check_event(From, To, Packet) of
+           case check_event_chatstates(From, To, Packet) of
                true ->
                    #jid{luser = LUser} = To,
                    TimeStamp = now(),
@@ -220,12 +220,22 @@ store_packet(From, To, Packet) ->
            ok
     end.
 
-check_event(From, To, Packet) ->
+%% Check if the packet has any content about XEP-0022 or XEP-0085
+check_event_chatstates(From, To, Packet) ->
     {xmlelement, Name, Attrs, Els} = Packet,
-    case find_x_event(Els) of
-       false ->
+    case find_x_event_chatstates(Els, {false, false, false}) of
+       %% There wasn't any x:event or chatstates subelements
+       {false, false, _} ->
+           true;
+       %% There a chatstates subelement and other stuff, but no x:event
+       {false, CEl, true} when CEl /= false ->
            true;
-       El ->
+       %% There was only a subelement: a chatstates
+       {false, CEl, false} when CEl /= false ->
+           %% Don't allow offline storage
+           false;
+       %% There was an x:event element, and maybe also other stuff
+       {El, _, _} when El /= false ->
            case xml:get_subtag(El, "id") of
                false ->
                    case xml:get_subtag(El, "offline") of
@@ -247,22 +257,25 @@ check_event(From, To, Packet) ->
                                            {xmlelement, "offline", [], []}]}]
                                        }),
                            true
-                       end;
+                   end;
                _ ->
                    false
            end
     end.
 
-find_x_event([]) ->
-    false;
-find_x_event([{xmlcdata, _} | Els]) ->
-    find_x_event(Els);
-find_x_event([El | Els]) ->
+%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
+find_x_event_chatstates([], Res) ->
+    Res;
+find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
+    find_x_event_chatstates(Els, Res);
+find_x_event_chatstates([El | Els], {A, B, C}) ->
     case xml:get_tag_attr_s("xmlns", El) of
        ?NS_EVENT ->
-           El;
+           find_x_event_chatstates(Els, {El, B, C});
+       ?NS_CHATSTATES ->
+           find_x_event_chatstates(Els, {A, El, C});
        _ ->
-           find_x_event(Els)
+           find_x_event_chatstates(Els, {A, B, true})
     end.
 
 find_x_expire(_, []) ->