From 086cd961ec9e9bf4605713a41c0861f3ef71d649 Mon Sep 17 00:00:00 2001 From: Night Date: Wed, 15 Nov 2023 23:00:42 -0500 Subject: [PATCH] move message delete to gql mutation --- src/modules/chat_custom_timeouts/index.js | 27 ++++++++++++++++++++++- src/utils/twitch.js | 8 +++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/modules/chat_custom_timeouts/index.js b/src/modules/chat_custom_timeouts/index.js index 97985fe356..bb46ed953c 100644 --- a/src/modules/chat_custom_timeouts/index.js +++ b/src/modules/chat_custom_timeouts/index.js @@ -1,6 +1,8 @@ import {off, on} from 'delegated-events'; +import gql from 'graphql-tag'; import {PlatformTypes} from '../../constants.js'; import formatMessage from '../../i18n/index.js'; +import {getCurrentChannel} from '../../utils/channel.js'; import {loadModuleForPlatforms} from '../../utils/modules.js'; import mouseButtons from '../../utils/mousebuttons.js'; import twitch from '../../utils/twitch.js'; @@ -87,7 +89,30 @@ function handleTimeoutClick(e, messageId) { command = '/timeout'; duration = action.length; } else if (action.type === ActionTypes.DELETE) { - twitch.sendChatMessage(`/delete ${messageId}`); + const currentChannel = getCurrentChannel(); + twitch + .graphqlMutation( + gql` + mutation BTTVDeleteChatMessage($input: DeleteChatMessageInput!) { + deleteChatMessage(input: $input) { + responseCode + message { + id + sender { + id + } + } + } + } + `, + { + input: { + channelID: currentChannel.id, + messageID: messageId, + }, + } + ) + .catch(() => {}); } if (command && user) { const reason = e.shiftKey ? setReason(action.type) : ''; diff --git a/src/utils/twitch.js b/src/utils/twitch.js index 6c9e16494d..dfc90ebaed 100644 --- a/src/utils/twitch.js +++ b/src/utils/twitch.js @@ -790,6 +790,14 @@ export default { return client.query({query, variables}); }, + graphqlMutation(mutation, variables) { + const client = this.getApolloClient(); + if (client == null) { + return Promise.reject(new Error('unable to locate Twitch Apollo client')); + } + return client.mutate({mutation, variables}); + }, + getChatCommandStore() { let context; try {