Compare commits

...
16 Commits
Author SHA1 Message Date
Shivam MishraandGitHub 5f998d6123 Merge branch 'develop' into feature/cw-1605 2023-05-18 17:51:31 +05:30
Shivam Mishra 80a66174a7 feat: include messages 2023-05-18 17:40:28 +05:30
Shivam Mishra 1b55172eb7 refactor: use first instead of count 2023-05-18 17:40:11 +05:30
Shivam Mishra 318e0b10e4 Merge branch 'develop' of github.com:chatwoot/chatwoot into feature/cw-1605 2023-05-10 23:23:40 +05:30
Shivam Mishra db9daa5fb6 Merge branch 'develop' of github.com:chatwoot/chatwoot into feature/cw-1605 2023-05-10 17:50:37 +05:30
Shivam Mishra d68345672c fix: typo 2023-05-09 15:10:47 +05:30
Shivam Mishra 1a74e52445 feat: ensure the clean-up logic works 2023-05-09 14:24:35 +05:30
Shivam Mishra ae5deca24b test: update to check for preloaded_label_list 2023-05-09 14:05:28 +05:30
Shivam Mishra 7c174cacc8 Merge branch 'develop' of github.com:chatwoot/chatwoot into feature/cw-1605 2023-05-09 13:30:38 +05:30
Shivam MishraandGitHub 43b5750314 Merge branch 'develop' into feature/cw-1605 2023-05-05 17:00:17 +05:30
Shivam Mishra 1a19c864d3 fix: use message_count only if it is available 2023-05-05 16:57:22 +05:30
Shivam Mishra 9614e19d82 fix: remove byebug in comments 2023-05-05 16:29:23 +05:30
Shivam Mishra 1a812692c9 refactor: better naming 2023-05-04 13:49:14 +05:30
Shivam Mishra ce394e7f08 fix: new line 2023-05-04 13:46:39 +05:30
Shivam Mishra d3afe64bb1 feat: preload messages_count 2023-05-04 13:17:55 +05:30
Shivam Mishra 9cff6c04ee feat: preload label list 2023-05-04 12:56:06 +05:30
5 changed files with 37 additions and 5 deletions
@@ -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
+18
View File
@@ -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
+2 -1
View File
@@ -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
+14
View File
@@ -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) }