Rename getMessageAttributesFromStanza to parseMessage

This commit is contained in:
JC Brand 2020-04-13 15:20:51 +02:00
parent fef5292a12
commit ce1f7e090e
5 changed files with 24 additions and 24 deletions

View File

@ -169,10 +169,10 @@ converse.plugins.add('converse-omemo', {
}, },
ChatBox: { ChatBox: {
async getMessageAttributesFromStanza (stanza, original_stanza) { async parseMessage (stanza, original_stanza) {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const encrypted = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, original_stanza).pop(), const encrypted = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, original_stanza).pop(),
attrs = await this.__super__.getMessageAttributesFromStanza.apply(this, arguments); attrs = await this.__super__.parseMessage.apply(this, arguments);
if (!encrypted || !_converse.config.get('trusted')) { if (!encrypted || !_converse.config.get('trusted')) {
return attrs; return attrs;

View File

@ -9,7 +9,7 @@ import { Model } from 'skeletor.js/src/model.js';
import converse from "./converse-core"; import converse from "./converse-core";
import filesize from "filesize"; import filesize from "filesize";
import log from "./log"; import log from "./log";
import stanza_utils from "./utils/stanza"; import st from "./utils/stanza";
const { $msg, Strophe, sizzle, utils } = converse.env; const { $msg, Strophe, sizzle, utils } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
@ -411,7 +411,7 @@ converse.plugins.add('converse-chat', {
}, },
async onMessage (stanza, original_stanza, from_jid) { async onMessage (stanza, original_stanza, from_jid) {
const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza); const attrs = await this.parseMessage(stanza, original_stanza);
const message = this.getDuplicateMessage(attrs); const message = this.getDuplicateMessage(attrs);
if (message) { if (message) {
this.updateMessage(message, original_stanza); this.updateMessage(message, original_stanza);
@ -527,7 +527,7 @@ converse.plugins.add('converse-chat', {
getUpdatedMessageAttributes (message, stanza) { // eslint-disable-line no-unused-vars getUpdatedMessageAttributes (message, stanza) { // eslint-disable-line no-unused-vars
return { return {
'is_archived': stanza_utils.isArchived(stanza), 'is_archived': st.isArchived(stanza),
} }
}, },
@ -610,7 +610,7 @@ converse.plugins.add('converse-chat', {
* @private * @private
* @method _converse.ChatBox#findDanglingRetraction * @method _converse.ChatBox#findDanglingRetraction
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns { _converse.Message } * @returns { _converse.Message }
*/ */
findDanglingRetraction (attrs) { findDanglingRetraction (attrs) {
@ -637,7 +637,7 @@ converse.plugins.add('converse-chat', {
* @private * @private
* @method _converse.ChatBox#handleRetraction * @method _converse.ChatBox#handleRetraction
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns { Boolean } Returns `true` or `false` depending on * @returns { Boolean } Returns `true` or `false` depending on
* whether a message was retracted or not. * whether a message was retracted or not.
*/ */
@ -677,7 +677,7 @@ converse.plugins.add('converse-chat', {
* @private * @private
* @method _converse.ChatBox#handleCorrection * @method _converse.ChatBox#handleCorrection
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns { _converse.Message|undefined } Returns the corrected * @returns { _converse.Message|undefined } Returns the corrected
* message or `undefined` if not applicable. * message or `undefined` if not applicable.
*/ */
@ -710,7 +710,7 @@ converse.plugins.add('converse-chat', {
* @private * @private
* @method _converse.ChatBox#getDuplicateMessage * @method _converse.ChatBox#getDuplicateMessage
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns {Promise<_converse.Message>} * @returns {Promise<_converse.Message>}
*/ */
getDuplicateMessage (attrs) { getDuplicateMessage (attrs) {
@ -1084,17 +1084,17 @@ converse.plugins.add('converse-chat', {
/** /**
* Parses a passed in message stanza and returns an object of attributes. * Parses a passed in message stanza and returns an object of attributes.
* @private * @private
* @method _converse.ChatBox#getMessageAttributesFromStanza * @method _converse.ChatBox#parseMessage
* @param { XMLElement } stanza - The message stanza * @param { XMLElement } stanza - The message stanza
* @param { XMLElement } original_stanza - The original stanza, that contains the * @param { XMLElement } original_stanza - The original stanza, that contains the
* message stanza, if it was contained, otherwise it's the message stanza itself. * message stanza, if it was contained, otherwise it's the message stanza itself.
* @returns { Object } * @returns { Object }
*/ */
getMessageAttributesFromStanza (stanza, original_stanza) { parseMessage (stanza, original_stanza) {
// XXX: Eventually we want to get rid of this pass-through // XXX: Eventually we want to get rid of this pass-through
// method but currently we still need it because converse-omemo // method but currently we still need it because converse-omemo
// overrides it. // overrides it.
return stanza_utils.getMessageAttributesFromStanza(stanza, original_stanza, this, _converse); return st.parseMessage(stanza, original_stanza, this, _converse);
}, },
maybeShow () { maybeShow () {
@ -1169,7 +1169,7 @@ converse.plugins.add('converse-chat', {
if (!should_show) { if (!should_show) {
return; return;
} }
const attrs = await chatbox.getMessageAttributesFromStanza(stanza, stanza); const attrs = await chatbox.parseMessage(stanza, stanza);
await chatbox.createMessage(attrs); await chatbox.createMessage(attrs);
} }

View File

@ -99,7 +99,7 @@ converse.plugins.add('converse-headlines', {
'type': _converse.HEADLINES_TYPE, 'type': _converse.HEADLINES_TYPE,
'from': from_jid 'from': from_jid
}); });
const attrs = await chatbox.getMessageAttributesFromStanza(message, message); const attrs = await chatbox.parseMessage(message, message);
await chatbox.createMessage(attrs); await chatbox.createMessage(attrs);
api.trigger('message', {'chatbox': chatbox, 'stanza': message}); api.trigger('message', {'chatbox': chatbox, 'stanza': message});
} }

View File

@ -13,7 +13,7 @@ import { clone, debounce, intersection, invoke, isElement, isObject, isString, p
import converse from "./converse-core"; import converse from "./converse-core";
import log from "./log"; import log from "./log";
import muc_utils from "./utils/muc"; import muc_utils from "./utils/muc";
import stanza_utils from "./utils/stanza"; import st from "./utils/stanza";
import u from "./utils/form"; import u from "./utils/form";
converse.MUC_TRAFFIC_STATES = ['entered', 'exited']; converse.MUC_TRAFFIC_STATES = ['entered', 'exited'];
@ -1566,7 +1566,7 @@ converse.plugins.add('converse-muc', {
* @param { XMLElement } pres - The presence stanza * @param { XMLElement } pres - The presence stanza
*/ */
updateOccupantsOnPresence (pres) { updateOccupantsOnPresence (pres) {
const data = this.parsePresence(pres); const data = st.parseMUCPresenceStanza(pres);
if (data.type === 'error' || (!data.jid && !data.nick)) { if (data.type === 'error' || (!data.jid && !data.nick)) {
return true; return true;
} }
@ -1703,7 +1703,7 @@ converse.plugins.add('converse-muc', {
* @private * @private
* @method _converse.ChatRoom#handleSubjectChange * @method _converse.ChatRoom#handleSubjectChange
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
*/ */
async handleSubjectChange (attrs) { async handleSubjectChange (attrs) {
if (isString(attrs.subject) && !attrs.thread && !attrs.message) { if (isString(attrs.subject) && !attrs.thread && !attrs.message) {
@ -1861,7 +1861,7 @@ converse.plugins.add('converse-muc', {
* @private * @private
* @method _converse.ChatRoom#findDanglingModeration * @method _converse.ChatRoom#findDanglingModeration
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns { _converse.ChatRoomMessage } * @returns { _converse.ChatRoomMessage }
*/ */
findDanglingModeration (attrs) { findDanglingModeration (attrs) {
@ -1892,7 +1892,7 @@ converse.plugins.add('converse-muc', {
* @private * @private
* @method _converse.ChatRoom#handleModeration * @method _converse.ChatRoom#handleModeration
* @param { object } attrs - Attributes representing a received * @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza} * message, as returned by {@link st.parseMessage}
* @returns { Boolean } Returns `true` or `false` depending on * @returns { Boolean } Returns `true` or `false` depending on
* whether a message was moderated or not. * whether a message was moderated or not.
*/ */
@ -2026,14 +2026,14 @@ converse.plugins.add('converse-muc', {
await this.createInfoMessages(stanza); await this.createInfoMessages(stanza);
this.fetchFeaturesIfConfigurationChanged(stanza); this.fetchFeaturesIfConfigurationChanged(stanza);
const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza); const attrs = await this.parseMessage(stanza, original_stanza);
const message = this.getDuplicateMessage(attrs); const message = this.getDuplicateMessage(attrs);
if (message) { if (message) {
this.updateMessage(message, original_stanza); this.updateMessage(message, original_stanza);
} }
if (message || if (message ||
stanza_utils.isReceipt(stanza) || st.isReceipt(stanza) ||
stanza_utils.isChatMarker(stanza) || st.isChatMarker(stanza) ||
this.ignorableCSN(attrs)) { this.ignorableCSN(attrs)) {
return api.trigger('message', {'stanza': original_stanza}); return api.trigger('message', {'stanza': original_stanza});
} }

View File

@ -284,7 +284,7 @@ const stanza_utils = {
/** /**
* Parses a passed in message stanza and returns an object of attributes. * Parses a passed in message stanza and returns an object of attributes.
* @private * @private
* @method stanza_utils#getMessageAttributesFromStanza * @method stanza_utils#parseMessage
* @param { XMLElement } stanza - The message stanza * @param { XMLElement } stanza - The message stanza
* @param { XMLElement } original_stanza - The original stanza, that contains the * @param { XMLElement } original_stanza - The original stanza, that contains the
* message stanza, if it was contained, otherwise it's the message stanza itself. * message stanza, if it was contained, otherwise it's the message stanza itself.
@ -292,7 +292,7 @@ const stanza_utils = {
* @param { _converse } _converse * @param { _converse } _converse
* @returns { Object } * @returns { Object }
*/ */
getMessageAttributesFromStanza (stanza, original_stanza, chatbox, _converse) { parseMessage (stanza, original_stanza, chatbox, _converse) {
const is_muc = u.isChatRoom(chatbox); const is_muc = u.isChatRoom(chatbox);
let attrs = Object.assign( let attrs = Object.assign(
stanza_utils.getStanzaIDs(stanza, original_stanza), stanza_utils.getStanzaIDs(stanza, original_stanza),