Get rid of unnecessary specificity and functions

This commit is contained in:
JC Brand 2021-09-09 11:19:34 +02:00
parent ef2c206507
commit 906a606010
2 changed files with 20 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/**
* @copyright 2020, the Converse.js contributors
* @copyright The Converse.js contributors
* @license Mozilla Public License (MPLv2)
* @description This is the core utilities module.
*/
@ -15,6 +15,17 @@ import { Model } from '@converse/skeletor/src/model.js';
import { Strophe } from 'strophe.js/src/strophe.js';
import { getOpenPromise } from '@converse/openpromise';
export function isEmptyMessage (attrs) {
if (attrs instanceof Model) {
attrs = attrs.attributes;
}
return !attrs['oob_url'] &&
!attrs['file'] &&
!(attrs['is_encrypted'] && attrs['plaintext']) &&
!attrs['message'];
}
/**
* The utils object
* @namespace u
@ -125,32 +136,13 @@ u.isNewMessage = function (message) {
u.shouldCreateMessage = function (attrs) {
return attrs['retracted'] || // Retraction received *before* the message
!u.isEmptyMessage(attrs);
!isEmptyMessage(attrs);
}
u.shouldCreateGroupchatMessage = function (attrs) {
return attrs.nick && (u.shouldCreateMessage(attrs) || attrs.is_tombstone);
}
u.isEmptyMessage = function (attrs) {
if (attrs instanceof Model) {
attrs = attrs.attributes;
}
return !attrs['oob_url'] &&
!attrs['file'] &&
!(attrs['is_encrypted'] && attrs['plaintext']) &&
!attrs['message'];
};
//TODO: Remove
u.isOnlyChatStateNotification = function (attrs) {
return attrs['chat_state'] && u.isEmptyMessage(attrs);
};
u.isOnlyMessageDeliveryReceipt = function (attrs) {
return attrs['received'] && u.isEmptyMessage(attrs);
};
u.isChatRoom = function (model) {
return model && (model.get('type') === 'chatroom');
}
@ -578,4 +570,6 @@ export function decodeHTMLEntities (str) {
return str;
}
export default u;
export default Object.assign({
isEmptyMessage
}, u);

View File

@ -1,9 +1,10 @@
import Favico from 'favico.js-slevomat';
import log from '@converse/headless/log';
import { __ } from 'i18n';
import { _converse, api, converse } from '@converse/headless/core';
import { _converse, api, converse } from '@converse/headless/core.js';
import { isEmptyMessage } from '@converse/headless/utils/core.js';
const { Strophe, u } = converse.env;
const { Strophe } = converse.env;
const supports_html5_notification = 'Notification' in window;
converse.env.Favico = Favico;
@ -132,8 +133,7 @@ function shouldNotifyOfMessage (data) {
}
const is_me = Strophe.getBareJidFromJid(attrs.from) === _converse.bare_jid;
return (
!u.isOnlyChatStateNotification(attrs) &&
!u.isOnlyMessageDeliveryReceipt(attrs) &&
!isEmptyMessage(attrs) &&
!is_me &&
(api.settings.get('show_desktop_notifications') === 'all' || isMessageToHiddenChat(attrs))
);