Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong message ID for messages sent from client #529

Open
Durss opened this issue Aug 26, 2022 · 4 comments
Open

Wrong message ID for messages sent from client #529

Durss opened this issue Aug 26, 2022 · 4 comments

Comments

@Durss
Copy link

Durss commented Aug 26, 2022

Hello :)

There's a very tricky issue with v1.8.5 of tmi.js that might still be an issue with v1.9.0 with this line:

this.userstate[channel] = tags;

(haven't tested with 1.9.0 sorry)

The base of the problem is that when sending a message from TMI.js, we get a on("message") event with a sort of fake message built up by TMI.js as twitch does not send us back the message.
On every USERSTATE event you keep the tags and stuff on a sort of cache so you can populate the next fake data with tags of the previous message. Including its ID.

The ideal would be that TMI would use the client-nonce and wait for the USERSTATE to call the on("message") with proper data on it so the user does not have to worry about this.
As this is not managed yet (on neither version if i'm not mistaken), I managed it on my side for now.

But, as you recycle the tags from the previous USERSTATE event, including the message ID, the new message receives the previous message ID. Because of this, if we try to delete a message based on this ID we actually delete the previous message.

A quick and dirty workaround is to delete the ID before storing it on the local cache:

delete tags.id://Added
this.userstate[channel] = tags;

Thanks for you work !

@Durss Durss changed the title Sent message IDs offset Wrong message ID for messages sent from client Aug 26, 2022
@iSlammedMyKindle
Copy link

Same issue over here ^ - we're working around this in our codebase by playing a game of telephone, which isn't ideal >.<

@Durss
Copy link
Author

Durss commented Feb 1, 2023

If that can be of any interest for anyone, I fixed this issue on this fork:
https://github.com/Durss/tmi.js

I generate a temporary ID, send it with the message in its "client-nonce" tag, wait for receiving a message ID, check if its client-nonce tag matches one of the sent messages, if so, I emit the new message event with the proper message ID.
This means that if twitch does not send back the real message ID, tmi.js will never emit the "message" event. Which may actually be a good idea as that may mean the message hasn't been sent.

(needs further testing to make sure it's ok tho)

@vivimouret29
Copy link

This issue is still open, I shall hope it will be done soon
We still can't delete a message with the command /deletemessage

I forked the work's @Durss but it didn't resolved the problem
Even if the UUID message is well relatable, it isn't erased from the tchat

image

@Durss
Copy link
Author

Durss commented Aug 5, 2023

There's no more /commands available since Twitch disabled them all (except for /me) last fabruary,.
You now need to use the API to delete a message:
https://dev.twitch.tv/docs/api/reference/#delete-chat-messages

Here is a migration guide for every /command
https://dev.twitch.tv/docs/irc/chat-commands/#migration-guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants