Skip to content

Commit

Permalink
Fixed issue zammad#880 - No chat message over 5000 chars possible. E.…
Browse files Browse the repository at this point in the history
… g. if image is pasted.
  • Loading branch information
martini committed Apr 20, 2017
1 parent de7fef8 commit e26aa1f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/app/controllers/chat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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: =>
Expand Down
16 changes: 14 additions & 2 deletions app/assets/javascripts/app/lib/base/jquery.contenteditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
# maxlength: 123
# multiline: true / disable enter + strip on paste
# placeholder: 'some placeholder'
# imageWidth: absolute (<img style="width: XXpx; height: XXXpx" src="">) || relative (<img style="width: 100%; max-width: XXpx;" src="">)
*/

var pluginName = 'ce',
defaults = {
debug: false,
mode: 'richtext',
multiline: true,
imageWidth: 'absolute',
allowKey: {
8: true, // backspace
9: true, // tab
Expand Down Expand Up @@ -284,7 +286,12 @@
}
_this.log('image inserted')
result = dataUrl
img = "<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">"
if (_this.options.imageWidth == 'absolute') {
img = "<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">"
}
else {
img = "<img style=\"width: 100%; max-width: " + width + "px;\" src=\"" + result + "\">"
}
document.execCommand('insertHTML', false, img)
}

Expand Down Expand Up @@ -399,7 +406,12 @@
//console.log('dataUrl', dataUrl)
_this.log('image inserted')
result = dataUrl
img = $("<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">")
if (_this.options.imageWidth == 'absolute') {
img = $("<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">")
}
else {
img = $("<img style=\"width: 100%; max-width: " + width + "px;\" src=\"" + result + "\">")
}
img = img.get(0)

if (document.caretPositionFromPoint) {
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20120101000010_create_ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def up

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
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20170420000001_chat_increase_message_size.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 9 additions & 5 deletions lib/sessions/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ def self.run(params)
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

0 comments on commit e26aa1f

Please sign in to comment.