Feature: User Notification Objects (#752)

Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-05-01 14:53:43 +05:30
committed by GitHub
parent 66aace7c13
commit 96da27f1f6
35 changed files with 461 additions and 110 deletions

View File

@@ -0,0 +1,34 @@
class CreateNotifications < ActiveRecord::Migration[6.0]
def change
create_table :notifications do |t|
t.references :account, index: true, null: false
t.references :user, index: true, null: false
t.integer :notification_type, null: false
t.references :primary_actor, polymorphic: true, null: false, index: { name: 'uniq_primary_actor_per_account_notifications' }
t.references :secondary_actor, polymorphic: true, index: { name: 'uniq_secondary_actor_per_account_notifications' }
t.timestamp :read_at, default: nil
t.timestamps
end
create_table :notification_subscriptions do |t|
t.references :user, index: true, null: false
t.integer :subscription_type, null: false
t.jsonb :subscription_attributes, null: false, default: '{}'
t.timestamps
end
add_column :notification_settings, :push_flags, :integer, default: 0, null: false
add_push_settings_to_users
end
def add_push_settings_to_users
::User.find_in_batches do |users_batch|
users_batch.each do |user|
user_notification_setting = user.notification_settings
user_notification_setting.push_conversation_assignment = true
user_notification_setting.save!
end
end
end
end

View File

@@ -273,9 +273,36 @@ ActiveRecord::Schema.define(version: 2020_04_29_082655) do
t.integer "email_flags", default: 0, null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "push_flags", default: 0, null: false
t.index ["account_id", "user_id"], name: "by_account_user", unique: true
end
create_table "notification_subscriptions", force: :cascade do |t|
t.bigint "user_id", null: false
t.integer "subscription_type", null: false
t.jsonb "subscription_attributes", default: "{}", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_notification_subscriptions_on_user_id"
end
create_table "notifications", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "user_id", null: false
t.integer "notification_type", null: false
t.string "primary_actor_type", null: false
t.bigint "primary_actor_id", null: false
t.string "secondary_actor_type"
t.bigint "secondary_actor_id"
t.datetime "read_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["account_id"], name: "index_notifications_on_account_id"
t.index ["primary_actor_type", "primary_actor_id"], name: "uniq_primary_actor_per_account_notifications"
t.index ["secondary_actor_type", "secondary_actor_id"], name: "uniq_secondary_actor_per_account_notifications"
t.index ["user_id"], name: "index_notifications_on_user_id"
end
create_table "subscriptions", id: :serial, force: :cascade do |t|
t.string "pricing_version"
t.integer "account_id"