|
@@ -1,5 +1,5 @@
|
|
/**
|
|
/**
|
|
- * @copyright 2020, the Converse.js contributors
|
|
|
|
|
|
+ * @copyright The Converse.js contributors
|
|
* @license Mozilla Public License (MPLv2)
|
|
* @license Mozilla Public License (MPLv2)
|
|
* @description This is the core utilities module.
|
|
* @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 { Strophe } from 'strophe.js/src/strophe.js';
|
|
import { getOpenPromise } from '@converse/openpromise';
|
|
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
|
|
* The utils object
|
|
* @namespace u
|
|
* @namespace u
|
|
@@ -125,32 +136,13 @@ u.isNewMessage = function (message) {
|
|
|
|
|
|
u.shouldCreateMessage = function (attrs) {
|
|
u.shouldCreateMessage = function (attrs) {
|
|
return attrs['retracted'] || // Retraction received *before* the message
|
|
return attrs['retracted'] || // Retraction received *before* the message
|
|
- !u.isEmptyMessage(attrs);
|
|
|
|
|
|
+ !isEmptyMessage(attrs);
|
|
}
|
|
}
|
|
|
|
|
|
u.shouldCreateGroupchatMessage = function (attrs) {
|
|
u.shouldCreateGroupchatMessage = function (attrs) {
|
|
return attrs.nick && (u.shouldCreateMessage(attrs) || attrs.is_tombstone);
|
|
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) {
|
|
u.isChatRoom = function (model) {
|
|
return model && (model.get('type') === 'chatroom');
|
|
return model && (model.get('type') === 'chatroom');
|
|
}
|
|
}
|
|
@@ -578,4 +570,6 @@ export function decodeHTMLEntities (str) {
|
|
return str;
|
|
return str;
|
|
}
|
|
}
|
|
|
|
|
|
-export default u;
|
|
|
|
|
|
+export default Object.assign({
|
|
|
|
+ isEmptyMessage
|
|
|
|
+}, u);
|