Add new message action to pin and unpin messages in rooms

Self-explanatory, now you can manage pinned messages in NeoChat alone.
This commit is contained in:
Joshua Goins
2025-02-21 18:11:20 -05:00
parent 9811c0d97a
commit 2861eb9c60
5 changed files with 48 additions and 0 deletions

View File

@@ -1751,4 +1751,23 @@ ThreadModel *NeoChatRoom::modelForThread(const QString &threadRootId)
return m_threadModels[threadRootId].get();
}
void NeoChatRoom::pinEvent(const QString &eventId)
{
auto eventIds = pinnedEventIds();
eventIds.push_back(eventId);
setPinnedEvents(eventIds);
}
void NeoChatRoom::unpinEvent(const QString &eventId)
{
auto eventIds = pinnedEventIds();
eventIds.removeAll(eventId);
setPinnedEvents(eventIds);
}
bool NeoChatRoom::isEventPinned(const QString &eventId) const
{
return pinnedEventIds().contains(eventId);
}
#include "moc_neochatroom.cpp"

View File

@@ -601,6 +601,23 @@ public:
*/
Q_INVOKABLE ThreadModel *modelForThread(const QString &threadRootId);
/**
* @brief Pin a message in the room.
* @param eventId The id of the event to pin.
*/
Q_INVOKABLE void pinEvent(const QString &eventId);
/**
* @brief Unpin a message in the room.
* @param eventId The id of the event to unpin.
*/
Q_INVOKABLE void unpinEvent(const QString &eventId);
/**
* @return True if @p eventId is pinned in the room.
*/
Q_INVOKABLE bool isEventPinned(const QString &eventId) const;
private:
bool m_visible = false;

View File

@@ -132,6 +132,15 @@ KirigamiComponents.ConvergentContextMenu {
}
}
component PinMessageAction: Kirigami.Action {
readonly property bool pinned: currentRoom.isEventPinned(root.eventId)
visible: currentRoom.canSendState("m.room.pinned_events")
text: pinned ? i18nc("@action:button 'Unpin' as in 'Unpin this message'", "Unpin") : i18nc("@action:button 'Pin' as in 'Pin the message in the room'", "Pin")
icon.name: pinned ? "window-unpin-symbolic" : "pin-symbolic"
onTriggered: pinned ? currentRoom.unpinEvent(root.eventId) : currentRoom.pinEvent(root.eventId)
}
headerContentItem: RowLayout {
spacing: Kirigami.Units.largeSpacing

View File

@@ -90,6 +90,8 @@ DelegateContextMenu {
}
}
DelegateContextMenu.PinMessageAction {}
DelegateContextMenu.ReportMessageAction {}
DelegateContextMenu.ShowUserAction {}

View File

@@ -86,6 +86,7 @@ DelegateContextMenu {
Kirigami.Action {
separator: true
}
DelegateContextMenu.PinMessageAction {}
DelegateContextMenu.ReportMessageAction {}
DelegateContextMenu.ShowUserAction {}
Kirigami.Action {