@@ -52,6 +52,14 @@ store_session(LUser, LServer, TS, PushJID, Node, XData) ->
5252 PushLJID = jid :tolower (PushJID ),
5353 MaxSessions = ejabberd_sm :get_max_user_sessions (LUser , LServer ),
5454 F = fun () ->
55+ Recs = mnesia :wread ({push_session , US }),
56+ lists :foreach (
57+ fun (# push_session {service = P , node = N } = Rec )
58+ when P == PushLJID , N == Node ->
59+ mnesia :delete_object (Rec );
60+ (_ ) ->
61+ ok
62+ end , Recs ),
5563 enforce_max_sessions (US , MaxSessions ),
5664 mnesia :write (# push_session {us = US ,
5765 timestamp = TS ,
@@ -78,8 +86,13 @@ lookup_session(LUser, LServer, PushJID, Node) ->
7886 N == Node ->
7987 Rec
8088 end ),
81- case mnesia :dirty_select (push_session , MatchSpec ) of
82- [# push_session {timestamp = TS , xml = El }] ->
89+ Records = mnesia :dirty_select (push_session , MatchSpec ),
90+ SortedRecords = lists :sort (fun (# push_session {timestamp = TS1 },
91+ # push_session {timestamp = TS2 }) ->
92+ TS1 >= TS2
93+ end , Records ),
94+ case SortedRecords of
95+ [# push_session {timestamp = TS , xml = El } | _ ] ->
8396 {ok , {TS , PushLJID , Node , decode_xdata (El )}};
8497 [] ->
8598 ? DEBUG (" No push session found for ~ts @~ts (~p , ~ts )" ,
0 commit comments