From 65190422c4d30cadc5959ad8e6627e37a6ce9ffb Mon Sep 17 00:00:00 2001 From: Nic Hippenmeyer Date: Thu, 27 Jul 2023 05:29:21 -0400 Subject: [PATCH] fix: Rename `unread_since` scope (#7267) - This renames the unread_since scope to created_since, which more accurately describes what the scope returns. - The EXTRACT(EPOCH FROM created_at) > (?) clause was also simplified and rewritten as created_at > ?, which is equivalent: --- app/models/conversation.rb | 4 ++-- app/models/message.rb | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 25fa48c0d..b175961c1 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -166,11 +166,11 @@ class Conversation < ApplicationRecord end def unread_messages - messages.unread_since(agent_last_seen_at) + messages.created_since(agent_last_seen_at) end def unread_incoming_messages - messages.incoming.unread_since(agent_last_seen_at) + messages.incoming.created_since(agent_last_seen_at) end def push_event_data diff --git a/app/models/message.rb b/app/models/message.rb index 3680ed589..dda5b51d5 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -103,8 +103,7 @@ class Message < ApplicationRecord store :external_source_ids, accessors: [:slack], coder: JSON, prefix: :external_source_id - # .succ is a hack to avoid https://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be - scope :unread_since, ->(datetime) { where('EXTRACT(EPOCH FROM created_at) > (?)', datetime.to_i.succ) } + scope :created_since, ->(datetime) { where('created_at > ?', datetime) } scope :chat, -> { where.not(message_type: :activity).where(private: false) } scope :non_activity_messages, -> { where.not(message_type: :activity).reorder('id desc') } scope :today, -> { where("date_trunc('day', created_at) = ?", Date.current) }