Skip to content

Commit

Permalink
Define mam_send_message behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Apr 27, 2021
1 parent 3a1b896 commit e406ffb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/mam/mam_lookup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ rsm_to_regular_lookup_vars(RSM, Filter, Offset, PageSize) ->
decode_rows(MessageRows, Env) ->
[decode_row(Row, Env) || Row <- MessageRows].

%% First element of the tuple is decoded message ID
-spec decoded_row_to_message_id(mod_mam:message_row()) -> mod_mam:message_id().
decoded_row_to_message_id(#{id := MessId}) -> MessId.

Expand Down
19 changes: 19 additions & 0 deletions src/mam/mam_send_message.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%% Forwards extracted messages to the client.
%% The default implementation is in mod_mam_utils.
-module(mam_send_message).
-export([call_send_message/5]).

-callback send_message(
Row :: mod_mam:message_row(),
ArcJID :: jid:jid(),
From :: jid:jid(),
Packet :: exml:element()) -> Acc :: mongoose_acc:t().

-spec call_send_message(
SendModule :: module(),
Row :: mod_mam:message_row(),
ArcJID :: jid:jid(),
From :: jid:jid(),
Packet :: exml:element()) -> Acc :: mongoose_acc:t().
call_send_message(SendModule, Row, ArcJID, From, Packet) ->
SendModule:send_message(Row, ArcJID, From, Packet).
8 changes: 5 additions & 3 deletions src/mam/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ forward_messages(From, ArcJID, MamNs, QueryID, MessageRows, SetClientNs) ->
{FirstMessID, LastMessID}.

send_message(SendModule, Row, ArcJID, From, Packet) ->
SendModule:send_message(Row, ArcJID, From, Packet).
mam_send_message:call_send_message(SendModule, Row, ArcJID, From, Packet).

-spec handle_get_message_form(jid:jid(), jid:jid(), jlib:iq()) ->
jlib:iq().
Expand Down Expand Up @@ -614,9 +614,11 @@ archive_message(Host, Params) ->

-spec message_row_to_xml(binary(), message_row(), QueryId :: binary(), boolean()) ->
exml:element().
message_row_to_xml(MamNs, #{id := MessID, jid := SrcJID, packet := Packet}, QueryID, SetClientNs) ->
message_row_to_xml(MamNs, #{id := MessID, jid := SrcJID, packet := Packet},
QueryID, SetClientNs) ->
{Microseconds, _NodeMessID} = decode_compact_uuid(MessID),
TS = calendar:system_time_to_rfc3339(erlang:convert_time_unit(Microseconds, microsecond, second), [{offset, "Z"}]),
Secs = erlang:convert_time_unit(Microseconds, microsecond, second),
TS = calendar:system_time_to_rfc3339(Secs, [{offset, "Z"}]),
BExtMessID = mess_id_to_external_binary(MessID),
Packet1 = mod_mam_utils:maybe_set_client_xmlns(SetClientNs, Packet),
wrap_message(MamNs, Packet1, QueryID, BExtMessID, TS, SrcJID).
Expand Down
2 changes: 1 addition & 1 deletion src/mam/mod_mam_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ forward_messages(From, ArcJID, MamNs, QueryID, MessageRows, SetClientNs) ->
{FirstMessID, LastMessID}.

send_message(SendModule, Row, ArcJID, From, Packet) ->
SendModule:send_message(Row, ArcJID, From, Packet).
mam_send_message:call_send_message(SendModule, Row, ArcJID, From, Packet).

-spec handle_get_message_form(jid:jid(), jid:jid(), jlib:iq()) ->
jlib:iq().
Expand Down

0 comments on commit e406ffb

Please sign in to comment.