mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-15 08:26:26 -05:00
Add notification grouping for follow notifications (#32085)
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
class NotifyService < BaseService
|
||||
include Redisable
|
||||
|
||||
MAXIMUM_GROUP_SPAN_HOURS = 12
|
||||
|
||||
# TODO: the severed_relationships type probably warrants email notifications
|
||||
NON_EMAIL_TYPES = %i(
|
||||
admin.report
|
||||
@@ -216,7 +214,7 @@ class NotifyService < BaseService
|
||||
return if drop?
|
||||
|
||||
@notification.filtered = filter?
|
||||
@notification.group_key = notification_group_key
|
||||
@notification.set_group_key!
|
||||
@notification.save!
|
||||
|
||||
# It's possible the underlying activity has been deleted
|
||||
@@ -236,23 +234,6 @@ class NotifyService < BaseService
|
||||
|
||||
private
|
||||
|
||||
def notification_group_key
|
||||
return nil if @notification.filtered || Notification::GROUPABLE_NOTIFICATION_TYPES.exclude?(@notification.type)
|
||||
|
||||
type_prefix = "#{@notification.type}-#{@notification.target_status.id}"
|
||||
redis_key = "notif-group/#{@recipient.id}/#{type_prefix}"
|
||||
hour_bucket = @notification.activity.created_at.utc.to_i / 1.hour.to_i
|
||||
|
||||
# Reuse previous group if it does not span too large an amount of time
|
||||
previous_bucket = redis.get(redis_key).to_i
|
||||
hour_bucket = previous_bucket if hour_bucket < previous_bucket + MAXIMUM_GROUP_SPAN_HOURS
|
||||
|
||||
# We do not concern ourselves with race conditions since we use hour buckets
|
||||
redis.set(redis_key, hour_bucket, ex: MAXIMUM_GROUP_SPAN_HOURS.hours.to_i)
|
||||
|
||||
"#{type_prefix}-#{hour_bucket}"
|
||||
end
|
||||
|
||||
def drop?
|
||||
DropCondition.new(@notification).drop?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user