chore: Migrate PubSub Token to contact inbox (#3434)
At present, the websocket pubsub tokens are present at the contact objects in chatwoot. A better approach would be to have these tokens at the contact_inbox object instead. This helps chatwoot to deliver the websocket events targetted to the specific widget connection, stop contact events from leaking into other chat sessions from the same contact. Fixes #1682 Fixes #1664 Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -7,4 +7,10 @@ module Pubsubable
|
||||
# Used by the actionCable/PubSub Service we use for real time communications
|
||||
has_secure_token :pubsub_token
|
||||
end
|
||||
|
||||
def pubsub_token
|
||||
# backfills tokens for existing records
|
||||
regenerate_pubsub_token if self[:pubsub_token].blank?
|
||||
self[:pubsub_token]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#
|
||||
|
||||
class Contact < ApplicationRecord
|
||||
include Pubsubable
|
||||
# TODO: remove the pubsub_token attribute from this model in future.
|
||||
include Avatarable
|
||||
include AvailabilityStatusable
|
||||
include Labelable
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# hmac_verified :boolean default(FALSE)
|
||||
# pubsub_token :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# contact_id :bigint
|
||||
@@ -15,6 +16,7 @@
|
||||
# index_contact_inboxes_on_contact_id (contact_id)
|
||||
# index_contact_inboxes_on_inbox_id (inbox_id)
|
||||
# index_contact_inboxes_on_inbox_id_and_source_id (inbox_id,source_id) UNIQUE
|
||||
# index_contact_inboxes_on_pubsub_token (pubsub_token) UNIQUE
|
||||
# index_contact_inboxes_on_source_id (source_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
@@ -24,6 +26,7 @@
|
||||
#
|
||||
|
||||
class ContactInbox < ApplicationRecord
|
||||
include Pubsubable
|
||||
validates :inbox_id, presence: true
|
||||
validates :contact_id, presence: true
|
||||
validates :source_id, presence: true
|
||||
|
||||
Reference in New Issue
Block a user