chat_session_update.rb 860 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class Sessions::Event::ChatSessionUpdate < Sessions::Event::ChatBase
  2. def run
  3. return super if super
  4. return if !check_chat_session_exists
  5. return if !permission_check('chat.agent', 'chat')
  6. chat_session = current_chat_session
  7. if @payload['data']['name'] != chat_session.name
  8. chat_session.name = @payload['data']['name']
  9. chat_session.save!
  10. end
  11. if @payload['data']['tags']
  12. new_tags = @payload['data']['tags'].split(',')
  13. new_tags.each(&:strip!)
  14. tags = chat_session.tag_list
  15. new_tags.each do |new_tag|
  16. next if new_tag.blank?
  17. next if tags.include?(new_tag)
  18. chat_session.tag_add(new_tag, current_user_id)
  19. end
  20. tags.each do |tag|
  21. next if new_tags.include?(tag)
  22. chat_session.tag_remove(tag, current_user_id)
  23. end
  24. end
  25. nil
  26. end
  27. end