Skip to content

Commit

Permalink
move message delete to gql mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
night committed Nov 16, 2023
1 parent 3037534 commit 086cd96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/modules/chat_custom_timeouts/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) : '';
Expand Down
8 changes: 8 additions & 0 deletions src/utils/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 086cd96

Please sign in to comment.