Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New "getOccupantActionButtons" hook, so that plugins can add actions on MUC occupants. #3475

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Upgrade to Bootstrap 5
- Add a new theme 'Cyberpunk' and remove the old 'Concord' theme.
- Improved accessibility.
- 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
17 changes: 15 additions & 2 deletions src/plugins/muc-views/styles/muc-occupants.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,32 @@
.occupant-nick-badge {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
flex-wrap: nowrap;
align-items: center;
gap: 0.25rem;

.occupant-nick {
flex-grow: 2;
}

.occupant-badges {
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
flex-direction: row;
flex-shrink: 1;
gap: 0.25rem;

span {
height: 1.6em;
margin-right: 0.25rem;
}
}

.occupant-actions {
// We must specify the position, else there is a bug:
// clicking on an action would close the dropdown without triggering the action.
position: static;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks hacky, do you know the underlying cause why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry, i did not understand. I spent 2 hours to find why the dropdown was not displaying correctly when using classes like dropstart (or no class at all).
I finally found that adding a position: static was correcting the issue.

Copy link
Contributor Author

@JohnXLivingston JohnXLivingston Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... I just tested again without this patch... And now it is working! (position: static is the default, even without these lines... i did not have the same result yesterday...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry. I'm not quite awake yet, it wasn't a display bug, but a bug on the click handler. The bug is still there when I remove these lines. And yet, position: static is the default, so it should not change anything...

}
}

div.row.g-0{
Expand Down
44 changes: 44 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,45 @@ const occupant_title = /** @param {MUCOccupant} o */(o) => {
}
}

/**
* @param {MUCOccupant} o
*/
async function tplActionButtons (o) {
/**
* *Hook* which allows plugins to add action buttons on occupants
* @event _converse#getOccupantActionButtons
* @example
* api.listen.on('getOccupantActionButtons', (el, buttons) => {
* buttons.push({
* 'i18n_text': 'Foo',
* 'handler': ev => alert('Foo!'),
* 'button_class': 'chat-occupant__action-foo',
* 'icon_class': 'fa fa-check',
* 'name': 'foo'
* });
* return buttons;
* });
*/
const buttons = await api.hook('getOccupantActionButtons', o, []);
JohnXLivingston marked this conversation as resolved.
Show resolved Hide resolved
if (!buttons?.length) { return '' }

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

return html`<converse-dropdown
class="occupant-actions chatbox-btn"
.items=${items}
></converse-dropdown>`;
}

/**
* @param {MUCOccupant} o
Expand Down Expand Up @@ -87,6 +128,9 @@ export default (o, chat) => {
${ (role === "moderator") ? html`<span class="badge badge-info">${i18n_moderator}</span>` : '' }
${ (role === "visitor") ? html`<span class="badge badge-secondary">${i18n_visitor}</span>` : '' }
</span>
${
until(tplActionButtons(o))
}
</div>
</div>
</li>
Expand Down
Loading