Move the function to get a subtitle string to eventhandler
This commit is contained in:
@@ -645,6 +645,15 @@ QString EventHandler::getGenericBody() const
|
||||
i18n("Unknown event"));
|
||||
}
|
||||
|
||||
QString EventHandler::subtitleText() const
|
||||
{
|
||||
if (m_event == nullptr) {
|
||||
qCWarning(EventHandling) << "subtitleText called with m_event set to nullptr.";
|
||||
return {};
|
||||
}
|
||||
return singleLineAuthorDisplayname() + (m_event->isStateEvent() ? QLatin1String(" ") : QLatin1String(": ")) + getPlainBody(true);
|
||||
}
|
||||
|
||||
QVariantMap EventHandler::getMediaInfo() const
|
||||
{
|
||||
if (m_room == nullptr) {
|
||||
|
||||
@@ -206,6 +206,14 @@ public:
|
||||
*/
|
||||
QString getGenericBody() const;
|
||||
|
||||
/**
|
||||
* @brief Output a string for the event to be used as a RoomList subtitle.
|
||||
*
|
||||
* The output includes the username followed by the plain message, all with no
|
||||
* line breaks.
|
||||
*/
|
||||
QString subtitleText() const;
|
||||
|
||||
/**
|
||||
* @brief Return the media info for the event.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "roomlistmodel.h"
|
||||
|
||||
#include "controller.h"
|
||||
#include "eventhandler.h"
|
||||
#include "neochatconfig.h"
|
||||
#include "neochatroom.h"
|
||||
#include "roommanager.h"
|
||||
@@ -351,7 +352,10 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
||||
if (room->lastEventIsSpoiler()) {
|
||||
return QString();
|
||||
}
|
||||
return room->lastEventToString(Qt::PlainText, true);
|
||||
EventHandler eventHandler;
|
||||
eventHandler.setRoom(room);
|
||||
eventHandler.setEvent(room->lastEvent());
|
||||
return eventHandler.subtitleText();
|
||||
}
|
||||
if (role == AvatarImageRole) {
|
||||
return room->avatar(128);
|
||||
|
||||
@@ -341,25 +341,6 @@ bool NeoChatRoom::lastEventIsSpoiler() const
|
||||
return false;
|
||||
}
|
||||
|
||||
QString NeoChatRoom::lastEventToString(Qt::TextFormat format, bool stripNewlines) const
|
||||
{
|
||||
if (auto event = lastEvent()) {
|
||||
EventHandler eventHandler;
|
||||
eventHandler.setRoom(this);
|
||||
eventHandler.setEvent(event);
|
||||
|
||||
QString body;
|
||||
if (format == Qt::TextFormat::RichText) {
|
||||
body = eventHandler.getRichBody(stripNewlines);
|
||||
} else {
|
||||
body = eventHandler.getPlainBody(stripNewlines);
|
||||
}
|
||||
|
||||
return eventHandler.singleLineAuthorDisplayname() + (event->isStateEvent() ? QLatin1String(" ") : QLatin1String(": ")) + body;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool NeoChatRoom::isEventHighlighted(const RoomEvent *e) const
|
||||
{
|
||||
return highlights.contains(e);
|
||||
|
||||
@@ -398,14 +398,6 @@ public:
|
||||
*/
|
||||
[[nodiscard]] const Quotient::RoomEvent *lastEvent() const;
|
||||
|
||||
/**
|
||||
* @brief Convenient way to call eventToString on the last event.
|
||||
*
|
||||
* @sa lastEvent()
|
||||
* @sa eventToString()
|
||||
*/
|
||||
[[nodiscard]] QString lastEventToString(Qt::TextFormat format = Qt::PlainText, bool stripNewlines = false) const;
|
||||
|
||||
/**
|
||||
* @brief Convenient way to check if the last event looks like it has spoilers.
|
||||
*
|
||||
@@ -492,15 +484,6 @@ public:
|
||||
|
||||
[[nodiscard]] bool readMarkerLoaded() const;
|
||||
|
||||
/**
|
||||
* @brief Get subtitle text for room
|
||||
*
|
||||
* Fetches last event and removes markdown formatting
|
||||
*
|
||||
* @see lastEventToString()
|
||||
*/
|
||||
[[nodiscard]] QString subtitleText();
|
||||
|
||||
[[nodiscard]] QString avatarMediaId() const;
|
||||
|
||||
Quotient::User *directChatRemoteUser() const;
|
||||
|
||||
Reference in New Issue
Block a user