From e26aa1f599a5b855e45736dd10800844cba6f4d0 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 20 Apr 2017 13:15:40 +0200 Subject: [PATCH] Fixed issue #880 - No chat message over 5000 chars possible. E. g. if image is pasted. --- .../javascripts/app/controllers/chat.coffee | 7 ++++--- .../app/lib/base/jquery.contenteditable.js | 16 ++++++++++++++-- db/migrate/20120101000010_create_ticket.rb | 2 +- .../20170420000001_chat_increase_message_size.rb | 10 ++++++++++ lib/sessions/event.rb | 14 +++++++++----- 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20170420000001_chat_increase_message_size.rb diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 0381eff35..f8e969e86 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -474,9 +474,10 @@ class ChatWindow extends App.Controller event.data.callback() @$('.js-customerChatInput').ce({ - mode: 'richtext' - multiline: true - maxlength: 40000 + mode: 'richtext' + multiline: true + maxlength: 40000 + imageWidth: 'relative' }) disconnect: => diff --git a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js index cf32462c8..32b336806 100644 --- a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js +++ b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js @@ -6,6 +6,7 @@ # maxlength: 123 # multiline: true / disable enter + strip on paste # placeholder: 'some placeholder' +# imageWidth: absolute () || relative () */ var pluginName = 'ce', @@ -13,6 +14,7 @@ debug: false, mode: 'richtext', multiline: true, + imageWidth: 'absolute', allowKey: { 8: true, // backspace 9: true, // tab @@ -284,7 +286,12 @@ } _this.log('image inserted') result = dataUrl - img = "" + if (_this.options.imageWidth == 'absolute') { + img = "" + } + else { + img = "" + } document.execCommand('insertHTML', false, img) } @@ -399,7 +406,12 @@ //console.log('dataUrl', dataUrl) _this.log('image inserted') result = dataUrl - img = $("") + if (_this.options.imageWidth == 'absolute') { + img = $("") + } + else { + img = $("") + } img = img.get(0) if (document.caretPositionFromPoint) { diff --git a/db/migrate/20120101000010_create_ticket.rb b/db/migrate/20120101000010_create_ticket.rb index e8c68dd0f..d9bb29bd5 100644 --- a/db/migrate/20120101000010_create_ticket.rb +++ b/db/migrate/20120101000010_create_ticket.rb @@ -434,7 +434,7 @@ class CreateTicket < ActiveRecord::Migration create_table :chat_messages do |t| t.integer :chat_session_id, null: false - t.string :content, limit: 5000, null: false + t.text :content, limit: 20.megabytes + 1, null: false t.integer :created_by_id, null: true t.timestamps limit: 3, null: false end diff --git a/db/migrate/20170420000001_chat_increase_message_size.rb b/db/migrate/20170420000001_chat_increase_message_size.rb new file mode 100644 index 000000000..6b14384cd --- /dev/null +++ b/db/migrate/20170420000001_chat_increase_message_size.rb @@ -0,0 +1,10 @@ +class ChatIncreaseMessageSize < ActiveRecord::Migration + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + change_column :chat_messages, :content, :text, limit: 20.megabytes + 1, null: false + end + +end diff --git a/lib/sessions/event.rb b/lib/sessions/event.rb index ed7ecb62e..3aa7f0b4b 100644 --- a/lib/sessions/event.rb +++ b/lib/sessions/event.rb @@ -7,13 +7,17 @@ class Sessions::Event begin backend = load_adapter(adapter) rescue => e - return { error: "No such event #{params[:event]}" } + return { event: 'error', data: { error: "No such event #{params[:event]}", payload: params[:payload] } } end - instance = backend.new(params) - result = instance.run - instance.destroy - result + begin + instance = backend.new(params) + result = instance.run + instance.destroy + result + rescue => e + return { event: 'error', data: { error: e.message, payload: params[:payload] } } + end end end