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'; import { html } from "lit"; import { repeat } from 'lit/directives/repeat.js'; import { shouldShowContact, shouldShowGroup, populateContactsMap } from '../utils.js'; export default (el) => { 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`
${i18n_heading_contacts} el.syncContacts(ev)} title="${i18n_title_sync_contacts}"> ${ api.settings.get('allow_contact_requests') ? html` el.showAddContactModal(ev)} title="${i18n_title_add_contact}" data-toggle="modal" data-target="#add-contact-modal"> ` : '' }
${ repeat(groupnames, n => n, name => { const contacts = contacts_map[name].filter(c => shouldShowContact(c, name)); contacts.sort(contactsComparator); if (contacts.length) { return tpl_group({ 'contacts': contacts, 'name': name, }); } else { return ''; } }) }
`; }