./ct_report/coverage/mod_smart_markers_backend.COVER.html

1 -module(mod_smart_markers_backend).
2
3 -define(MAIN_MODULE, mod_smart_markers).
4
5 -export([init/2]).
6 -export([update_chat_marker/2]).
7 -export([get_conv_chat_marker/6]).
8 -export([get_chat_markers/4]).
9 -export([remove_domain/2]).
10 -export([remove_user/2]).
11 -export([remove_to/2]).
12 -export([remove_to_for_user/3]).
13
14 %%--------------------------------------------------------------------
15 %% DB backend behaviour definition
16 %%--------------------------------------------------------------------
17 -callback init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
18
19 %%% 'domain', from', 'to', 'thread' and 'type' keys of the ChatMarker map serve
20 %%% as a composite database key. If key is not available in the database,
21 %%% then chat marker must be added. Otherwise this function must update
22 %%% chat marker record for that composite key.
23 -callback update_chat_marker(mongooseim:host_type(), mod_smart_markers:chat_marker()) -> ok.
24
25 %%% This function must return the latest chat markers sent to the
26 %%% user/room (with or w/o thread) later than provided timestamp.
27 -callback get_conv_chat_marker(HostType :: mongooseim:host_type(),
28 From :: jid:jid(),
29 To :: jid:jid(),
30 Thread :: mod_smart_markers:maybe_thread(),
31 Timestamp :: integer(),
32 Private :: boolean()) ->
33 [mod_smart_markers:chat_marker()].
34
35 -callback get_chat_markers(HostType :: mongooseim:host_type(),
36 To :: jid:jid(),
37 Thread :: mod_smart_markers:maybe_thread(),
38 Timestamp :: integer()) ->
39 [mod_smart_markers:chat_marker()].
40
41 -callback remove_domain(mongooseim:host_type(), jid:lserver()) -> term().
42
43 -callback remove_user(mongooseim:host_type(), jid:jid()) -> term().
44
45 -callback remove_to(mongooseim:host_type(), jid:jid()) -> term().
46
47 -callback remove_to_for_user(mongooseim:host_type(), From :: jid:jid(), To :: jid:jid()) -> term().
48
49 -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
50 init(HostType, Opts) ->
51 8 TrackedFuns = [get_chat_markers, get_conv_chat_marker, update_chat_marker],
52 8 mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
53 8 Args = [HostType, Opts],
54 8 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
55
56 -spec update_chat_marker(mongooseim:host_type(),
57 mod_smart_markers:chat_marker()) -> ok.
58 update_chat_marker(HostType, ChatMarker) ->
59 49 Args = [HostType, ChatMarker],
60 49 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
61
62 -spec get_conv_chat_marker(HostType :: mongooseim:host_type(),
63 From :: jid:jid(),
64 To :: jid:jid(),
65 Thread :: mod_smart_markers:maybe_thread(),
66 Timestamp :: integer(),
67 Private :: boolean()) -> [mod_smart_markers:chat_marker()].
68 get_conv_chat_marker(HostType, From, To, Thread, TS, Private) ->
69 22 Args = [HostType, From, To, Thread, TS, Private],
70 22 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
71
72 -spec get_chat_markers(HostType :: mongooseim:host_type(),
73 To :: jid:jid(),
74 Thread :: mod_smart_markers:maybe_thread(),
75 Timestamp :: integer()) -> [mod_smart_markers:chat_marker()].
76 get_chat_markers(HostType, To, Thread, TS) ->
77 24 Args = [HostType, To, Thread, TS],
78 24 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
79
80 %% @doc remove all entries for a given domain
81 -spec remove_domain(mongooseim:host_type(), jid:lserver()) -> term().
82 remove_domain(HostType, Domain) ->
83 1 Args = [HostType, Domain],
84 1 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
85
86 %% @doc remove all stored interactions with a given user
87 -spec remove_user(mongooseim:host_type(), jid:jid()) -> term().
88 remove_user(HostType, User) ->
89 66 Args = [HostType, User],
90 66 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
91
92 %% @doc remove all markers a user has ever been sent
93 %% Useful for example for `forget_room', when we need to drop all knowledge
94 %% other users had of this room
95 -spec remove_to(mongooseim:host_type(), jid:jid()) -> term().
96 remove_to(HostType, To) ->
97 4 Args = [HostType, To],
98 4 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
99
100 %% @doc remove markers a user sent to a given other
101 %% Useful for when a user leaves a room, but the room still exists
102 -spec remove_to_for_user(mongooseim:host_type(), From :: jid:jid(), To :: jid:jid()) -> term().
103 remove_to_for_user(HostType, From, To) ->
104 2 Args = [HostType, From, To],
105 2 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
Line Hits Source