Skip to content

Commit

Permalink
Merge pull request #3596 from esl/inbox/small_refactor
Browse files Browse the repository at this point in the history
Inbox/small refactor
  • Loading branch information
chrzaszcz authored Mar 18, 2022
2 parents 7d2da37 + 86285b9 commit 7a43c61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/mod_inbox.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
-type get_inbox_res() :: list(inbox_res()).

-type inbox_res() :: #{remote_jid := binary(),
msg := content(),
msg := exml:element(),
unread_count := integer(),
msg_id := id(),
timestamp := integer(),
archive := boolean(),
muted_until := integer()}.
Expand Down
7 changes: 3 additions & 4 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ build_inbox_message(#{msg := Content,
#xmlel{name = <<"message">>, attrs = [{<<"id">>, mod_inbox_utils:wrapper_id()}],
children = [build_result_el(Content, QueryId, Count, Timestamp, Archive, MutedUntil, AccTS)]}.

-spec build_result_el(content(), id(), integer(), integer(), boolean(), integer(), integer()) -> exml:element().
-spec build_result_el(exml:element(), id(), integer(), integer(), boolean(), integer(), integer()) -> exml:element().
build_result_el(Msg, QueryId, Count, Timestamp, Archive, MutedUntil, AccTS) ->
Forwarded = build_forward_el(Msg, Timestamp),
Properties = mod_inbox_entries:extensions_result(Archive, MutedUntil, AccTS),
Expand All @@ -338,12 +338,11 @@ build_result_iq(List) ->
build_result_el(Name, CountBin) ->
#xmlel{name = Name, children = [#xmlcdata{content = CountBin}]}.

-spec build_forward_el(content(), integer()) -> exml:element().
-spec build_forward_el(exml:element(), integer()) -> exml:element().
build_forward_el(Content, Timestamp) ->
{ok, Parsed} = exml:parse(Content),
Delay = build_delay_el(Timestamp),
#xmlel{name = <<"forwarded">>, attrs = [{<<"xmlns">>, ?NS_FORWARD}],
children = [Delay, Parsed]}.
children = [Delay, Content]}.

-spec build_delay_el(Timestamp :: integer()) -> exml:element().
build_delay_el(Timestamp) ->
Expand Down
10 changes: 6 additions & 4 deletions src/inbox/mod_inbox_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
-type db_return() :: {jid:luser(),
msg_content(),
count_bin(),
binary(),
non_neg_integer() | binary(),
archived(),
muted_until()}.
Expand Down Expand Up @@ -260,7 +261,7 @@ lookup_query(#{order := Order} = Params) ->
Conditions = [lookup_sql_condition(Key, maps:get(Key, Params, undefined)) ||
Key <- [start, 'end', hidden_read, archive]],
["SELECT ", MSLimitSQL,
" remote_bare_jid, content, unread_count, timestamp, archive, muted_until "
" remote_bare_jid, content, unread_count, msg_id, timestamp, archive, muted_until "
" FROM inbox WHERE luser = ? AND lserver = ?", Conditions,
" ORDER BY timestamp ", OrderSQL, " ", LimitSQL].

Expand Down Expand Up @@ -419,15 +420,16 @@ execute_delete_domain(HostType, LServer) ->
%% Result processing

-spec decode_row(mongooseim:host_type(), db_return()) -> inbox_res().
decode_row(HostType, {Username, Content, Count, Timestamp, Archive, MutedUntil}) ->
Data = mongoose_rdbms:unescape_binary(HostType, Content),
decode_row(HostType, {Username, Content, Count, MsgId, Timestamp, Archive, MutedUntil}) ->
{ok, Parsed} = exml:parse(mongoose_rdbms:unescape_binary(HostType, Content)),
BCount = mongoose_rdbms:result_to_integer(Count),
NumericTimestamp = mongoose_rdbms:result_to_integer(Timestamp),
BoolArchive = mongoose_rdbms:to_bool(Archive),
NumericMutedUntil = mongoose_rdbms:result_to_integer(MutedUntil),
#{remote_jid => Username,
msg => Data,
msg => Parsed,
unread_count => BCount,
msg_id => MsgId,
timestamp => NumericTimestamp,
archive => BoolArchive,
muted_until => NumericMutedUntil}.
Expand Down

0 comments on commit 7a43c61

Please sign in to comment.