Skip to content

Commit

Permalink
feat: include top level parent information in ChatReply (#833)
Browse files Browse the repository at this point in the history
* feat: add new thread parent fields to ChatReply

* chore: reply directly to relevant message
  • Loading branch information
iProdigy committed Sep 7, 2023
1 parent 5751b46 commit 33b50b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Expand Up @@ -2,7 +2,6 @@

import com.github.twitch4j.chat.ITwitchChat;
import com.github.twitch4j.common.events.domain.EventChannel;
import com.github.twitch4j.common.util.ChatReply;
import com.github.twitch4j.common.util.CryptoUtils;

@FunctionalInterface
Expand All @@ -21,9 +20,7 @@ default EventChannel getChannel() {
* @param message the message to be sent.
*/
default void reply(ITwitchChat chat, String message) {
String replyId = getMessageEvent().getTagValue(ChatReply.REPLY_MSG_ID_TAG_NAME)
.orElseGet(() -> getMessageEvent().getMessageId().orElse(null));
chat.sendMessage(getChannel().getName(), message, CryptoUtils.generateNonce(32), replyId);
chat.sendMessage(getChannel().getName(), message, CryptoUtils.generateNonce(32), getMessageEvent().getMessageId().orElse(null));
}

}
Expand Up @@ -18,31 +18,41 @@ public class ChatReply {
public static final String REPLY_MSG_ID_TAG_NAME = "reply-parent-msg-id";

/**
* The msgId of the original message being replied to.
* An ID that uniquely identifies the direct parent message that this message is replying to.
*/
@NonNull
String messageId;

/**
* The text of the original message being replied to.
* The text of the direct parent message.
*/
String messageBody;

/**
* The id of the user who originally sent the message being replied to.
* An ID that identifies the sender of the direct parent message.
*/
String userId;

/**
* The login name of the user who originally sent the message being replied to.
* The login name of the sender of the direct parent message.
*/
String userLogin;

/**
* The display name of the user who originally sent the message being replied to.
* The display name of the sender of the direct parent message.
*/
String displayName;

/**
* An ID that uniquely identifies the top-level parent message of the reply thread that this message is replying to.
*/
String threadMessageId;

/**
* The login name of the sender of the top-level parent message.
*/
String threadUserLogin;

/**
* Attempts to parse a {@link ChatReply} instance from chat tags.
*
Expand All @@ -60,7 +70,9 @@ public static ChatReply parse(final Map<String, CharSequence> tags) {
unescapeTagValue(tags.get("reply-parent-msg-body")),
Objects.toString(tags.get("reply-parent-user-id"), null),
Objects.toString(tags.get("reply-parent-user-login"), null),
unescapeTagValue(tags.get("reply-parent-display-name"))
unescapeTagValue(tags.get("reply-parent-display-name")),
Objects.toString(tags.get("reply-thread-parent-msg-id"), null),
Objects.toString(tags.get("reply-thread-parent-user-login"), null)
);
}
}

0 comments on commit 33b50b7

Please sign in to comment.