From 21ea8d71ff60e55db44c7c94a8e42546f5e5bfa1 Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Sun, 11 Dec 2022 01:18:21 +0000 Subject: fix(user-track): ensure we only get an user per network even if it's over multiple bot connections --- lib/irc/user_track.ex | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/irc') 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 -- cgit v1.2.3