Skip to content

Commit

Permalink
Mark only new significant inbox messages unread & mark their threads …
Browse files Browse the repository at this point in the history
…with InboxTag
  • Loading branch information
luciajanikova committed Feb 5, 2025
1 parent 7437ec3 commit 8031370
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/jobs/add_inbox_tag_to_thread_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddInboxTagToThreadJob < ApplicationJob
def perform(message_thread)
message_thread.assign_tag(message_thread.tenant.inbox_tag) if message_thread.messages.any?{ |message| significant_inbox_message?(message) }
end

private

def significant_inbox_message?(message)
!message.outbox? && !Govbox::Message::INFORMATIONAL_MESSAGE_CLASSES.include?(message.metadata.dig('edesk_class'))
end
end
5 changes: 5 additions & 0 deletions app/jobs/add_inbox_tag_to_threads_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInboxTagToThreadsJob < ApplicationJob
def perform
MessageThread.find_each { |message_thread| AddInboxTagToThreadJob.perform_later(message_thread) }
end
end
14 changes: 12 additions & 2 deletions app/models/govbox/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Govbox::Message < ApplicationRecord

EGOV_DOCUMENT_CLASS = 'EGOV_DOCUMENT'
EGOV_NOTIFICATION_CLASS = 'EGOV_NOTIFICATION'
COLLAPSED_BY_DEFAULT_MESSAGE_CLASSES = ['ED_DELIVERY_REPORT', 'POSTING_CONFIRMATION', 'POSTING_INFORMATION']
INFORMATIONAL_MESSAGE_CLASSES = ['ED_DELIVERY_REPORT', 'POSTING_CONFIRMATION', 'POSTING_INFORMATION']
GENERAL_AGENDA_SCHEMA = 'http://schemas.gov.sk/form/App.GeneralAgenda/1.9'

DELIVERY_NOTIFICATION_TAG = 'delivery_notification'
Expand All @@ -39,6 +39,7 @@ def self.create_message_with_thread!(govbox_message)
title: message.metadata.dig("delivery_notification", "consignment", "subject").presence || message.title,
delivered_at: govbox_message.delivered_at
)
message.thread.assign_tag(message.thread.tenant.inbox_tag) if !message.outbox? && !govbox_message.insignificant?

message.save!

Expand Down Expand Up @@ -66,7 +67,15 @@ def replyable?
end

def collapsed?
payload["class"].in?(COLLAPSED_BY_DEFAULT_MESSAGE_CLASSES)
insignificant?
end

def read?
folder.outbox? || insignificant?
end

def insignificant?
payload["class"].in?(INFORMATIONAL_MESSAGE_CLASSES)
end

def delivery_notification
Expand Down Expand Up @@ -97,6 +106,7 @@ def self.create_message(govbox_message)
replyable: govbox_message.replyable?,
collapsed: govbox_message.collapsed?,
outbox: govbox_message.folder.outbox?,
read: govbox_message.read?,
metadata: {
"correlation_id": govbox_message.payload["correlation_id"],
"reference_id": govbox_message.payload["reference_id"],
Expand Down
22 changes: 22 additions & 0 deletions app/models/inbox_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: tags
#
# id :bigint not null, primary key
# color :enum
# external_name :string
# icon :string
# name :string not null
# tag_groups_count :integer default(0), not null
# type :string not null
# visible :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
# owner_id :bigint
# tenant_id :bigint not null
#
class InboxTag < Tag
def destroyable?
false
end
end
2 changes: 2 additions & 0 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Tenant < ApplicationRecord

has_one :draft_tag, -> { where(owner_id: nil) }
has_one :everything_tag
has_one :inbox_tag
has_one :signature_requested_tag
has_one :signed_tag
has_one :signed_externally_tag
Expand Down Expand Up @@ -117,6 +118,7 @@ def create_default_objects

create_draft_tag!(name: "Rozpracované", visible: true)
create_everything_tag!(name: "Všetky správy", visible: false)
create_inbox_tag!(name: "Doručené", visible: false)
create_archived_tag!(name: "Archivované", color: "green", icon: "archive-box", visible: true)
create_signature_requested_tag!(name: "Na podpis", visible: true, color: "yellow", icon: "pencil")
create_signed_tag!(name: "Podpísané", visible: true, color: "green", icon: "fingerprint")
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20250204074342_create_inbox_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateInboxTag < ActiveRecord::Migration[7.1]
def up
Tenant.find_each do |tenant|
tenant.create_inbox_tag!(name: "Doručené", visible: false) unless tenant.inbox_tag
AddInboxTagToThreadsJob.set(job_context: :later).perform_later
end
end

def down
# noop
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8031370

Please sign in to comment.