aboutsummaryrefslogtreecommitdiff
path: root/src/mod_last.erl
diff options
context:
space:
mode:
authorAndreas Köhler <andreas.koehler@1und1.de>2010-11-05 18:38:42 +0100
committerBadlop <badlop@process-one.net>2010-11-10 15:40:04 +0100
commit0c484369c9d8b01d5407450d8741f8ca52ccc442 (patch)
treee8664c88b6d5f5096302903c632e858d1032a27b /src/mod_last.erl
parentRefactor mod_last to use the same core get_last/2 functionality, but keep api... (diff)
In mod_last*:get_last_iq/4, check for user resources first to return 0 seconds if there is one
Fixes problem 2 of EJAB-1158.
Diffstat (limited to 'src/mod_last.erl')
-rw-r--r--src/mod_last.erl29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/mod_last.erl b/src/mod_last.erl
index b5bca2cd4..a4c984dd1 100644
--- a/src/mod_last.erl
+++ b/src/mod_last.erl
@@ -153,19 +153,28 @@ get_last(LUser, LServer) ->
end.
get_last_iq(IQ, SubEl, LUser, LServer) ->
- case get_last(LUser, LServer) of
- {error, _Reason} ->
- IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
- not_found ->
- IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]};
- {ok, TimeStamp, Status} ->
- TimeStamp2 = now_to_seconds(now()),
- Sec = TimeStamp2 - TimeStamp,
+ case ejabberd_sm:get_user_resources(LUser, LServer) of
+ [] ->
+ case get_last(LUser, LServer) of
+ {error, _Reason} ->
+ IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
+ not_found ->
+ IQ#iq{type = error, sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]};
+ {ok, TimeStamp, Status} ->
+ TimeStamp2 = now_to_seconds(now()),
+ Sec = TimeStamp2 - TimeStamp,
+ IQ#iq{type = result,
+ sub_el = [{xmlelement, "query",
+ [{"xmlns", ?NS_LAST},
+ {"seconds", integer_to_list(Sec)}],
+ [{xmlcdata, Status}]}]}
+ end;
+ _ ->
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", ?NS_LAST},
- {"seconds", integer_to_list(Sec)}],
- [{xmlcdata, Status}]}]}
+ {"seconds", "0"}],
+ []}]}
end.
on_presence_update(User, Server, _Resource, Status) ->