Add notification policies and notification requests (#29366)
This commit is contained in:
parent
653ce43abe
commit
50b17f7e10
104 changed files with 1096 additions and 247 deletions
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddFilteredToNotifications < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :notifications, :filtered, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
18
db/migrate/20240221195828_create_notification_requests.rb
Normal file
18
db/migrate/20240221195828_create_notification_requests.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateNotificationRequests < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :notification_requests do |t|
|
||||
t.references :account, null: false, foreign_key: { on_delete: :cascade }, index: false
|
||||
t.references :from_account, null: false, foreign_key: { to_table: :accounts, on_delete: :cascade }
|
||||
t.references :last_status, null: false, foreign_key: { to_table: :statuses, on_delete: :nullify }
|
||||
t.bigint :notifications_count, null: false, default: 0
|
||||
t.boolean :dismissed, null: false, default: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :notification_requests, [:account_id, :from_account_id], unique: true
|
||||
add_index :notification_requests, [:account_id, :id], where: 'dismissed = false', order: { id: :desc }
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class NotificationRequestIdsToTimestampIds < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
safety_assured do
|
||||
execute("ALTER TABLE notification_requests ALTER COLUMN id SET DEFAULT timestamp_id('notification_requests')")
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
execute('LOCK notification_requests')
|
||||
execute("SELECT setval('notification_requests_id_seq', (SELECT MAX(id) FROM notification_requests))")
|
||||
execute("ALTER TABLE notification_requests ALTER COLUMN id SET DEFAULT nextval('notification_requests_id_seq')")
|
||||
end
|
||||
end
|
12
db/migrate/20240222193403_create_notification_permissions.rb
Normal file
12
db/migrate/20240222193403_create_notification_permissions.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateNotificationPermissions < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :notification_permissions do |t|
|
||||
t.references :account, null: false, foreign_key: true
|
||||
t.references :from_account, null: false, foreign_key: { to_table: :accounts }
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
15
db/migrate/20240222203722_create_notification_policies.rb
Normal file
15
db/migrate/20240222203722_create_notification_policies.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateNotificationPolicies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :notification_policies do |t|
|
||||
t.references :account, null: false, foreign_key: true, index: { unique: true }
|
||||
t.boolean :filter_not_following, null: false, default: false
|
||||
t.boolean :filter_not_followers, null: false, default: false
|
||||
t.boolean :filter_new_accounts, null: false, default: false
|
||||
t.boolean :filter_private_mentions, null: false, default: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddFilteredIndexOnNotifications < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :notifications, [:account_id, :id, :type], where: 'filtered = false', order: { id: :desc }, name: 'index_notifications_on_filtered', algorithm: :concurrently
|
||||
end
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MigrateInteractionSettingsToPolicy < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
# Dummy classes, to make migration possible across version changes
|
||||
class Account < ApplicationRecord
|
||||
has_one :user, inverse_of: :account
|
||||
has_one :notification_policy, inverse_of: :account
|
||||
end
|
||||
|
||||
class User < ApplicationRecord
|
||||
belongs_to :account
|
||||
end
|
||||
|
||||
class NotificationPolicy < ApplicationRecord
|
||||
belongs_to :account
|
||||
end
|
||||
|
||||
def up
|
||||
User.includes(account: :notification_policy).find_each do |user|
|
||||
deserialized_settings = Oj.load(user.attributes_before_type_cast['settings'])
|
||||
policy = user.account.notification_policy || user.account.build_notification_policy
|
||||
requires_new_policy = false
|
||||
|
||||
if deserialized_settings['interactions.must_be_follower']
|
||||
policy.filter_not_followers = true
|
||||
requires_new_policy = true
|
||||
end
|
||||
|
||||
if deserialized_settings['interactions.must_be_following']
|
||||
policy.filter_not_following = true
|
||||
requires_new_policy = true
|
||||
end
|
||||
|
||||
if deserialized_settings['interactions.must_be_following_dm']
|
||||
policy.filter_private_mentions = true
|
||||
requires_new_policy = true
|
||||
end
|
||||
|
||||
policy.save if requires_new_policy && policy.changed?
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
44
db/schema.rb
44
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_01_11_033014) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_03_04_090449) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -666,6 +666,40 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_11_033014) do
|
|||
t.index ["target_account_id"], name: "index_mutes_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "notification_permissions", force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "from_account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_notification_permissions_on_account_id"
|
||||
t.index ["from_account_id"], name: "index_notification_permissions_on_from_account_id"
|
||||
end
|
||||
|
||||
create_table "notification_policies", force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.boolean "filter_not_following", default: false, null: false
|
||||
t.boolean "filter_not_followers", default: false, null: false
|
||||
t.boolean "filter_new_accounts", default: false, null: false
|
||||
t.boolean "filter_private_mentions", default: true, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_notification_policies_on_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "notification_requests", id: :bigint, default: -> { "timestamp_id('notification_requests'::text)" }, force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "from_account_id", null: false
|
||||
t.bigint "last_status_id", null: false
|
||||
t.bigint "notifications_count", default: 0, null: false
|
||||
t.boolean "dismissed", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id", "from_account_id"], name: "index_notification_requests_on_account_id_and_from_account_id", unique: true
|
||||
t.index ["account_id", "id"], name: "index_notification_requests_on_account_id_and_id", order: { id: :desc }, where: "(dismissed = false)"
|
||||
t.index ["from_account_id"], name: "index_notification_requests_on_from_account_id"
|
||||
t.index ["last_status_id"], name: "index_notification_requests_on_last_status_id"
|
||||
end
|
||||
|
||||
create_table "notifications", force: :cascade do |t|
|
||||
t.bigint "activity_id", null: false
|
||||
t.string "activity_type", null: false
|
||||
|
@ -674,7 +708,9 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_11_033014) do
|
|||
t.bigint "account_id", null: false
|
||||
t.bigint "from_account_id", null: false
|
||||
t.string "type"
|
||||
t.boolean "filtered", default: false, null: false
|
||||
t.index ["account_id", "id", "type"], name: "index_notifications_on_account_id_and_id_and_type", order: { id: :desc }
|
||||
t.index ["account_id", "id", "type"], name: "index_notifications_on_filtered", order: { id: :desc }, where: "(filtered = false)"
|
||||
t.index ["activity_id", "activity_type"], name: "index_notifications_on_activity_id_and_activity_type"
|
||||
t.index ["from_account_id"], name: "index_notifications_on_from_account_id"
|
||||
end
|
||||
|
@ -1255,6 +1291,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_11_033014) do
|
|||
add_foreign_key "mentions", "statuses", on_delete: :cascade
|
||||
add_foreign_key "mutes", "accounts", column: "target_account_id", name: "fk_eecff219ea", on_delete: :cascade
|
||||
add_foreign_key "mutes", "accounts", name: "fk_b8d8daf315", on_delete: :cascade
|
||||
add_foreign_key "notification_permissions", "accounts"
|
||||
add_foreign_key "notification_permissions", "accounts", column: "from_account_id"
|
||||
add_foreign_key "notification_policies", "accounts"
|
||||
add_foreign_key "notification_requests", "accounts", column: "from_account_id", on_delete: :cascade
|
||||
add_foreign_key "notification_requests", "accounts", on_delete: :cascade
|
||||
add_foreign_key "notification_requests", "statuses", column: "last_status_id", on_delete: :nullify
|
||||
add_foreign_key "notifications", "accounts", column: "from_account_id", name: "fk_fbd6b0bf9e", on_delete: :cascade
|
||||
add_foreign_key "notifications", "accounts", name: "fk_c141c8ee55", on_delete: :cascade
|
||||
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id", name: "fk_34d54b0a33", on_delete: :cascade
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue