./ct_report/coverage/mam_decoder.COVER.html

1 -module(mam_decoder).
2 -export([decode_row/2]).
3 -export([decode_muc_row/2]).
4 -export([decode_muc_gdpr_row/2]).
5 -export([decode_retraction_info/3]).
6
7 -type ext_mess_id() :: non_neg_integer() | binary().
8 -type env_vars() :: mod_mam_rdbms_arch:env_vars().
9 -type db_row() :: {ext_mess_id(), ExtSrcJID :: binary(), ExtData :: binary()}.
10 -type db_muc_row() :: {ext_mess_id(), Nick :: binary(), ExtData :: binary()}.
11 -type db_muc_gdpr_row() :: {ext_mess_id(), ExtData :: binary()}.
12 -type decoded_muc_gdpr_row() :: {ext_mess_id(), exml:element()}.
13
14 -spec decode_row(db_row(), env_vars()) -> mod_mam:message_row().
15 decode_row({ExtMessID, ExtSrcJID, ExtData}, Env) ->
16 2898 MessID = mongoose_rdbms:result_to_integer(ExtMessID),
17 2898 SrcJID = decode_jid(ExtSrcJID, Env),
18 2898 Packet = decode_packet(ExtData, Env),
19 2898 #{id => MessID, jid => SrcJID, packet => Packet}.
20
21 -spec decode_muc_row(db_muc_row(), env_vars()) -> mod_mam:message_row().
22 decode_muc_row({ExtMessID, Nick, ExtData}, Env = #{archive_jid := RoomJID}) ->
23 1633 MessID = mongoose_rdbms:result_to_integer(ExtMessID),
24 1633 SrcJID = jid:replace_resource(RoomJID, Nick),
25 1633 Packet = decode_packet(ExtData, Env),
26 1633 #{id => MessID, jid => SrcJID, packet => Packet}.
27
28 -spec decode_muc_gdpr_row(db_muc_gdpr_row(), env_vars()) -> decoded_muc_gdpr_row().
29 decode_muc_gdpr_row({ExtMessID, ExtData}, Env) ->
30 13 Packet = decode_packet(ExtData, Env),
31 13 {ExtMessID, Packet}.
32
33 -spec decode_retraction_info(env_vars(),
34 [{binary(), mod_mam:message_id(), binary()}],
35 mod_mam_utils:retraction_id()) ->
36 skip | mod_mam_utils:retraction_info().
37 21 decode_retraction_info(_Env, [], _) -> skip;
38 decode_retraction_info(Env, [{ResMessID, Data}], {origin_id, OriginID}) ->
39 21 Packet = decode_packet(Data, Env),
40 21 MessID = mongoose_rdbms:result_to_integer(ResMessID),
41 21 #{retract_on => origin_id, packet => Packet, message_id => MessID, origin_id => OriginID};
42 decode_retraction_info(Env, [{OriginID, Data}], {stanza_id, StanzaID}) ->
43 21 Packet = decode_packet(Data, Env),
44 21 MessID = mod_mam_utils:external_binary_to_mess_id(StanzaID),
45 21 #{retract_on => stanza_id, packet => Packet, message_id => MessID, origin_id => OriginID}.
46
47 -spec decode_jid(binary(), env_vars()) -> jid:jid().
48 decode_jid(ExtJID, #{db_jid_codec := Codec, archive_jid := ArcJID}) ->
49 2898 mam_jid:decode(Codec, ArcJID, ExtJID).
50
51 -spec decode_packet(binary(), env_vars()) -> exml:element().
52 decode_packet(ExtBin, Env = #{db_message_codec := Codec}) ->
53 4586 Bin = unescape_binary(ExtBin, Env),
54 4586 mam_message:decode(Codec, Bin).
55
56 -spec unescape_binary(binary(), env_vars()) -> binary().
57 unescape_binary(Bin, #{host_type := HostType}) ->
58 4586 mongoose_rdbms:unescape_binary(HostType, Bin).
Line Hits Source