diff options
author | Jordan Bracco <href@random.sh> | 2022-12-11 01:18:21 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-11 02:03:36 +0000 |
commit | 21ea8d71ff60e55db44c7c94a8e42546f5e5bfa1 (patch) | |
tree | e4f39642db414ff45c31f24b5c38c3963c28557c /lib/irc | |
parent | fix(irc-connection): attempt to find or create/join user in track when receiv... (diff) |
fix(user-track): ensure we only get an user per network even if it's over multiple bot connections
Diffstat (limited to 'lib/irc')
-rw-r--r-- | lib/irc/user_track.ex | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/irc/user_track.ex b/lib/irc/user_track.ex index 3eeaec3..1efa523 100644 --- a/lib/irc/user_track.ex +++ b/lib/irc/user_track.ex @@ -146,7 +146,7 @@ defmodule IRC.UserTrack do def find_by_nick(network, nick) do case :ets.match(@ets, {:"$1", network, :_, String.downcase(nick), :_, :_, :_, :_, :_, :_, :_, :_}) do - [[id]] -> lookup(id) + [[id] | _] -> lookup(id) _ -> nil end @@ -179,10 +179,15 @@ defmodule IRC.UserTrack do # TODO def connected(network, nick, user, host, account_id, opts \\ %{}) do if account = IRC.Account.get(account_id) do - user = %User{id: IRC.UserTrack.Id.large_id, account: account_id, network: network, nick: nick, username: user, host: host, privileges: %{}, options: opts} - Storage.op(fn(ets) -> - :ets.insert(ets, User.to_tuple(user)) - end) + user = if user = find_by_nick(network, nick) do + user + else + user = %User{id: IRC.UserTrack.Id.large_id, account: account_id, network: network, nick: nick, username: user, host: host, privileges: %{}, options: opts} + Storage.op(fn(ets) -> + :ets.insert(ets, User.to_tuple(user)) + end) + user + end IRC.Connection.publish_event(network, %{type: :connect, user_id: user.id, account_id: user.account}) :ok @@ -216,6 +221,8 @@ defmodule IRC.UserTrack do end) IRC.Connection.publish_event({sender.network, channel}, %{type: :join, user_id: user.id, account_id: user.account}) + + user end #def joined(network, channel, nick, privileges) do |