diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy index 4b0e60fe..4c60de83 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy @@ -3,6 +3,8 @@ package com.muwire.clilanterna import com.googlecode.lanterna.gui2.TextBox import com.googlecode.lanterna.gui2.TextGUI import com.googlecode.lanterna.gui2.Window +import com.googlecode.lanterna.gui2.dialogs.MessageDialog +import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton import com.googlecode.lanterna.TerminalSize import com.googlecode.lanterna.gui2.BasicWindow import com.googlecode.lanterna.gui2.Button @@ -10,6 +12,7 @@ import com.googlecode.lanterna.gui2.GridLayout import com.googlecode.lanterna.gui2.GridLayout.Alignment import com.googlecode.lanterna.gui2.LayoutData import com.googlecode.lanterna.gui2.Panel +import com.muwire.core.Constants import com.muwire.core.Core import com.muwire.core.SharedFile import com.muwire.core.files.UICommentEvent @@ -49,11 +52,16 @@ class AddCommentView extends BasicWindow { Button saveButton = new Button("Save", { String newComment = textBox.getText() - newComment = Base64.encode(DataUtil.encodei18nString(newComment)) - String encodedOldComment = sharedFile.getComment() - sharedFile.setComment(newComment) - core.eventBus.publish(new UICommentEvent(sharedFile : sharedFile, oldComment : encodedOldComment)) - close() + if (newComment.length() > Constants.MAX_COMMENT_LENGTH) { + String error = "Your comment is too long - ${newComment.length()} bytes. Maximum is $Constants.MAX_COMMENT_LENGTH bytes" + MessageDialog.showMessageDialog(textGUI, "Comment Too Long", error, MessageDialogButton.Close) + } else { + newComment = Base64.encode(DataUtil.encodei18nString(newComment)) + String encodedOldComment = sharedFile.getComment() + sharedFile.setComment(newComment) + core.eventBus.publish(new UICommentEvent(sharedFile : sharedFile, oldComment : encodedOldComment)) + close() + } }) Button cancelButton = new Button("Cancel", {close()})