mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-30 14:38:31 +00:00
4.0.0-rc13.2
* Fixed: The `chat:pre-send-message` event not being called correctly.
This commit is contained in:
parent
006631b6e0
commit
796da1739a
3 changed files with 169 additions and 27 deletions
|
@ -414,7 +414,15 @@ export default class ChatHook extends Module {
|
|||
|
||||
for(const inst of instances) {
|
||||
inst.client.events.removeAll();
|
||||
|
||||
inst._ffzInstall();
|
||||
|
||||
inst.connectHandlers();
|
||||
|
||||
inst.props.setChatConnectionAPI({
|
||||
sendMessage: inst.sendMessage,
|
||||
_ffz_inst: inst
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -732,6 +740,7 @@ export default class ChatHook extends Module {
|
|||
|
||||
wrapChatService(cls) {
|
||||
const t = this,
|
||||
old_mount = cls.prototype.componentDidMount,
|
||||
old_handler = cls.prototype.connectHandlers;
|
||||
|
||||
cls.prototype._ffz_was_here = true;
|
||||
|
@ -760,6 +769,53 @@ export default class ChatHook extends Module {
|
|||
}
|
||||
|
||||
|
||||
cls.prototype._ffzInstall = function() {
|
||||
if ( this._ffz_installed )
|
||||
return;
|
||||
|
||||
this._ffz_installed = true;
|
||||
|
||||
const inst = this,
|
||||
old_send = this.sendMessage;
|
||||
|
||||
inst.sendMessage = function(raw_msg) {
|
||||
const msg = raw_msg.replace(/\n/g, '');
|
||||
|
||||
if ( msg.startsWith('/ffz') ) {
|
||||
inst.addMessage({
|
||||
type: t.chat_types.Notice,
|
||||
message: 'The /ffz command is not yet re-implemented.'
|
||||
})
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const event = new FFZEvent({
|
||||
message: msg,
|
||||
channel: inst.props.channelLogin
|
||||
});
|
||||
|
||||
t.emit('chat:pre-send-message', event);
|
||||
|
||||
if ( event.defaultPrevented )
|
||||
return;
|
||||
|
||||
return old_send.call(this, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cls.prototype.componentDidMount = function() {
|
||||
try {
|
||||
this._ffzInstall();
|
||||
} catch(err) {
|
||||
t.log.error('Error installing FFZ features onto chat service.', err);
|
||||
}
|
||||
|
||||
return old_mount.call(this);
|
||||
}
|
||||
|
||||
|
||||
cls.prototype.connectHandlers = function(...args) {
|
||||
if ( ! this._ffz_init ) {
|
||||
const i = this;
|
||||
|
@ -775,32 +831,6 @@ export default class ChatHook extends Module {
|
|||
}
|
||||
}
|
||||
|
||||
const old_send = this.sendMessage;
|
||||
this.sendMessage = function(raw_msg) {
|
||||
const msg = raw_msg.replace(/\n/g, '');
|
||||
|
||||
if ( msg.startsWith('/ffz') ) {
|
||||
this.postMessage({
|
||||
type: t.chat_types.Notice,
|
||||
message: 'The /ffz command is not yet re-implemented.'
|
||||
})
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const event = new FFZEvent({
|
||||
message: msg,
|
||||
channel: this.channelLogin
|
||||
});
|
||||
|
||||
t.emit('chat:pre-send-message', event);
|
||||
|
||||
if ( event.defaultPrevented )
|
||||
return;
|
||||
|
||||
return old_send.call(this, msg);
|
||||
}
|
||||
|
||||
const old_chat = this.onChatMessageEvent;
|
||||
this.onChatMessageEvent = function(e) {
|
||||
if ( e && e.sentByCurrentUser ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue