Skip to content

Commit

Permalink
Put in better constraints for max message length
Browse files Browse the repository at this point in the history
  • Loading branch information
dogeared committed Sep 29, 2023
1 parent 20b9942 commit 1f5dc0e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
target
node_modules
.nuxt
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
6 changes: 5 additions & 1 deletion src/frontend/components/room/ChatContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="message.userName"></v-list-item-title>
<v-list-item-subtitle v-html="marked(message.message)"></v-list-item-subtitle>
<v-list-item-subtitle class="message" v-html="marked(message.message)"></v-list-item-subtitle>
</v-list-item-content>
</template>
<template v-else>
Expand Down Expand Up @@ -53,4 +53,8 @@ export default {
</script>

<style scoped>
.message {
inline-size: 500px;
overflow-wrap: break-word;
}
</style>
10 changes: 7 additions & 3 deletions src/frontend/components/room/ChatMessageSender.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>
<form @submit.prevent="sendMessage">
<v-text-field
counter="500"
:counter="maxMessageLength"
:rules="rules"
label="Type a message"
type="text"
Expand All @@ -31,7 +31,8 @@ export default {
data() {
return {
message: "",
rules: [v => v.length <= 500 || 'Max 500 characters']
maxMessageLength: 500,
rules: [v => v.length <= this.maxMessageLength || 'Max 500 characters']
};
},
computed: {
Expand All @@ -41,9 +42,12 @@ export default {
},
methods: {
sendMessage() {
if (this.message.length > this.maxMessageLength) {
return;
};
const newMessage = {
type: "MESSAGE",
message: (this.message.length > 500) ? this.message.substring(0,500) : this.message
message: this.message
};
const messageWithRoomId = { roomId: this.roomId, message: newMessage };
this.$store.dispatch("main/sendMessage", messageWithRoomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ChatController {
private final RoomService roomService;
private final SimpMessageSendingOperations messagingTemplate;

private final int MAX_MESSAGE_LENGTH = 500;

public ChatController(RoomService roomService, SimpMessageSendingOperations messagingTemplate) {
this.roomService = roomService;
this.messagingTemplate = messagingTemplate;
Expand Down Expand Up @@ -88,6 +90,9 @@ public ChatRoomUserListDto userLeaveRoom(UserRoomKeyDto userRoomKey, SimpMessage

@MessageMapping("chat/{roomId}/sendMessage")
public Message sendMessage(@DestinationVariable String roomId, Message message) {
if (message.message.length() > MAX_MESSAGE_LENGTH) {
message = new Message(message.type, message.userName, message.message.substring(0,MAX_MESSAGE_LENGTH));
}
messagingTemplate.convertAndSend(format("/chat/%s/messages", roomId), message);
return message;
}
Expand Down

0 comments on commit 1f5dc0e

Please sign in to comment.