Server side code for Watching First Post Only

This commit is contained in:
Robin Ward
2016-07-06 15:56:40 -04:00
parent 1eb64151f6
commit 2005565c9c
13 changed files with 112 additions and 39 deletions

View File

@@ -17,6 +17,7 @@ class Category < ActiveRecord::Base
belongs_to :latest_post, class_name: "Post"
has_many :topics
has_many :category_users
has_many :category_featured_topics
has_many :featured_topics, through: :category_featured_topics, source: :topic

View File

@@ -1,3 +1,5 @@
require_dependency 'notification_levels'
class CategoryUser < ActiveRecord::Base
belongs_to :category
belongs_to :user
@@ -11,11 +13,7 @@ class CategoryUser < ActiveRecord::Base
end
def self.notification_levels
@notification_levels ||= Enum.new(muted: 0,
regular: 1,
tracking: 2,
watching: 3,
watching_first_post: 4)
NotificationLevels.all
end
def self.watching_levels

View File

@@ -1,3 +1,5 @@
require_dependency 'notification_levels'
class GroupUser < ActiveRecord::Base
belongs_to :group, counter_cache: "user_count"
belongs_to :user
@@ -10,6 +12,10 @@ class GroupUser < ActiveRecord::Base
after_save :grant_trust_level
def self.notification_levels
NotificationLevels.all
end
protected
def set_primary_group

View File

@@ -42,7 +42,8 @@ class Notification < ActiveRecord::Base
invited_to_topic: 13,
custom: 14,
group_mentioned: 15,
group_message_summary: 16
group_message_summary: 16,
watching_first_post: 17
)
end
@@ -107,11 +108,6 @@ class Notification < ActiveRecord::Base
end
end
def text_description
link = block_given? ? yield : ""
I18n.t("notification_types.#{Notification.types[notification_type]}", data_hash.merge(link: link))
end
def url
topic.relative_url(post_number) if topic.present?
end

View File

@@ -1,9 +1,11 @@
require_dependency 'notification_levels'
class TagUser < ActiveRecord::Base
belongs_to :tag
belongs_to :user
def self.notification_levels
TopicUser.notification_levels
NotificationLevels.all
end
def self.change(user_id, tag_id, level)

View File

@@ -79,6 +79,7 @@ class Topic < ActiveRecord::Base
end
belongs_to :category
has_many :category_users, through: :category
has_many :posts
has_many :ordered_posts, -> { order(post_number: :asc) }, class_name: "Post"
has_many :topic_allowed_users
@@ -94,6 +95,7 @@ class Topic < ActiveRecord::Base
has_many :topic_tags, dependent: :destroy
has_many :tags, through: :topic_tags
has_many :tag_users, through: :tags
has_one :top_topic
belongs_to :user

View File

@@ -1,3 +1,5 @@
require_dependency 'notification_levels'
class TopicUser < ActiveRecord::Base
belongs_to :user
belongs_to :topic
@@ -17,10 +19,7 @@ class TopicUser < ActiveRecord::Base
# Enums
def notification_levels
@notification_levels ||= Enum.new(muted: 0,
regular: 1,
tracking: 2,
watching: 3)
NotificationLevels.topic_levels
end
def notification_reasons