2021-01-26 14:01:37 +01:00
|
|
|
import tpl_group from "./group.js";
|
|
|
|
import { __ } from 'i18n';
|
|
|
|
import { _converse, api } from "@converse/headless/core";
|
|
|
|
import { contactsComparator, groupsComparator } from '@converse/headless/plugins/roster/utils.js';
|
2021-04-14 22:56:59 +02:00
|
|
|
import { html } from "lit";
|
|
|
|
import { repeat } from 'lit/directives/repeat.js';
|
2022-04-14 23:39:01 +02:00
|
|
|
import { shouldShowContact, shouldShowGroup, populateContactsMap } from '../utils.js';
|
2021-01-26 14:01:37 +01:00
|
|
|
|
|
|
|
|
2021-07-15 16:16:25 +02:00
|
|
|
export default (el) => {
|
2021-01-26 14:01:37 +01:00
|
|
|
const i18n_heading_contacts = __('Contacts');
|
|
|
|
const i18n_title_add_contact = __('Add a contact');
|
|
|
|
const i18n_title_sync_contacts = __('Re-sync your contacts');
|
|
|
|
const roster = _converse.roster || [];
|
|
|
|
const contacts_map = roster.reduce((acc, contact) => populateContactsMap(acc, contact), {});
|
|
|
|
const groupnames = Object.keys(contacts_map).filter(shouldShowGroup);
|
|
|
|
groupnames.sort(groupsComparator);
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div class="d-flex controlbox-padded">
|
|
|
|
<span class="w-100 controlbox-heading controlbox-heading--contacts">${i18n_heading_contacts}</span>
|
2021-07-15 16:16:25 +02:00
|
|
|
<a class="controlbox-heading__btn sync-contacts" @click=${ev => el.syncContacts(ev)} title="${i18n_title_sync_contacts}">
|
2022-01-29 11:55:06 +01:00
|
|
|
<converse-icon class="fa fa-sync right ${el.syncing_contacts ? 'fa-spin' : ''}" size="1em"></converse-icon>
|
2021-07-15 16:16:25 +02:00
|
|
|
</a>
|
2021-01-26 14:01:37 +01:00
|
|
|
${ api.settings.get('allow_contact_requests') ? html`
|
2021-07-15 16:16:25 +02:00
|
|
|
<a class="controlbox-heading__btn add-contact"
|
|
|
|
@click=${ev => el.showAddContactModal(ev)}
|
2021-01-26 14:01:37 +01:00
|
|
|
title="${i18n_title_add_contact}"
|
|
|
|
data-toggle="modal"
|
2021-07-15 16:16:25 +02:00
|
|
|
data-target="#add-contact-modal">
|
2022-01-29 11:55:06 +01:00
|
|
|
<converse-icon class="fa fa-user-plus right" size="1.25em"></converse-icon>
|
2021-07-15 16:16:25 +02:00
|
|
|
</a>` : '' }
|
2021-01-26 14:01:37 +01:00
|
|
|
</div>
|
|
|
|
<converse-roster-filter></converse-roster-filter>
|
|
|
|
<div class="list-container roster-contacts">
|
2021-02-06 12:29:56 +01:00
|
|
|
${ repeat(groupnames, n => n, name => {
|
2021-05-12 12:26:16 +02:00
|
|
|
const contacts = contacts_map[name].filter(c => shouldShowContact(c, name));
|
2021-01-26 14:01:37 +01:00
|
|
|
contacts.sort(contactsComparator);
|
|
|
|
if (contacts.length) {
|
|
|
|
return tpl_group({
|
|
|
|
'contacts': contacts,
|
|
|
|
'name': name,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}) }
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|