2020-12-28 20:28:45 +01:00
|
|
|
import tpl_roster from "./templates/roster.js";
|
2021-07-15 16:36:42 +02:00
|
|
|
import { CustomElement } from 'shared/components/element.js';
|
2020-12-28 18:41:38 +01:00
|
|
|
import { Model } from '@converse/skeletor/src/model.js';
|
2021-07-15 16:16:25 +02:00
|
|
|
import { _converse, api } from "@converse/headless/core";
|
2020-12-28 18:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @namespace _converse.RosterView
|
|
|
|
* @memberOf _converse
|
|
|
|
*/
|
2021-07-15 16:36:42 +02:00
|
|
|
export default class RosterView extends CustomElement {
|
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
async initialize () {
|
|
|
|
await api.waitUntil('rosterInitialized')
|
2021-07-15 16:36:42 +02:00
|
|
|
this.listenTo(_converse, 'rosterContactsFetched', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.presences, 'change:show', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.roster, 'add', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.roster, 'destroy', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.roster, 'remove', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.roster, 'change', this.requestUpdate);
|
|
|
|
this.listenTo(_converse.roster.state, 'change', this.requestUpdate);
|
2021-01-26 14:01:37 +01:00
|
|
|
/**
|
|
|
|
* Triggered once the _converse.RosterView instance has been created and initialized.
|
|
|
|
* @event _converse#rosterViewInitialized
|
|
|
|
* @example _converse.api.listen.on('rosterViewInitialized', () => { ... });
|
|
|
|
*/
|
|
|
|
api.trigger('rosterViewInitialized');
|
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-07-15 16:36:42 +02:00
|
|
|
firstUpdated () {
|
|
|
|
this.listenToRosterFilter();
|
2021-01-26 14:01:37 +01:00
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-07-15 16:36:42 +02:00
|
|
|
render () {
|
|
|
|
return tpl_roster(this);
|
2021-01-26 14:01:37 +01:00
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
listenToRosterFilter () {
|
|
|
|
this.filter_view = this.querySelector('converse-roster-filter');
|
2021-07-15 16:36:42 +02:00
|
|
|
this.filter_view.addEventListener('update', () => this.requestUpdate());
|
2021-01-26 14:01:37 +01:00
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
showAddContactModal (ev) { // eslint-disable-line class-methods-use-this
|
|
|
|
api.modal.show(_converse.AddContactModal, {'model': new Model()}, ev);
|
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
async syncContacts (ev) { // eslint-disable-line class-methods-use-this
|
2020-12-28 18:41:38 +01:00
|
|
|
ev.preventDefault();
|
2021-07-15 16:16:25 +02:00
|
|
|
this.syncing_contacts = true;
|
2021-07-15 16:36:42 +02:00
|
|
|
this.requestUpdate();
|
2021-07-15 16:16:25 +02:00
|
|
|
|
2020-12-28 18:41:38 +01:00
|
|
|
_converse.roster.data.save('version', null);
|
|
|
|
await _converse.roster.fetchFromServer();
|
|
|
|
api.user.presence.send();
|
2021-07-15 16:16:25 +02:00
|
|
|
|
|
|
|
this.syncing_contacts = false;
|
2021-07-15 16:36:42 +02:00
|
|
|
this.requestUpdate();
|
2020-12-28 18:41:38 +01:00
|
|
|
}
|
2021-01-26 14:01:37 +01:00
|
|
|
}
|
2020-12-28 18:41:38 +01:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
api.elements.define('converse-roster', RosterView);
|