feat(chats): tags

This commit is contained in:
Daniel Kempkens 2023-08-21 00:20:42 +02:00
parent f443a5b7ae
commit b301a3a726
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
6 changed files with 43 additions and 13 deletions

1
.gitignore vendored
View file

@ -38,3 +38,4 @@ erl_crash.dump
/tags*
/xref_graph.dot
/xref_graph.png
/scripts

View file

@ -98,6 +98,9 @@
erlang
elixir
postgres
pkgs.ruby_3_2
pkgs.rubyPackages_3_2.nokogiri
] ++ lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
@ -138,6 +141,7 @@
settings = {
environment = {
BDFR_BROWSER_BASE_DIRECTORY = "/Volumes/MediaScraper/Reddit";
BDFR_BROWSER_CONFIG_FILE = "./priv/config.yml";
BDFR_BROWSER_REPO_USER = db-user;
BDFR_BROWSER_REPO_HOST = db-host;
RELEASE_DISTRIBUTION = "none";

View file

@ -9,6 +9,7 @@ defmodule BdfrBrowser.Chat do
schema "chats" do
field :accounts, {:array, :string}
field :tags, {:array, :string}, default: []
has_many :messages, Message
end
@ -16,7 +17,13 @@ defmodule BdfrBrowser.Chat do
def listing do
from(c in __MODULE__,
left_join: m in assoc(c, :messages),
select: %{id: c.id, accounts: c.accounts, num_messages: count(m.id), latest_message: max(m.posted_at)},
select: %{
id: c.id,
accounts: c.accounts,
num_messages: count(m.id),
latest_message: max(m.posted_at),
tags: c.tags
},
order_by: [desc: max(m.posted_at)],
group_by: c.id
)

View file

@ -281,5 +281,6 @@ let
beamDeps = [ yamerl ];
};
};
in self
in
self

View file

@ -0,0 +1,9 @@
defmodule BdfrBrowser.Repo.Migrations.AddChatTags do
use Ecto.Migration
def change do
alter table("chats") do
add :tags, {:array, :string}, default: []
end
end
end

View file

@ -9,6 +9,14 @@
<h6 class="card-subtitle mb-2 text-body-secondary">
<%= chat.num_messages %> message(s) - <%= DateTime.to_iso8601(chat.latest_message) %>
</h6>
<%= if length(chat.tags) > 0 do %>
<p>
<%= for tag <- chat.tags do %>
<span class="badge text-bg-info"><%= tag %></span>
<% end %>
</p>
<% end %>
</div>
</div>
<% end %>