From 44d8cd0f63b5fbdf5e4810480953de8b3be46f10 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 11 Aug 2019 16:55:15 +1200 Subject: [PATCH] Copy timestamps from Notifications to Conversations --- db/migrate/20190720000625_notifications_to_mailboxer.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/db/migrate/20190720000625_notifications_to_mailboxer.rb b/db/migrate/20190720000625_notifications_to_mailboxer.rb index e0aaff0b5..cd92baca6 100644 --- a/db/migrate/20190720000625_notifications_to_mailboxer.rb +++ b/db/migrate/20190720000625_notifications_to_mailboxer.rb @@ -8,9 +8,12 @@ class NotificationsToMailboxer < ActiveRecord::Migration[5.2] group.each do |n| n.body = 'message has no body' if n.body.blank? receipt = n.send_message - next unless n.read - - receipt.conversation.receipts.each(&:mark_as_read) + # Copy over which messages are read + receipt.conversation.receipts.each(&:mark_as_read) if n.read + # copy over timestamps + receipt.conversation.messages.each do |msg| + msg.update!(created_at: n.created_at, updated_at: n.updated_at) + end end end end