diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2016-04-13 09:59:39 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2016-04-13 09:59:39 +0300 |
commit | 7fd4808cdea6d22cd520bbfd1d0e12344fea7092 (patch) | |
tree | 46b6eb2fe391290fd903d1e4b3086aae7a9e5750 /src/mod_last_riak.erl | |
parent | Make it possible to get DB backend of a module (diff) |
Clean mod_last.erl from DB specific code
Diffstat (limited to 'src/mod_last_riak.erl')
-rw-r--r-- | src/mod_last_riak.erl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/mod_last_riak.erl b/src/mod_last_riak.erl new file mode 100644 index 00000000..d25a3a15 --- /dev/null +++ b/src/mod_last_riak.erl @@ -0,0 +1,53 @@ +%%%------------------------------------------------------------------- +%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net> +%%% @copyright (C) 2016, Evgeny Khramtsov +%%% @doc +%%% +%%% @end +%%% Created : 13 Apr 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net> +%%%------------------------------------------------------------------- +-module(mod_last_riak). +-behaviour(mod_last). + +%% API +-export([init/2, import/2, get_last/2, store_last_info/4, remove_user/2]). + +-include("mod_last.hrl"). +-include("logger.hrl"). + +%%%=================================================================== +%%% API +%%%=================================================================== +init(_Host, _Opts) -> + ok. + +get_last(LUser, LServer) -> + case ejabberd_riak:get(last_activity, last_activity_schema(), + {LUser, LServer}) of + {ok, #last_activity{timestamp = TimeStamp, + status = Status}} -> + {ok, TimeStamp, Status}; + {error, notfound} -> + not_found; + Err -> + Err + end. + +store_last_info(LUser, LServer, TimeStamp, Status) -> + US = {LUser, LServer}, + {atomic, ejabberd_riak:put(#last_activity{us = US, + timestamp = TimeStamp, + status = Status}, + last_activity_schema())}. + +remove_user(LUser, LServer) -> + {atomic, ejabberd_riak:delete(last_activity, {LUser, LServer})}. + +import(_LServer, #last_activity{} = LA) -> + ejabberd_riak:put(LA, last_activity_schema()). + +%%%=================================================================== +%%% Internal functions +%%%=================================================================== +last_activity_schema() -> + {record_info(fields, last_activity), #last_activity{}}. |