Allow opening message menus for out-of-room events
These are more common than we thought, good examples are pinned or searched messages - which are not going to be in the room's history unless you happen to have them loaded. But currently our message menu infrastructure expects them to be, since its looked up by the room + event ID. To fix this is simple, we now move the job of finding the event to the caller which may use a model instead. I didn't fix all existing call-sites yet, mainly the message menu opening one since that was the most obvious bug. But this opens up the door for other assumptions about room history to be fixed too. I had to do a bit of C++ re-jiggering in order to expose useful functions to QML.
This commit is contained in:
@@ -282,26 +282,20 @@ void RoomManager::viewEventSource(const QString &eventId)
|
||||
Q_EMIT showEventSource(eventId);
|
||||
}
|
||||
|
||||
void RoomManager::viewEventMenu(const QString &eventId, NeoChatRoom *room, const QString &selectedText, const QString &hoveredLink)
|
||||
void RoomManager::viewEventMenu(const RoomEvent *event, NeoChatRoom *room, const QString &selectedText, const QString &hoveredLink)
|
||||
{
|
||||
if (eventId.isEmpty()) {
|
||||
qWarning() << "Tried to open event menu with empty event id";
|
||||
if (!event) {
|
||||
qWarning() << "Tried to open event menu with empty event";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto it = room->findInTimeline(eventId);
|
||||
if (it == room->historyEdge()) {
|
||||
// This is probably a pending event
|
||||
return;
|
||||
}
|
||||
const auto &event = **it;
|
||||
Q_EMIT showDelegateMenu(eventId,
|
||||
room->qmlSafeMember(event.senderId()),
|
||||
MessageComponentType::typeForEvent(event),
|
||||
EventHandler::plainBody(room, &event),
|
||||
EventHandler::richBody(room, &event),
|
||||
EventHandler::mediaInfo(room, &event)["mimeType"_L1].toString(),
|
||||
room->fileTransferInfo(eventId),
|
||||
Q_EMIT showDelegateMenu(event->id(),
|
||||
room->qmlSafeMember(event->senderId()),
|
||||
MessageComponentType::typeForEvent(*event),
|
||||
EventHandler::plainBody(room, event),
|
||||
EventHandler::richBody(room, event),
|
||||
EventHandler::mediaInfo(room, event)["mimeType"_L1].toString(),
|
||||
room->fileTransferInfo(event->id()),
|
||||
selectedText,
|
||||
hoveredLink);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user