Allow getHats method to be overriden (#2308)

This commit is contained in:
Xavi 2020-10-23 14:09:30 +02:00 committed by GitHub
parent 03919b9777
commit 5a4fbe12a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -38,6 +38,7 @@ Soon we'll deprecate the latter, so prepare now.
- #2285: Rename config option `muc_hats_from_vcard` to [muc_hats](https://conversejs.org/docs/html/configuration.html#muc-hats). Now accepts a list instead of a boolean and allows for more flexible choices regarding user badges.
- #2304: Custom emojis (stickers) images not shown
- #2307: BootstrapModal is not accessible to plugins
- #2308: Allow getHats method to be overriden in the `overrides` object in plugins.
- The `trusted` configuration setting has been removed in favor of two new settings:
[allow_user_trust_override](https://conversejs.org/docs/html/configuration.html#allow-user-trust-override)
[clear_cache_on_logout](https://conversejs.org/docs/html/configuration.html#clear-cache-on-logout)

View File

@ -3,7 +3,7 @@ import dayjs from 'dayjs';
import tpl_new_day from "../templates//new_day.js";
import { CustomElement } from './element.js';
import { __ } from '../i18n';
import { api } from "@converse/headless/converse-core";
import { _converse, api } from "@converse/headless/converse-core";
import { html } from 'lit-element';
import { repeat } from 'lit-html/directives/repeat.js';
@ -67,8 +67,10 @@ function getDayIndicator (model) {
});
}
}
function getHats (model) {
// This is set to _converse so that it can be overriden. An attempt was made to use
// a hook instead, but hook returns a promise and it forces the asynchronicity up
// to the render method.
_converse.getHats = function (model) {
if (model.get('type') === 'groupchat') {
const allowed_hats = api.settings.get('muc_hats').filter(hat => hat).map((hat) => (hat.toLowerCase()));
let vcard_roles = []
@ -93,7 +95,7 @@ export function getDerivedMessageProps (chatbox, model) {
const is_groupchat = model.get('type') === 'groupchat';
return {
'has_mentions': is_groupchat && model.get('sender') === 'them' && chatbox.isUserMentioned(model),
'hats': getHats(model),
'hats': _converse.getHats(model),
'is_first_unread': chatbox.get('first_unread_id') === model.get('id'),
'is_me_message': model.isMeCommand(),
'is_retracted': model.get('retracted') || model.get('moderated') === 'retracted',