<commit_before>%% @doc Process which receives messages from users and delivers them to channels.
%% @version 0.1.0
%% @author <NAME> <<EMAIL>>
%%   [http://student.vub.ac.be/~dmeysman]
%% @copyright 2016 <NAME>
-module(receiver).

-export([initialize/0, initialize_with/1, receiver_actor/1]).

initialize() ->
  initialize_with(dict:new()).

initialize_with(Channels) ->
  spawn_link(?MODULE, receiver_actor, [Channels]).

-spec receiver_actor(Channels :: dict:dict(string(), pid())) -> any().
receiver_actor(Channels) ->
  receive
    {Sender, log_out, UserName} ->
      % We delegate the work to the registered master process.
      master_actor ! {Sender, log_out, UserName};
      % We do not proceed, as there is no longer any use for us.

    {Sender, send_message, UserName, ChannelName, MessageText, SentTime} ->
      % We ask the channel to broadcast the message by fetching its pid through its name.
      dict:fetch(ChannelName, Channels) ! {self(), broadcast, {message, UserName, ChannelName, MessageText, SentTime}},
      Sender ! {self(), message_sent},
      receiver_actor(Channels);

    {Sender, join_channel, UserName, ChannelName} ->
      master_actor ! {Sender, self(), join_channel, UserName, ChannelName},
      receiver_actor(Channels);

    {Sender, get_channel_history, ChannelName} ->
      % We delegate the history retrieval to the channel process by fetching its pid through its name.
      dict:fetch(ChannelName, Channels) ! {Sender, get_channel_history};

    {_, new_channel, {channel, ChannelName, ChannelPid}} ->
      % We proceed with the new state.
      receiver_actor(dict:store(ChannelName, ChannelPid, Channels))
  end.<commit_msg>Always make a receiver process proceed recursively<commit_after>%% @doc Process which receives messages from users and delivers them to channels.
%% @version 0.1.0
%% @author <NAME> <<EMAIL>>
%%   [http://student.vub.ac.be/~dmeysman]
%% @copyright 2016 <NAME>
-module(receiver).

-export([initialize/0, initialize_with/1, receiver_actor/1]).

initialize() ->
  initialize_with(dict:new()).

initialize_with(Channels) ->
  spawn_link(?MODULE, receiver_actor, [Channels]).

-spec receiver_actor(Channels :: dict:dict(string(), pid())) -> any().
receiver_actor(Channels) ->
  receive
    {Sender, log_out, UserName} ->
      % We delegate the work to the registered master process.
      master_actor ! {Sender, log_out, UserName};
      % We do not proceed, as there is no longer any use for us.

    {Sender, send_message, UserName, ChannelName, MessageText, SentTime} ->
      % We ask the channel to broadcast the message by fetching its pid through its name.
      dict:fetch(ChannelName, Channels) ! {self(), broadcast, {message, UserName, ChannelName, MessageText, SentTime}},
      Sender ! {self(), message_sent},
      receiver_actor(Channels);

    {Sender, join_channel, UserName, ChannelName} ->
      master_actor ! {Sender, self(), join_channel, UserName, ChannelName},
      receiver_actor(Channels);

    {Sender, get_channel_history, ChannelName} ->
      % We delegate the history retrieval to the channel process by fetching its pid through its name.
      dict:fetch(ChannelName, Channels) ! {Sender, get_channel_history},
      receiver_actor(Channels);

    {_, new_channel, {channel, ChannelName, ChannelPid}} ->
      % We proceed with the new state.
      receiver_actor(dict:store(ChannelName, ChannelPid, Channels))
  end.
{'fraction_non_alphanumeric': 0.1235036496350365, 'fraction_numerical': 0.00583941605839416, 'mean_word_length': 4.159638554216867, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3257556', 'n_tokens_mistral': 1023, 'n_tokens_neox': 998, 'n_words': 306}