diff options
author | href <href@random.sh> | 2021-09-07 05:27:12 +0200 |
---|---|---|
committer | href <href@random.sh> | 2021-09-07 05:27:12 +0200 |
commit | d3c811cfc7a4796a92b229ae31807160c2a96dc5 (patch) | |
tree | ee75e6c035268b2df39f1b3f2a2d6573258635fc /lib/irc | |
parent | json logger (diff) |
user_track: fix find_by_account/2
Diffstat (limited to 'lib/irc')
-rw-r--r-- | lib/irc/user_track.ex | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/irc/user_track.ex b/lib/irc/user_track.ex index 1b51266..3eeaec3 100644 --- a/lib/irc/user_track.ex +++ b/lib/irc/user_track.ex @@ -81,7 +81,9 @@ defmodule IRC.UserTrack do {:==, :"$2", {:const, id}} ], [:"$_"]} ] - for obj <- :ets.select(@ets, spec), do: User.from_tuple(obj) + results = :ets.select(@ets, spec) + |> Enum.filter(& &1) + for obj <- results, do: User.from_tuple(obj) end def find_by_account(network, nil) do @@ -99,15 +101,16 @@ defmodule IRC.UserTrack do ] case :ets.select(@ets, spec) do results = [_r | _] -> - results - |> Enum.reject(fn({_, net, _, _, _, _, _, _, _, _, actives, opts}) -> net == "matrix" end) - |> Enum.reject(fn({_, net, _, _, _, _, _, _, _, _, actives, opts}) -> net == "telegram" end) - |> Enum.reject(fn({_, _, _, _, _, _, _, _, _, _, actives, opts}) -> Map.get(opts, :puppet) end) + result = results + |> Enum.reject(fn({_, net, _, _, _, _, _, _, _, _, actives, opts}) -> network != "matrix" && net == "matrix" end) + |> Enum.reject(fn({_, net, _, _, _, _, _, _, _, _, actives, opts}) -> network != "telegram" && net == "telegram" end) + |> Enum.reject(fn({_, _, _, _, _, _, _, _, _, _, actives, opts}) -> network not in ["matrix", "telegram"] && Map.get(opts, :puppet) end) |> Enum.sort_by(fn({_, _, _, _, _, _, _, _, _, _, actives, _}) -> Map.get(actives, nil) end, {:desc, NaiveDateTime}) |> List.first - |> User.from_tuple() + + if result, do: User.from_tuple(result) _ -> nil end end |