diff --git a/app/jobs/signal_adapter/receive_polling_job.rb b/app/jobs/signal_adapter/receive_polling_job.rb index 7161fba6f..30d918ce5 100644 --- a/app/jobs/signal_adapter/receive_polling_job.rb +++ b/app/jobs/signal_adapter/receive_polling_job.rb @@ -30,9 +30,7 @@ def perform(*_args) end adapter.on(SignalAdapter::HANDLE_DELIVERY_RECEIPT) do |delivery_receipt, contributor| - if delivery_receipt[:isDelivery] - contributor.received_messages.first.update(received_at: Time.zone.at(delivery_receipt[:when]).to_datetime) - end + handle_delivery_receipt(delivery_receipt, contributor) end signal_messages.each do |raw_message| @@ -70,5 +68,12 @@ def handle_connect(contributor) SignalAdapter::Outbound.send_welcome_message!(contributor) SignalAdapter::AttachContributorsAvatarJob.perform_later(contributor) end + + def handle_delivery_receipt(delivery_receipt, contributor) + datetime = Time.zone.at(delivery_receipt[:when] / 1000).to_datetime + latest_received_message = contributor.received_messages.first + latest_received_message.update(received_at: datetime) if delivery_receipt[:isDelivery] + latest_received_message.update(read_at: datetime) if delivery_receipt[:isRead] + end end end diff --git a/db/migrate/20231024144124_add_read_at_to_messages.rb b/db/migrate/20231024144124_add_read_at_to_messages.rb new file mode 100644 index 000000000..5dbf6a6ad --- /dev/null +++ b/db/migrate/20231024144124_add_read_at_to_messages.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddReadAtToMessages < ActiveRecord::Migration[6.1] + def change + add_column :messages, :read_at, :datetime, default: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 339d795f7..74b98d80a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_09_15_070544) do +ActiveRecord::Schema.define(version: 2023_10_24_144124) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -170,6 +170,7 @@ t.bigint "creator_id" t.string "sender_type" t.datetime "received_at" + t.datetime "read_at" t.index ["creator_id"], name: "index_messages_on_creator_id" t.index ["recipient_id"], name: "index_messages_on_recipient_id" t.index ["request_id"], name: "index_messages_on_request_id"