Skip to content

Commit

Permalink
improvement: put back old forum posts & data
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 16, 2023
1 parent db5b940 commit cf675ed
Show file tree
Hide file tree
Showing 14 changed files with 776 additions and 155 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ config :ash_hq,
AshHq.Blog,
AshHq.Docs,
AshHq.Github,
AshHq.MailingList
AshHq.MailingList,
AshHq.Discord
]

config :ash_hq, AshHq.Repo,
Expand Down
14 changes: 14 additions & 0 deletions lib/ash_hq/discord/discord.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule AshHq.Discord do
@moduledoc "Discord api import & interactions"
use Ash.Api

resources do
resource AshHq.Discord.Attachment
resource AshHq.Discord.Channel
resource AshHq.Discord.Message
resource AshHq.Discord.Reaction
resource AshHq.Discord.Tag
resource AshHq.Discord.Thread
resource AshHq.Discord.ThreadTag
end
end
138 changes: 0 additions & 138 deletions lib/ash_hq/discord/listener.ex

This file was deleted.

35 changes: 35 additions & 0 deletions lib/ash_hq/discord/resources/attachment.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule AshHq.Discord.Attachment do
@moduledoc "A discord attachment on a message"
use Ash.Resource,
data_layer: AshPostgres.DataLayer

actions do
defaults [:create, :read, :update, :destroy]
end

attributes do
integer_primary_key :id, generated?: false, writable?: true
attribute :filename, :string
attribute :size, :integer
attribute :url, :string
attribute :proxy_url, :string
attribute :height, :integer
attribute :width, :integer
end

relationships do
belongs_to :message, AshHq.Discord.Message do
allow_nil? false
attribute_type :integer
end
end

postgres do
table "discord_attachments"
repo AshHq.Repo

references do
reference :message, on_delete: :delete, on_update: :update
end
end
end
43 changes: 43 additions & 0 deletions lib/ash_hq/discord/resources/channel.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule AshHq.Discord.Channel do
@moduledoc """
The channel is the discord forum channel. We explicitly configure which ones we import.
"""

use Ash.Resource,
data_layer: AshPostgres.DataLayer

actions do
defaults [:create, :read, :update, :destroy]

create :upsert do
upsert? true
end
end

attributes do
integer_primary_key :id, writable?: true, generated?: false

attribute :name, :string do
allow_nil? false
end

attribute :order, :integer do
allow_nil? false
end
end

relationships do
has_many :threads, AshHq.Discord.Thread
end

postgres do
table "discord_channels"
repo AshHq.Repo
end

code_interface do
define_for AshHq.Discord
define :read
define :upsert
end
end
96 changes: 96 additions & 0 deletions lib/ash_hq/discord/resources/message.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
defmodule AshHq.Discord.Message do
@moduledoc """
Discord messages synchronized by the discord bot
"""
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [
AshHq.Docs.Extensions.RenderMarkdown,
AshHq.Docs.Extensions.Search
]

actions do
defaults [:read, :destroy]

create :create do
primary? true
argument :attachments, {:array, :map}
argument :reactions, {:array, :map}
change manage_relationship(:attachments, type: :direct_control)

change manage_relationship(:reactions,
type: :direct_control,
use_identities: [:unique_message_emoji]
)
end

update :update do
primary? true
argument :attachments, {:array, :map}
argument :reactions, {:array, :map}
change manage_relationship(:attachments, type: :direct_control)

change manage_relationship(:reactions,
type: :direct_control,
use_identities: [:unique_message_emoji]
)
end
end

render_markdown do
render_attributes content: :content_html
end

search do
doc_attribute :content

type "Forum"

load_for_search [
:channel_name,
:thread_name
]

has_name_attribute? false
weight_content(-0.7)
end

attributes do
integer_primary_key :id, generated?: false, writable?: true

attribute :author, :string do
allow_nil? false
end

attribute :content, :string
attribute :content_html, :string

attribute :timestamp, :utc_datetime do
allow_nil? false
end
end

relationships do
belongs_to :thread, AshHq.Discord.Thread do
attribute_type :integer
allow_nil? false
end

has_many :attachments, AshHq.Discord.Attachment
has_many :reactions, AshHq.Discord.Reaction
end

postgres do
table "discord_messages"
repo AshHq.Repo

references do
reference :thread, on_delete: :delete, on_update: :update
end
end

aggregates do
first :channel_name, [:thread, :channel], :name
first :thread_name, [:thread], :name
end
end
43 changes: 43 additions & 0 deletions lib/ash_hq/discord/resources/reaction.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule AshHq.Discord.Reaction do
@moduledoc """
Reactions store emoji reaction counts.
"""
use Ash.Resource,
data_layer: AshPostgres.DataLayer

actions do
defaults [:create, :read, :update, :destroy]
end

attributes do
uuid_primary_key :id

attribute :count, :integer do
allow_nil? false
end

attribute :emoji, :string do
allow_nil? false
end
end

relationships do
belongs_to :message, AshHq.Discord.Message do
attribute_type :integer
allow_nil? false
end
end

postgres do
table "discord_reactions"
repo AshHq.Repo

references do
reference :message, on_delete: :delete, on_update: :update
end
end

identities do
identity :unique_message_emoji, [:emoji, :message_id]
end
end
Loading

0 comments on commit cf675ed

Please sign in to comment.