<commit_before>require Logger

defmodule Serverboards.Auth.User do
  import Ecto.Changeset
  import Ecto.Query

  alias Serverboards.MOM
  alias Serverboards.Auth.Model
  alias Serverboards.Repo

  def setup_eventsourcing(es) do
    EventSourcing.subscribe :auth, :add_user, fn attributes, me ->
			{:ok, user} = Repo.insert(%Model.User{
				email: attributes.email,
        first_name: attributes.first_name,
        last_name: attributes.last_name,
        is_active: Map.get(attributes, :is_active, true)
				})
      user = user_info user
      MOM.Channel.send( :client_events, %MOM.Message{ payload: %{ type: "user.added", data: %{ user: user} } } )
    end
    EventSourcing.subscribe :auth, :update_user, fn %{ user: email, operations: operations }, _me ->
      user = Repo.get_by!(Model.User, email: email)
      Repo.update(
        Model.User.changeset(user, operations)
      )
      user = user_info user
      MOM.Channel.send( :client_events, %MOM.Message{ payload: %{ type: "user.updated", data: %{ user: user} } } )
    end
  end<commit_msg>Fix send proper user updated event data.<commit_after>require Logger

defmodule Serverboards.Auth.User do
  import Ecto.Changeset
  import Ecto.Query

  alias Serverboards.MOM
  alias Serverboards.Auth.Model
  alias Serverboards.Repo

  def setup_eventsourcing(es) do
    EventSourcing.subscribe :auth, :add_user, fn attributes, me ->
			{:ok, user} = Repo.insert(%Model.User{
				email: attributes.email,
        first_name: attributes.first_name,
        last_name: attributes.last_name,
        is_active: Map.get(attributes, :is_active, true)
				})
      user = user_info user
      MOM.Channel.send( :client_events, %MOM.Message{ payload: %{ type: "user.added", data: %{ user: user} } } )
    end
    EventSourcing.subscribe :auth, :update_user, fn %{ user: email, operations: operations }, _me ->
      user = Repo.get_by!(Model.User, email: email)
      {:ok, user} = Repo.update(
        Model.User.changeset(user, operations)
      )
      user = user_info user
      MOM.Channel.send( :client_events, %MOM.Message{ payload: %{ type: "user.updated", data: %{ user: user} } } )
    end
  end
{'fraction_non_alphanumeric': 0.1222788327929597, 'fraction_numerical': 0.0, 'mean_word_length': 3.260355029585799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2271563', 'n_tokens_mistral': 730, 'n_tokens_neox': 695, 'n_words': 167}