Skip to content

Commit

Permalink
chore: add is system message to last read
Browse files Browse the repository at this point in the history
Co-authored-by: ublefo <[email protected]>
Co-authored-by: ugonj <[email protected]>
  • Loading branch information
3 people committed Feb 15, 2023
1 parent 8c5a422 commit 9d80ca4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/messages/last_message_read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ class LastMessageRead < ApplicationRecord

# todo: on update validate that the scope has not changed

# system message doesn't have an associated context object
def is_system_message?
message.context_object.nil?
end

private

def ensure_only_one_per_user_per_scope
# all contexts must be able to return the messages they contain
if is_system_message
if is_system_message?
# System messages do not have a context - only one place where they are read... so only one of these ever for a user
errors.add(:user, "User has already got a last read system message") unless LastMessageRead.where(user: user, context_id: nil).empty?
else
Expand Down

0 comments on commit 9d80ca4

Please sign in to comment.