tm-better-chat icon indicating copy to clipboard operation
tm-better-chat copied to clipboard

Chat Channel API - Plugin Export

Open Geekid812 opened this issue 1 year ago • 1 comments

As Better Chat is a fully fledged chat replacement, it seems interesting to provide other plugins a way to use BC to implement their own chat channels/servers (this is completely unrelated to other plugins I am developing, of course). This is sort of similar in spirit to #53, but should allow plugins to have more flexibility to act as a controller for how messages are passed in an out of a channel.

A simple API implementation example could be:

shared interface IChatChannelHook
{
    void WriteLine(... data);
    void WriteSystemMessage(... data);
    void Clear();
}

shared interface IChatChannelSink
{
    void Send(const string&in text);
}

IChatChannelHook@ AquireChatChannelHook(IChatChannelSink@ sink);
void ReleaseChatChannelHook(IChatChannelHook@ hook);

When the hook is acquired, the plugin should consider that a new chat channel was created, akin to being connected to a server in the current version. Then, the dependant plugin can write incoming messages to the channel by calling methods on the hook and they should be sent to all listeners to display. Conversely, sent text messages will be routed from BC to the external plugin with the channel sink call.

This current implementation was thought out to work like a mutex, so that only one plugin controls the chat at once. Another possibility could be to create a new tab for each created channel to allow multiple channels to exist simultanously.

I have implemented a prototype version to test out how it could work. Some internal refactorings will need to be made to ChatLineInfo to adapt to arbitrary input, then it should be a matter of passing down parameters from ChatWindow and ChatLine.

Geekid812 avatar Jun 30 '23 19:06 Geekid812