2019-03-15 10:00:08 +01:00
|
|
|
// Converse.js (A browser based XMPP chat client)
|
|
|
|
// https://conversejs.org
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012-2019, Jan-Carel Brand <jc@opkode.com>
|
|
|
|
// Licensed under the Mozilla Public License (MPLv2)
|
|
|
|
//
|
2019-07-11 10:48:52 +02:00
|
|
|
/**
|
|
|
|
* @module converse-mam-views
|
|
|
|
* @description
|
|
|
|
* Views for XEP-0313 Message Archive Management
|
|
|
|
*/
|
2019-03-15 10:00:08 +01:00
|
|
|
import converse from "@converse/headless/converse-core";
|
2019-05-22 14:03:13 +02:00
|
|
|
import { debounce } from 'lodash'
|
2019-03-15 10:00:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
converse.plugins.add('converse-mam-views', {
|
|
|
|
|
2019-05-22 14:03:13 +02:00
|
|
|
dependencies: ['converse-mam', 'converse-chatview', 'converse-muc-views'],
|
2019-03-15 10:00:08 +01:00
|
|
|
|
|
|
|
overrides: {
|
|
|
|
// Overrides mentioned here will be picked up by converse.js's
|
|
|
|
// plugin architecture they will replace existing methods on the
|
|
|
|
// relevant objects or classes.
|
|
|
|
//
|
|
|
|
// New functions which don't exist yet can also be added.
|
|
|
|
|
2019-05-16 11:41:24 +02:00
|
|
|
ChatBoxView: {
|
|
|
|
render () {
|
|
|
|
const result = this.__super__.render.apply(this, arguments);
|
|
|
|
if (!this.disable_mam) {
|
2019-05-22 14:03:13 +02:00
|
|
|
this.content.addEventListener('scroll', debounce(this.onScroll.bind(this), 100));
|
2019-05-16 11:41:24 +02:00
|
|
|
}
|
|
|
|
return result;
|
2019-03-15 10:00:08 +01:00
|
|
|
},
|
|
|
|
|
2019-10-09 16:01:38 +02:00
|
|
|
async onScroll () {
|
2019-03-15 10:00:08 +01:00
|
|
|
if (this.content.scrollTop === 0 && this.model.messages.length) {
|
2019-08-07 10:47:11 +02:00
|
|
|
const oldest_message = this.model.getOldestMessage();
|
2019-09-06 16:14:30 +02:00
|
|
|
if (oldest_message) {
|
|
|
|
const by_jid = this.model.get('jid');
|
|
|
|
const stanza_id = oldest_message && oldest_message.get(`stanza_id ${by_jid}`);
|
|
|
|
this.addSpinner();
|
|
|
|
if (stanza_id) {
|
|
|
|
await this.model.fetchArchivedMessages({
|
|
|
|
'before': stanza_id
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
await this.model.fetchArchivedMessages({
|
|
|
|
'end': oldest_message.get('time')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.clearSpinner();
|
2019-03-15 10:00:08 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-16 11:41:24 +02:00
|
|
|
}
|
2019-03-15 10:00:08 +01:00
|
|
|
},
|
|
|
|
|
2019-05-16 11:41:24 +02:00
|
|
|
ChatRoomView: {
|
2019-03-15 10:00:08 +01:00
|
|
|
renderChatArea () {
|
|
|
|
const result = this.__super__.renderChatArea.apply(this, arguments);
|
|
|
|
if (!this.disable_mam) {
|
2019-05-22 14:03:13 +02:00
|
|
|
this.content.addEventListener('scroll', debounce(this.onScroll.bind(this), 100));
|
2019-03-15 10:00:08 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|