chat_session_update.rb 937 B

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