aboutsummaryrefslogtreecommitdiff
path: root/src/mod_offline.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2016-11-22 14:48:01 +0100
committerChristophe Romain <christophe.romain@process-one.net>2016-11-22 14:48:01 +0100
commitfbfbb968727617ae9bbeedc9b3d4adb7636ad5da (patch)
treee48dafe80850fe41be32a3ab47f27e6e130b832b /src/mod_offline.erl
parentAdd new xmpp repo as dependency in mix.exs (diff)
Improve ODBC import
Diffstat (limited to '')
-rw-r--r--src/mod_offline.erl39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/mod_offline.erl b/src/mod_offline.erl
index d007bf3c6..241677b2a 100644
--- a/src/mod_offline.erl
+++ b/src/mod_offline.erl
@@ -53,8 +53,9 @@
remove_expired_messages/1,
remove_old_messages/2,
remove_user/2,
- import/1,
- import/3,
+ import_info/0,
+ import_start/2,
+ import/5,
export/1,
get_queue_length/2,
count_offline_messages/2,
@@ -90,7 +91,7 @@
-type us() :: {binary(), binary()}.
-callback init(binary(), gen_mod:opts()) -> any().
--callback import(binary(), #offline_msg{}) -> ok | pass.
+-callback import(#offline_msg{}) -> ok.
-callback store_messages(binary(), us(), [#offline_msg{}],
non_neg_integer(), non_neg_integer()) ->
{atomic, any()}.
@@ -851,13 +852,35 @@ export(LServer) ->
Mod = gen_mod:db_mod(LServer, ?MODULE),
Mod:export(LServer).
-import(LServer) ->
- Mod = gen_mod:db_mod(LServer, ?MODULE),
- Mod:import(LServer).
+import_info() ->
+ [{<<"spool">>, 4}].
-import(LServer, DBType, Data) ->
+import_start(LServer, DBType) ->
+ Mod = gen_mod:db_mod(DBType, ?MODULE),
+ Mod:import(LServer, []).
+
+import(LServer, {sql, _}, DBType, <<"spool">>,
+ [LUser, XML, _Seq, _TimeStamp]) ->
+ El = fxml_stream:parse_element(XML),
+ From = #jid{} = jid:from_string(
+ fxml:get_attr_s(<<"from">>, El#xmlel.attrs)),
+ To = #jid{} = jid:from_string(
+ fxml:get_attr_s(<<"to">>, El#xmlel.attrs)),
+ Stamp = fxml:get_path_s(El, [{elem, <<"delay">>},
+ {attr, <<"stamp">>}]),
+ TS = case jlib:datetime_string_to_timestamp(Stamp) of
+ {MegaSecs, Secs, _} ->
+ {MegaSecs, Secs, 0};
+ undefined ->
+ p1_time_compat:timestamp()
+ end,
+ US = {LUser, LServer},
+ Expire = find_x_expire(TS, El#xmlel.children),
+ Msg = #offline_msg{us = US, packet = El,
+ from = From, to = To,
+ timestamp = TS, expire = Expire},
Mod = gen_mod:db_mod(DBType, ?MODULE),
- Mod:import(LServer, Data).
+ Mod:import(Msg).
mod_opt_type(access_max_user_messages) ->
fun acl:shaper_rules_validator/1;