-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: put back old forum posts & data
- Loading branch information
1 parent
db5b940
commit cf675ed
Showing
14 changed files
with
776 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.