Skip to content

Commit

Permalink
Extract helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
gustawlippa committed Dec 6, 2024
1 parent 16f4aa3 commit 4415dbe
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/stream_management/mod_stream_management.erl
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,7 @@ reroute_buffer(StateData, #sm_state{buffer = Buffer}) ->
mongoose_c2s:reroute_buffer(StateData, Buffer).

add_delay_elements_to_buffer(#sm_state{buffer = Buffer} = SmState, FromServer) ->
BufferWithDelays = [begin
TS = mongoose_acc:timestamp(Acc),
StanzaName = mongoose_acc:stanza_name(Acc),
StanzaType = mongoose_acc:stanza_type(Acc),
{From, To, El} = mongoose_acc:packet(Acc),
ElWithDelay = maybe_add_timestamp(El, StanzaName, StanzaType, TS, FromServer),
AccParams = #{from_jid => From, to_jid => To, element => ElWithDelay},
mongoose_acc:update_stanza(AccParams, Acc)
end || Acc <- Buffer],
BufferWithDelays = [maybe_add_timestamp(Acc, FromServer) || Acc <- Buffer],
SmState#sm_state{buffer = BufferWithDelays}.

-spec terminate(term(), c2s_state(), mongoose_c2s:data()) -> term().
Expand Down Expand Up @@ -629,14 +621,20 @@ get_all_stanzas_to_forward(StateData, SMID) ->
LServer = mongoose_c2s:get_lserver(StateData),
FromServer = jid:make_noprep(<<>>, LServer, <<>>),
ToForward = [ begin
TS = mongoose_acc:timestamp(Acc),
Packet = mongoose_acc:element(Acc),
StanzaName = mongoose_acc:stanza_name(Acc),
StanzaType = mongoose_acc:stanza_type(Acc),
maybe_add_timestamp(Packet, StanzaName, StanzaType, TS, FromServer)
AccWithTS = maybe_add_timestamp(Acc, FromServer),
mongoose_acc:element(AccWithTS)

Check warning on line 625 in src/stream_management/mod_stream_management.erl

View check run for this annotation

Codecov / codecov/patch

src/stream_management/mod_stream_management.erl#L624-L625

Added lines #L624 - L625 were not covered by tests
end || Acc <- lists:reverse(Buffer)],
{Resumed, ToForward}.

maybe_add_timestamp(Acc, FromServer) ->
TS = mongoose_acc:timestamp(Acc),
StanzaName = mongoose_acc:stanza_name(Acc),
StanzaType = mongoose_acc:stanza_type(Acc),
{From, To, El} = mongoose_acc:packet(Acc),
ElWithDelay = maybe_add_timestamp(El, StanzaName, StanzaType, TS, FromServer),
AccParams = #{from_jid => From, to_jid => To, element => ElWithDelay},
mongoose_acc:update_stanza(AccParams, Acc).

maybe_add_timestamp(Packet, <<"message">>, <<"error">>, _, _) ->
Packet;
maybe_add_timestamp(Packet, <<"message">>, <<"headline">>, _, _) ->
Expand Down

0 comments on commit 4415dbe

Please sign in to comment.