diff --git a/src/main.js b/src/main.js index 2b751281..1edaba3f 100644 --- a/src/main.js +++ b/src/main.js @@ -149,7 +149,7 @@ ${typeof x[1] === 'string' ? x[1] : JSON.stringify(x[1], null, 4)}` FrankerFaceZ.Logger = Logger; const VER = FrankerFaceZ.version_info = { - major: 4, minor: 0, revision: 0, extra: '-rc19.4', + major: 4, minor: 0, revision: 0, extra: '-rc20', commit: __git_commit__, build: __webpack_hash__, toString: () => diff --git a/src/modules/chat/actions/components/edit-icon.vue b/src/modules/chat/actions/components/edit-icon.vue index 55fce223..0bb3afd5 100644 --- a/src/modules/chat/actions/components/edit-icon.vue +++ b/src/modules/chat/actions/components/edit-icon.vue @@ -94,8 +94,6 @@ const FFZ_ICONS = [ 'lock', 'lock-open', 'arrows-cw', - 'pin', - 'pin-outline', 'gift', 'eyedropper', 'github', diff --git a/src/modules/chat/actions/index.jsx b/src/modules/chat/actions/index.jsx index 93e63aba..4e454f15 100644 --- a/src/modules/chat/actions/index.jsx +++ b/src/modules/chat/actions/index.jsx @@ -90,6 +90,35 @@ export default class Actions extends Module { } }); + this.settings.add('chat.actions.room', { + // Filter out actions + process: (ctx, val) => + val.filter(x => x.type || (x.appearance && + this.renderers[x.appearance.type] && + (! this.renderers[x.appearance.type].load || this.renderers[x.appearance.type].load(x.appearance)) && + (! x.action || this.actions[x.action]) + )), + + default: [], + type: 'array_merge', + ui: { + path: 'Chat > Actions > Room @{"description": "Here, you can define custom actions that will appear above the chat input box."}', + component: 'chat-actions', + context: ['room'], + inline: true, + + data: () => { + const chat = this.resolve('site.chat'); + + return { + color: val => chat && chat.colors ? chat.colors.process(val) : val, + actions: deep_copy(this.actions), + renderers: deep_copy(this.renderers) + } + } + } + }); + this.settings.add('chat.actions.rules-as-reasons', { default: true, ui: { @@ -346,6 +375,56 @@ export default class Actions extends Module { } + renderRoom(mod_icons, current_user, current_room, createElement) { + const actions = [], + chat = this.resolve('site.chat'); + + for(const data of this.parent.context.get('chat.actions.room')) { + if ( ! data || ! data.action || ! data.appearance ) + continue; + + const ap = data.appearance || {}, + disp = data.display || {}, + + def = this.renderers[ap.type]; + + if ( ! def || disp.disabled || + (disp.mod_icons != null && disp.mod_icons !== !!mod_icons) || + (disp.mod != null && disp.mod !== (current_user ? !!current_user.mod : false)) || + (disp.staff != null && disp.staff !== (current_user ? !!current_user.staff : false)) ) + continue; + + const has_color = def.colored && ap.color, + color = has_color && (chat && chat.colors ? chat.colors.process(ap.color) : ap.color), + contents = def.render.call(this, ap, createElement, color); + + actions.push(); + } + + if ( ! actions.length ) + return null; + + const room = current_room && JSON.stringify(current_room); + + return (
+ {actions} +
) + } + + renderInline(msg, mod_icons, current_user, current_room, createElement) { const actions = []; @@ -393,19 +472,17 @@ export default class Actions extends Module { if ( ! actions.length ) return null; - const room = current_room && JSON.stringify(current_room), + /*const room = current_room && JSON.stringify(current_room), user = msg.user && JSON.stringify({ login: msg.user.login, displayName: msg.user.displayName, id: msg.user.id, type: msg.user.type - }); + });*/ return (
{actions}
); @@ -422,19 +499,56 @@ export default class Actions extends Module { if ( ! definition ) return null; - const user = pds && pds.user ? JSON.parse(pds.user) : null, - room = pds && pds.room ? JSON.parse(pds.room) : null, - message_id = pds && pds.msgId, + let user, room, message, loaded = false; - data = { - action, - definition, - tip: ds.tip, - options: ds.options ? JSON.parse(ds.options) : null, - user, - room, - message_id - }; + if ( pds ) { + if ( pds.source === 'line' ) { + const fine = this.resolve('site.fine'), + react = fine && fine.getParent(parent.parentElement), + line = react && react.stateNode; + + if ( line && line.props && line.props.message ) { + loaded = true; + + const msg = line.props.message; + + user = msg.user ? { + color: msg.user.color, + id: msg.user.id, + login: msg.user.login, + displayName: msg.user.displayName, + type: msg.user.type + } : null; + + room = { + login: line.props.channelLogin, + id: line.props.channelID + } + + message = { + id: msg.id, + text: msg.message + } + } + } + + if ( ! loaded ) { + user = pds.user ? JSON.parse(pds.user) : null; + room = pds.room ? JSON.parse(pds.room) : null; + message = pds.message ? JSON.parse(pds.message) : pds.msgId ? {id: pds.msgId} : null; + } + } + + const data = { + action, + definition, + tip: ds.tip, + options: ds.options ? JSON.parse(ds.options) : null, + user, + room, + message, + message_id: message ? message.id : null + }; if ( definition.defaults ) data.options = Object.assign({}, maybe_call(definition.defaults, this, data, element), data.options); diff --git a/src/modules/chat/rich_providers.js b/src/modules/chat/rich_providers.js index 2104f598..9e3ad375 100644 --- a/src/modules/chat/rich_providers.js +++ b/src/modules/chat/rich_providers.js @@ -41,7 +41,7 @@ export const Links = { return { url: token.url, title: this.i18n.t('card.error', 'An error occurred.'), - desc_1: err + desc_1: String(err) } } diff --git a/src/modules/main_menu/components/action-editor.vue b/src/modules/main_menu/components/action-editor.vue index 9e8079e4..1906f946 100644 --- a/src/modules/main_menu/components/action-editor.vue +++ b/src/modules/main_menu/components/action-editor.vue @@ -104,7 +104,7 @@ -
+
@@ -215,7 +215,7 @@ import {has, maybe_call, deep_copy} from 'utilities/object'; export default { - props: ['action', 'data', 'inline'], + props: ['action', 'data', 'inline', 'context'], data() { return { @@ -233,14 +233,30 @@ export default { return this.action.v; }, + has_message() { + return this.context && this.context.includes('message') + }, + vars() { - const out = ['user.login', 'user.displayName', 'user.id', 'user.type']; + const out = [], + ctx = this.context || []; - out.push('room.login') - out.push('room.id'); + if ( ctx.includes('user') ) { + out.push('user.login'); + out.push('user.displayName'); + out.push('user.id'); + out.push('user.type'); + } - if ( this.inline ) - out.push('message_id'); + if ( ctx.includes('room') ) { + out.push('room.login'); + out.push('room.id'); + } + + if ( ctx.includes('message') ) { + out.push('message.id'); + out.push('message.text'); + } return out.map(x => `{{${x}}}`).join(', '); }, diff --git a/src/modules/main_menu/components/chat-actions.vue b/src/modules/main_menu/components/chat-actions.vue index 5539ecff..edc5da91 100644 --- a/src/modules/main_menu/components/chat-actions.vue +++ b/src/modules/main_menu/components/chat-actions.vue @@ -27,7 +27,7 @@
-
+
@@ -169,7 +170,7 @@