Skip to content

Commit

Permalink
fix(twitch/chat): chat cooldown timer
Browse files Browse the repository at this point in the history
  • Loading branch information
pimothyxd committed Dec 21, 2024
1 parent 9bde37d commit 24ff0ee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/site/twitch.tv/modules/chat/ChatController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ChatList
ref="chatList"
:list="list"
:restrictions="restrictions"
:shared-chat-data="sharedChatDataByChannelID"
:message-handler="messageHandler"
/>
Expand Down Expand Up @@ -70,6 +71,7 @@ const props = defineProps<{
buffer?: HookedInstance<Twitch.MessageBufferComponent>;
events?: HookedInstance<Twitch.ChatEventComponent>;
presentation?: HookedInstance<Twitch.ChatListPresentationComponent>;
restrictions?: HookedInstance<Twitch.ChatRestrictionsComponent>;
}>();

const mod = getModule<"TWITCH", "chat">("chat")!;
Expand Down
10 changes: 10 additions & 0 deletions src/site/twitch.tv/modules/chat/ChatList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import BasicSystemMessage from "@/app/chat/msg/BasicSystemMessage.vue";
const props = defineProps<{
list: HookedInstance<Twitch.ChatListComponent>;
restrictions?: HookedInstance<Twitch.ChatRestrictionsComponent>;
messageHandler: Twitch.MessageHandlerAPI | null;
sharedChatData: Map<string, Twitch.SharedChat> | null;
}>();
Expand Down Expand Up @@ -80,6 +81,7 @@ const showMonitoredLowTrustUser = useConfig<boolean>("highlights.basic.monitored
const messageHandler = toRef(props, "messageHandler");
const list = toRef(props, "list");
const sharedChatData = toRef(props, "sharedChatData");
const restrictions = toRef(props, "restrictions");
// Unrender messages out of view
const chatListEl = ref<HTMLElement>();
Expand Down Expand Up @@ -449,8 +451,16 @@ watch(
messageHandler,
(handler, old) => {
if (handler !== old && old) {
if (restrictions.value?.component.onChatEvent) {
messages.handlers.delete(restrictions.value.component.onChatEvent);
}
unsetPropertyHook(old, "handleMessage");
} else if (handler) {
if (restrictions.value?.component.onChatEvent) {
messages.handlers.add(restrictions.value.component.onChatEvent);
}
defineFunctionHook(handler, "handleMessage", function (old, msg: Twitch.AnyMessage) {
const ok = onMessage(msg);
if (ok) return ""; // message was rendered by the extension
Expand Down
6 changes: 6 additions & 0 deletions src/site/twitch.tv/modules/chat/ChatModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:buffer="chatBuffer.instances[0] ?? undefined"
:events="chatEvents.instances[0] ?? undefined"
:presentation="chatListPresentation.instances[0] ?? undefined"
:restrictions="chatRestrictions.instances[0] ?? undefined"
/>
</template>
</template>
Expand Down Expand Up @@ -100,6 +101,11 @@ const chatListPresentation = useComponentHook<Twitch.ChatListPresentationCompone
predicate: (n) => n.props && n.props.sharedChatDataByChannelID,
});
const chatRestrictions = useComponentHook<Twitch.ChatRestrictionsComponent>({
parentSelector: ".stream-chat",
predicate: (n) => n.getRestrictions && n.onChatEvent,
});
const isHookable = ref(false);
const isHookableDbc = refDebounced(isHookable, 200);
Expand Down
7 changes: 7 additions & 0 deletions src/types/twitch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ declare module Twitch {
handleMessage: (msg: ChatMessage) => void;
}

export type ChatRestrictionsComponent = ReactExtended.WritableComponent<{}> & {
notifyHandlers: () => void;
getRestrictions: () => string[];
updateRestrictionState: () => void;
onChatEvent: (msgData: Twitch.AnyMessage) => void;
};

export type VideoChannelComponent = ReactExtended.WritableComponent<{
channelID: string;
displayName: string;
Expand Down

0 comments on commit 24ff0ee

Please sign in to comment.