Skip to content

Commit

Permalink
New "getOccupantActionButtons" hook, so that plugins can add actions …
Browse files Browse the repository at this point in the history
…on MUC occupants.
  • Loading branch information
JohnXLivingston committed Aug 6, 2024
1 parent 45dd8d9 commit bae7e21
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- New `loadEmojis` hook, to customize emojis at runtime.
- Upgrade to Bootstrap 5
- Fix: removing the "add to contact" button in occupant modal in singleton mode (as there is no roster).
- New "getOccupantActionButtons" hook, so that plugins can add actions on MUC occupants.

### Breaking changes:

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/muc-views/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class MUCSidebar extends CustomElement {
const tpl = tplMUCSidebar(this, Object.assign(
this.model.toJSON(), {
'occupants': [...this.model.occupants.models],
'onOccupantClicked': ev => this.onOccupantClicked(ev),
'onOccupantClicked': ev => this.onOccupantClicked(ev)
}
));
return tpl;
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/muc-views/styles/muc-occupants.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@

.occupant-nick-badge {
display: flex;
justify-content: space-between;
justify-content: flex-start;
flex-wrap: wrap;
align-items: center;

.occupant-badges {
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
flex-direction: row;

margin-left: auto; // this tricks align the item to the right.

span {
height: 1.6em;
margin-right: 0.25rem;
Expand Down
32 changes: 32 additions & 0 deletions src/plugins/muc-views/templates/occupant.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* @typedef {import('@converse/headless').MUCOccupant} MUCOccupant
*/
import { api } from '@converse/headless';
import { PRETTY_CHAT_STATUS } from '../constants.js';
import { __ } from 'i18n';
import { html } from "lit";
import { until } from 'lit/directives/until.js';
import { showOccupantModal } from '../utils.js';
import { getAuthorStyle } from 'utils/color.js';

Expand All @@ -29,6 +31,33 @@ const occupant_title = /** @param {MUCOccupant} o */(o) => {
}
}

/**
* @param {MUCOccupant} o
*/
async function tplActionButtons (o) {
const buttons = await api.hook('getOccupantActionButtons', o, []);
if (!buttons?.length) { return '' }

const items = buttons.map(b => {
return html`
<button class="dropdown-item ${b.button_class}" @click=${b.handler}>
<converse-icon
class="${b.icon_class}"
color="var(--inverse-link-color)"
size="1em"
></converse-icon>&nbsp;${b.i18n_text}
</button>`
});

if (!items.length) {
return ''
}

return html`<converse-dropdown
class="btn btn--transparent btn--standalone dropdown-toggle dropdown-toggle--no-caret"
.items=${items}
></converse-dropdown>`;
}

/**
* @param {MUCOccupant} o
Expand Down Expand Up @@ -80,6 +109,9 @@ export default (o, chat) => {
title="${occupant_title(o)}"
@click=${chat.onOccupantClicked}
style="${getAuthorStyle(o)}">${o.getDisplayName()}</span>
${
until(tplActionButtons(o))
}
<span class="occupant-badges">
${ (affiliation === "owner") ? html`<span class="badge badge-groupchat">${i18n_owner}</span>` : '' }
${ (affiliation === "admin") ? html`<span class="badge badge-info">${i18n_admin}</span>` : '' }
Expand Down

0 comments on commit bae7e21

Please sign in to comment.