Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f998d6123 | ||
|
|
80a66174a7 | ||
|
|
1b55172eb7 | ||
|
|
318e0b10e4 | ||
|
|
db9daa5fb6 | ||
|
|
d68345672c | ||
|
|
1a74e52445 | ||
|
|
ae5deca24b | ||
|
|
7c174cacc8 | ||
|
|
43b5750314 | ||
|
|
1a19c864d3 | ||
|
|
9614e19d82 | ||
|
|
1a812692c9 | ||
|
|
ce394e7f08 | ||
|
|
d3afe64bb1 | ||
|
|
9cff6c04ee |
@@ -48,7 +48,6 @@ class JsonSchemaValidator < ActiveModel::Validator
|
||||
|
||||
# Add validation errors to the record with a formatted statement
|
||||
validation_errors.each do |error|
|
||||
# byebug
|
||||
format_and_append_error(error, record)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ module Labelable
|
||||
|
||||
included do
|
||||
acts_as_taggable_on :labels
|
||||
before_save :clear_labels_cache
|
||||
end
|
||||
|
||||
def update_labels(labels = nil)
|
||||
@@ -13,4 +14,21 @@ module Labelable
|
||||
new_labels << labels
|
||||
update!(label_list: new_labels)
|
||||
end
|
||||
|
||||
def preloaded_label_list
|
||||
unless @labels_cache
|
||||
@labels_cache = []
|
||||
taggings.each do |tagging|
|
||||
@labels_cache << tagging.tag.name
|
||||
end
|
||||
end
|
||||
|
||||
@labels_cache || []
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clear_labels_cache
|
||||
@labels_cache = nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,8 +58,9 @@ class Conversations::FilterService < FilterService
|
||||
|
||||
def conversations
|
||||
@conversations = @conversations.includes(
|
||||
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team
|
||||
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team, :messages
|
||||
)
|
||||
|
||||
@conversations.latest.page(current_page)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,8 +17,8 @@ json.meta do
|
||||
end
|
||||
|
||||
json.id conversation.display_id
|
||||
if conversation.messages.count.zero?
|
||||
json.messages []
|
||||
if !conversation.messages.first.present?
|
||||
json.messages []
|
||||
elsif conversation.unread_incoming_messages.count.zero?
|
||||
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]
|
||||
else
|
||||
@@ -33,7 +33,7 @@ json.can_reply conversation.can_reply?
|
||||
json.contact_last_seen_at conversation.contact_last_seen_at.to_i
|
||||
json.custom_attributes conversation.custom_attributes
|
||||
json.inbox_id conversation.inbox_id
|
||||
json.labels conversation.label_list
|
||||
json.labels conversation.preloaded_label_list
|
||||
json.muted conversation.muted?
|
||||
json.snoozed_until conversation.snoozed_until
|
||||
json.status conversation.status
|
||||
|
||||
@@ -243,6 +243,20 @@ RSpec.describe Conversation, type: :model do
|
||||
expect(conversation.label_list).to match_array(labels)
|
||||
end
|
||||
|
||||
it 'ensures preloaded labels are always in sync with the database' do
|
||||
labels = [first_label].map(&:title)
|
||||
expect(conversation.update_labels(labels)).to be(true)
|
||||
expect(conversation.label_list).to match_array(labels)
|
||||
expect(conversation.preloaded_label_list).to match_array(labels)
|
||||
|
||||
updated_labels = [second_label].map(&:title)
|
||||
# reload this so that the taggins collection is updated
|
||||
conversation.reload
|
||||
expect(conversation.update_labels(updated_labels)).to be(true)
|
||||
expect(conversation.label_list).to match_array(updated_labels)
|
||||
expect(conversation.preloaded_label_list).to match_array(updated_labels)
|
||||
end
|
||||
|
||||
it 'adds and removes previously added labels' do
|
||||
labels = [first_label, fourth_label].map(&:title)
|
||||
expect { conversation.update_labels(labels) }
|
||||
|
||||
Reference in New Issue
Block a user