Skip to content

Commit

Permalink
Store messages in EmoteMessage not just md5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev committed Nov 21, 2024
1 parent 503db3b commit 2bff2f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ class Chat {
this.removeSlashCmdFromText(win.lastmessage?.message) === textonly;

if (isCombo && win.lastmessage?.type === MessageTypes.EMOTE) {
win.lastmessage.add(message.md5);
win.lastmessage.add(message);

if (this.user.equalWatching(usr.watching)) {
win.lastmessage.ui.classList.toggle('watching-same', true);
Expand All @@ -1168,12 +1168,12 @@ class Chat {
}

if (isCombo && win.lastmessage?.type === MessageTypes.USER) {
const lastMessageMd5 = win.lastmessage.md5;
const lastMessage = win.lastmessage;
win.removeLastMessage();
const msg = MessageBuilder.emote(
textonly,
data.timestamp,
[lastMessageMd5, message.md5],
lastMessage.timestamp,
[lastMessage, message],
2,
).into(this);

Expand Down
18 changes: 12 additions & 6 deletions assets/chat/js/messages/ChatEmoteMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ function ChatEmoteMessageCount(message) {
const ChatEmoteMessageCountThrottle = throttle(63, ChatEmoteMessageCount);

export default class ChatEmoteMessage extends ChatMessage {
md5List = [];
messages = [];

constructor(emote, timestamp, md5List, count = 1) {
emotecount = 0;

constructor(emote, timestamp, messages) {
super(emote, timestamp, MessageTypes.EMOTE);
this.md5List = md5List;
this.emotecount = count;
this.messages = messages;
this.emotecount = messages.length;
this.emoteFormatter = new EmoteFormatter();
}

Expand Down Expand Up @@ -65,12 +67,16 @@ export default class ChatEmoteMessage extends ChatMessage {
this.ui.append(this.text.get(0), this.combo.get(0));
}

add(md5) {
this.md5List.push(md5);
add(message) {
this.messages.push(message);
this.emotecount += 1;
ChatEmoteMessageCountThrottle(this);
}

containsMessage(message) {
return this.messages.find((msg) => msg.md5 === message.md5);
}

completeCombo() {
ChatEmoteMessageCount(this);
this.combo.attr('class', `${this.combo.attr('class')} combo-complete`);
Expand Down
4 changes: 2 additions & 2 deletions assets/chat/js/messages/MessageBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default class MessageBuilder {
return new ChatUserMessage(message, user, timestamp);
}

static emote(emote, timestamp, md5List, count = 1) {
return new ChatEmoteMessage(emote, timestamp, md5List, count);
static emote(emote, timestamp, messages) {
return new ChatEmoteMessage(emote, timestamp, messages);
}

static whisper(message, user, target, timestamp = null, id = null) {
Expand Down
2 changes: 1 addition & 1 deletion assets/chat/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ChatWindow extends EventEmitter {
containsMessage(message) {
return this.messages.find((msg) => {
if (msg.type === MessageTypes.EMOTE) {
return msg.md5List.includes(message.md5);
return msg.containsMessage(message);
}
return msg.md5 === message.md5;
});
Expand Down

0 comments on commit 2bff2f0

Please sign in to comment.