mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-27 17:28:26 -04:00
Migration of notifications to mailboxer, without sending new emails
This commit is contained in:
1 parent
d76c77d176
commit
083d7c09e6
2 files changed
+24
-2
No files matched your search
@@ -4,6 +4,8 @@ class Notification < ApplicationRecord
|
||||
belongs_to :post, optional: true
|
||||
|
||||
validates :subject, length: { maximum: 255 }
|
||||
validates :subject, presence: true
|
||||
validates :body, presence: true
|
||||
|
||||
scope :unread, -> { where(read: false) }
|
||||
scope :by_recipient, ->(recipient) { where(recipient_id: recipient) }
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
class NotificationsToMailboxer < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
def up
|
||||
Notification.all.each do |n|
|
||||
n.sender.send_message(n.recipient, n.body, n.subject)
|
||||
next unless n.valid?
|
||||
|
||||
conversation = Mailboxer::ConversationBuilder.new(
|
||||
subject: n.subject,
|
||||
created_at: n.created_at,
|
||||
updated_at: n.updated_at
|
||||
).build
|
||||
|
||||
message = Mailboxer::MessageBuilder.new(
|
||||
sender: n.sender,
|
||||
conversation: conversation,
|
||||
recipients: [n.recipient],
|
||||
body: n.body,
|
||||
subject: n.subject,
|
||||
# attachment: attachment,
|
||||
created_at: n.created_at,
|
||||
updated_at: n.updated_at
|
||||
).build
|
||||
|
||||
conversation.save!
|
||||
message.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user