Add conversations API (#8832)
* Add conversations API * Add web UI for conversations * Add test for conversations API * Add tests for ConversationAccount * Improve web UI * Rename ConversationAccount to AccountConversation * Remove conversations on block and mute * Change last_status_id to be a denormalization of status_ids * Add optimistic locking
This commit is contained in:
parent
25744d43b0
commit
774ac47373
33 changed files with 816 additions and 44 deletions
|
@ -8,9 +8,10 @@ class NotifyService < BaseService
|
|||
|
||||
return if recipient.user.nil? || blocked?
|
||||
|
||||
create_notification
|
||||
push_notification if @notification.browserable?
|
||||
send_email if email_enabled?
|
||||
create_notification!
|
||||
push_notification! if @notification.browserable?
|
||||
push_to_conversation! if direct_message?
|
||||
send_email! if email_enabled?
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
return
|
||||
end
|
||||
|
@ -100,18 +101,23 @@ class NotifyService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def create_notification
|
||||
def create_notification!
|
||||
@notification.save!
|
||||
end
|
||||
|
||||
def push_notification
|
||||
def push_notification!
|
||||
return if @notification.activity.nil?
|
||||
|
||||
Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, :notification)))
|
||||
send_push_notifications
|
||||
send_push_notifications!
|
||||
end
|
||||
|
||||
def send_push_notifications
|
||||
def push_to_conversation!
|
||||
return if @notification.activity.nil?
|
||||
AccountConversation.add_status(@recipient, @notification.target_status)
|
||||
end
|
||||
|
||||
def send_push_notifications!
|
||||
subscriptions_ids = ::Web::PushSubscription.where(user_id: @recipient.user.id)
|
||||
.select { |subscription| subscription.pushable?(@notification) }
|
||||
.map(&:id)
|
||||
|
@ -121,7 +127,7 @@ class NotifyService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def send_email
|
||||
def send_email!
|
||||
return if @notification.activity.nil?
|
||||
NotificationMailer.public_send(@notification.type, @recipient, @notification).deliver_later(wait: 2.minutes)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue