Support displaying spoilers
This adds support for displaying recieved spoilers, but not sending them. Spoilers are displayed as a black rectangle, and can be clicked on to be revealed. If the last message in a channel was a spoiler, it is not shown on the left sidebar. The spoiler blackening is done in CSS, but to check if a message contains a spoiler for determining if it should cause a different cursor to be displayed and if it should be shown in the sidebar, a simple check of if the message contains "data-mx-spoiler" is used.
This commit is contained in:
@@ -147,6 +147,19 @@ const RoomMessageEvent *NeoChatRoom::lastEvent(bool ignoreStateEvent) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool NeoChatRoom::lastEventIsSpoiler() const
|
||||
{
|
||||
if (auto event = lastEvent()) {
|
||||
if (auto e = eventCast<const RoomMessageEvent>(event)) {
|
||||
if (e->hasTextContent() && e->content() && e->mimeType().name() == "text/html") {
|
||||
auto htmlBody = static_cast<const Quotient::EventContent::TextContent *>(e->content())->body;
|
||||
return htmlBody.contains("data-mx-spoiler");
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString NeoChatRoom::lastEventToString() const
|
||||
{
|
||||
if (auto event = lastEvent()) {
|
||||
|
||||
@@ -47,8 +47,15 @@ public:
|
||||
/// Convenient way to get the last event but in a string format.
|
||||
///
|
||||
/// \see lastEvent
|
||||
/// \see lastEventIsSpoiler
|
||||
[[nodiscard]] QString lastEventToString() const;
|
||||
|
||||
/// Convenient way to check if the last event looks like it has spoilers.
|
||||
///
|
||||
/// \see lastEvent
|
||||
/// \see lastEventToString
|
||||
[[nodiscard]] bool lastEventIsSpoiler() const;
|
||||
|
||||
/// Convenient way to get the QDateTime of the last event.
|
||||
///
|
||||
/// \see lastEvent
|
||||
|
||||
@@ -364,6 +364,9 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
||||
return room->highlightCount();
|
||||
}
|
||||
if (role == LastEventRole) {
|
||||
if (room->lastEventIsSpoiler()) {
|
||||
return QString();
|
||||
}
|
||||
return room->lastEventToString();
|
||||
}
|
||||
if (role == LastActiveTimeRole) {
|
||||
|
||||
Reference in New Issue
Block a user