group unread count
This commit is contained in:
@@ -9,6 +9,8 @@ class Api::V1::Timelines::GroupController < Api::BaseController
|
||||
after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
|
||||
|
||||
def show
|
||||
mark_as_unread
|
||||
|
||||
render json: @statuses,
|
||||
each_serializer: REST::StatusSerializer,
|
||||
relationships: StatusRelationshipsPresenter.new(@statuses, current_user.account_id)
|
||||
@@ -16,6 +18,10 @@ class Api::V1::Timelines::GroupController < Api::BaseController
|
||||
|
||||
private
|
||||
|
||||
def mark_as_unread
|
||||
GroupAccount.where(group: @group, account: current_account).update_all("unread_count = 0")
|
||||
end
|
||||
|
||||
def set_group
|
||||
@group = Group.find(params[:id])
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# role :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# unread_count :integer default(0)
|
||||
#
|
||||
|
||||
class GroupAccount < ApplicationRecord
|
||||
|
||||
@@ -256,6 +256,7 @@ class Status < ApplicationRecord
|
||||
|
||||
after_create_commit :store_uri, if: :local?
|
||||
after_create_commit :update_statistics, if: :local?
|
||||
after_create_commit :increase_group_unread_counts, if: Proc.new { |status| !status.group_id.nil? }
|
||||
|
||||
around_create GabSocial::Snowflake::Callbacks
|
||||
|
||||
@@ -535,4 +536,8 @@ class Status < ApplicationRecord
|
||||
AccountConversation.remove_status(inbox_owner, self)
|
||||
end
|
||||
end
|
||||
|
||||
def increase_group_unread_counts
|
||||
GroupAccount.where(group_id: group_id).where.not(account_id: account_id).update_all("unread_count = unread_count + 1")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user