1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-05 18:48:31 +00:00

4.0.0-rc13.2

* Fixed: The `chat:pre-send-message` event not being called correctly.
This commit is contained in:
SirStendec 2018-10-14 13:12:51 -04:00
parent 006631b6e0
commit 796da1739a
3 changed files with 169 additions and 27 deletions

View file

@ -100,7 +100,7 @@ class FrankerFaceZ extends Module {
FrankerFaceZ.Logger = Logger; FrankerFaceZ.Logger = Logger;
const VER = FrankerFaceZ.version_info = { const VER = FrankerFaceZ.version_info = {
major: 4, minor: 0, revision: 0, extra: '-rc13.1', major: 4, minor: 0, revision: 0, extra: '-rc13.2',
commit: __git_commit__, commit: __git_commit__,
build: __webpack_hash__, build: __webpack_hash__,
toString: () => toString: () =>

View file

@ -0,0 +1,112 @@
<template lang="html">
<div
:class="{inherits: isInherited, default: isDefault}"
class="ffz--widget ffz--select-box"
>
<div class="tw-flex tw-align-items-start">
<label :for="item.full_key" class="tw-mg-y-05">
{{ t(item.i18n_key, item.title, item) }}
</label>
<div class="tw-flex tw-flex-column tw-mg-05">
<select
ref="control"
:id="item.full_key"
class="tw-border-radius-medium tw-font-size-6 tw-select tw-pd-l-1 tw-pd-r-3 tw-pd-y-05"
@change="onChange"
>
<option
v-for="i in data"
:key="i.value"
:selected="i.value === value"
>
{{ i.i18n_key ? t(i.i18n_key, i.title, i) : i.title }}
</option>
<option :selected="isCustom">
{{ t('setting.combo-box.custom', 'Custom') }}
</option>
</select>
<input
ref="text"
:value="value"
:disabled="! isCustom"
class="tw-border-radius-medium tw-font-size-6 tw-pd-x-1 tw-pd-y-05 tw-input"
@change="onTextChange"
>
</div>
<button
v-if="source && source !== profile"
class="tw-mg-l-05 tw-mg-y-05 tw-button tw-button--text"
@click="context.currentProfile = source"
>
<span class="tw-button__text ffz-i-right-dir">
{{ sourceDisplay }}
</span>
</button>
<button v-if="has_value" class="tw-mg-l-05 tw-mg-y-05 tw-button tw-button--text tw-tooltip-wrapper" @click="clear">
<span class="tw-button__text ffz-i-cancel" />
<div class="tw-tooltip tw-tooltip--down tw-tooltip--align-right">
{{ t('setting.reset', 'Reset to Default') }}
</div>
</button>
</div>
<section
v-if="item.description"
class="tw-c-text-alt-2"
>
<markdown :source="t(item.desc_i18n_key || `${item.i18n_key}.description`, item.description, item)" />
</section>
</div>
</template>
<script>
import SettingMixin from '../setting-mixin';
export default {
mixins: [SettingMixin],
props: ['item', 'context'],
data() {
return {
isCustom: false
}
},
watch: {
value(val) {
for(const item of this.data)
if ( item.value === val )
return;
this.isCustom = true;
},
has_value() {
if ( ! this.has_value )
this.isCustom = false;
}
},
methods: {
onChange() {
const idx = this.$refs.control.selectedIndex,
raw_value = this.data[idx];
if ( raw_value ) {
this.set(raw_value.value);
this.isCustom = false;
} else
this.isCustom = true;
},
onTextChange() {
const value = this.$refs.text.value;
if ( value != null )
this.set(value);
}
}
}
</script>

View file

@ -414,7 +414,15 @@ export default class ChatHook extends Module {
for(const inst of instances) { for(const inst of instances) {
inst.client.events.removeAll(); inst.client.events.removeAll();
inst._ffzInstall();
inst.connectHandlers(); inst.connectHandlers();
inst.props.setChatConnectionAPI({
sendMessage: inst.sendMessage,
_ffz_inst: inst
});
} }
}); });
@ -732,6 +740,7 @@ export default class ChatHook extends Module {
wrapChatService(cls) { wrapChatService(cls) {
const t = this, const t = this,
old_mount = cls.prototype.componentDidMount,
old_handler = cls.prototype.connectHandlers; old_handler = cls.prototype.connectHandlers;
cls.prototype._ffz_was_here = true; 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) { cls.prototype.connectHandlers = function(...args) {
if ( ! this._ffz_init ) { if ( ! this._ffz_init ) {
const i = this; 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; const old_chat = this.onChatMessageEvent;
this.onChatMessageEvent = function(e) { this.onChatMessageEvent = function(e) {
if ( e && e.sentByCurrentUser ) { if ( e && e.sentByCurrentUser ) {