Skip to content

Commit

Permalink
Added correct handling for long messages (>2000 symbols)
Browse files Browse the repository at this point in the history
Removed unused code
  • Loading branch information
kaspian-xz committed Apr 11, 2023
1 parent c8e8333 commit c7245c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ public void handle(Message message) {
.responseStream().subscribe(new DisposableSubscriber<>() {
private final StringBuilder sb = new StringBuilder();

@Override
protected void onStart() {
super.onStart();
message.getChannel().sendTyping().queue();
}

@Override
public void onNext(String s) {
if (sb.length() + s.length() > Message.MAX_CONTENT_LENGTH) {
message.reply(sb.toString()).queue();
message.getChannel().sendTyping().queue();
sb.delete(0, sb.length());
}
sb.append(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ public class MessageHandler {

private static final Logger LOG = LoggerFactory.getLogger(MessageHandler.class);

private final EmptyMessageHandler emptyMessageHandler;
private final PrivateMessageHandler privateMessageHandler;
private final MentionRequestHandler mentionRequestHandler;

public MessageHandler(EmptyMessageHandler emptyMessageHandler, PrivateMessageHandler privateMessageHandler, MentionRequestHandler mentionRequestHandler) {
public MessageHandler(PrivateMessageHandler privateMessageHandler, MentionRequestHandler mentionRequestHandler) {
LOG.info("MessageHandler created");
this.emptyMessageHandler = emptyMessageHandler;
this.privateMessageHandler = privateMessageHandler;
this.mentionRequestHandler = mentionRequestHandler;
}
Expand All @@ -32,8 +30,6 @@ public void handle(Message message) {
privateMessageHandler.handle(message);
} else if (isCurrentUserMentioned(message)) {
mentionRequestHandler.handle(message);
} else {
emptyMessageHandler.handle(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class PrivateMessageHandler {

private static final Logger LOG = LoggerFactory.getLogger(PrivateMessageHandler.class);

private final ChatModelConnectorService chatModelConnectorService;

public PrivateMessageHandler(ChatModelConnectorService chatModelConnectorService) {
Expand Down Expand Up @@ -49,8 +48,19 @@ public void handle(Message message) {
.responseStream().subscribe(new DisposableSubscriber<>() {
private final StringBuilder sb = new StringBuilder();

@Override
protected void onStart() {
super.onStart();
channel.sendTyping().queue();
}

@Override
public void onNext(String s) {
if (sb.length() + s.length() > Message.MAX_CONTENT_LENGTH) {
channel.sendMessage(sb.toString()).queue();
channel.sendTyping().queue();
sb.delete(0, sb.length());
}
sb.append(s);
}

Expand Down

0 comments on commit c7245c1

Please sign in to comment.