Show subtitle text without markdown
Create new role in RoomListModel to send back cleaned subtitle text
This commit is contained in:
@@ -237,13 +237,8 @@ Kirigami.ScrollablePage {
|
|||||||
bold: unreadCount > 0
|
bold: unreadCount > 0
|
||||||
label: name ?? ""
|
label: name ?? ""
|
||||||
labelItem.textFormat: Text.PlainText
|
labelItem.textFormat: Text.PlainText
|
||||||
subtitle: {
|
subtitle: subtitleText
|
||||||
const txt = (lastEvent.length === 0 ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm, " ")
|
subtitleItem.textFormat: Text.PlainText
|
||||||
if (txt.length) {
|
|
||||||
return txt
|
|
||||||
}
|
|
||||||
return " "
|
|
||||||
}
|
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
const menu = roomListContextMenu.createObject(page, {"room": currentRoom})
|
const menu = roomListContextMenu.createObject(page, {"room": currentRoom})
|
||||||
configButton.visible = true
|
configButton.visible = true
|
||||||
|
|||||||
@@ -252,6 +252,35 @@ QDateTime NeoChatRoom::lastActiveTime()
|
|||||||
return messageEvents().rbegin()->get()->originTimestamp();
|
return messageEvents().rbegin()->get()->originTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString NeoChatRoom::subtitleText()
|
||||||
|
{
|
||||||
|
QString subtitle = this->lastEventToString().size() == 0 ? this->topic() : this->lastEventToString();
|
||||||
|
|
||||||
|
subtitle
|
||||||
|
// replace blockquote, i.e. '> text'
|
||||||
|
.replace(QRegularExpression("(\r\n\t|\n|\r\t|)> "), " ")
|
||||||
|
// replace headings, i.e. "# text"
|
||||||
|
.replace(QRegularExpression("(\r\n\t|\n|\r\t|)\\#{1,6} "), " ")
|
||||||
|
// replace newlines
|
||||||
|
.replace(QRegularExpression("(\r\n\t|\n|\r\t)"), " ")
|
||||||
|
// replace '**text**' and '__text__'
|
||||||
|
.replace(QRegularExpression("(\\*\\*|__)(?=\\S)([^\\r]*\\S)\\1"), "\\2")
|
||||||
|
// replace '*text*' and '_text_'
|
||||||
|
.replace(QRegularExpression("(\\*|_)(?=\\S)([^\\r]*\\S)\\1"), "\\2")
|
||||||
|
// replace '~~text~~'
|
||||||
|
.replace(QRegularExpression("~~(.*)~~"), "\\1")
|
||||||
|
// replace '~text~'
|
||||||
|
.replace(QRegularExpression("~(.*)~"), "\\1")
|
||||||
|
// replace '<del>text</del>'
|
||||||
|
.replace(QRegularExpression("<del>(.*)</del>"), "\\1")
|
||||||
|
// replace '```code```'
|
||||||
|
.replace(QRegularExpression("```([^```]+)```"), "\\1")
|
||||||
|
// replace '`code`'
|
||||||
|
.replace(QRegularExpression("`([^`]+)`"), "\\1");
|
||||||
|
|
||||||
|
return subtitle.size() > 0 ? subtitle : QStringLiteral(" ");
|
||||||
|
}
|
||||||
|
|
||||||
int NeoChatRoom::savedTopVisibleIndex() const
|
int NeoChatRoom::savedTopVisibleIndex() const
|
||||||
{
|
{
|
||||||
return firstDisplayedMarker() == historyEdge() ? 0 : int(firstDisplayedMarker() - messageEvents().rbegin());
|
return firstDisplayedMarker() == historyEdge() ? 0 : int(firstDisplayedMarker() - messageEvents().rbegin());
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ public:
|
|||||||
/// \see lastEvent
|
/// \see lastEvent
|
||||||
[[nodiscard]] QDateTime lastActiveTime();
|
[[nodiscard]] QDateTime lastActiveTime();
|
||||||
|
|
||||||
|
/// Get subtitle text for room
|
||||||
|
///
|
||||||
|
/// Fetches last event and removes markdown formatting
|
||||||
|
/// \see lastEventToString
|
||||||
|
[[nodiscard]] QString subtitleText();
|
||||||
|
|
||||||
bool isEventHighlighted(const Quotient::RoomEvent *e) const;
|
bool isEventHighlighted(const Quotient::RoomEvent *e) const;
|
||||||
|
|
||||||
[[nodiscard]] QString joinRule() const;
|
[[nodiscard]] QString joinRule() const;
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room)
|
|||||||
refresh(room);
|
refresh(room);
|
||||||
});
|
});
|
||||||
connect(room, &Room::addedMessages, this, [this, room] {
|
connect(room, &Room::addedMessages, this, [this, room] {
|
||||||
refresh(room, {LastEventRole});
|
refresh(room, {LastEventRole, SubtitleTextRole});
|
||||||
});
|
});
|
||||||
connect(room, &Room::notificationCountChanged, this, &RoomListModel::handleNotifications);
|
connect(room, &Room::notificationCountChanged, this, &RoomListModel::handleNotifications);
|
||||||
connect(room, &Room::highlightCountChanged, this, [this, room] {
|
connect(room, &Room::highlightCountChanged, this, [this, room] {
|
||||||
@@ -396,6 +396,9 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
|||||||
if (role == CategoryVisibleRole) {
|
if (role == CategoryVisibleRole) {
|
||||||
return m_categoryVisibility.value(data(index, CategoryRole).toInt(), true);
|
return m_categoryVisibility.value(data(index, CategoryRole).toInt(), true);
|
||||||
}
|
}
|
||||||
|
if (role == SubtitleTextRole) {
|
||||||
|
return room->subtitleText();
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,6 +429,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const
|
|||||||
roles[JoinStateRole] = "joinState";
|
roles[JoinStateRole] = "joinState";
|
||||||
roles[CurrentRoomRole] = "currentRoom";
|
roles[CurrentRoomRole] = "currentRoom";
|
||||||
roles[CategoryVisibleRole] = "categoryVisible";
|
roles[CategoryVisibleRole] = "categoryVisible";
|
||||||
|
roles[SubtitleTextRole] = "subtitleText";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public:
|
|||||||
JoinStateRole,
|
JoinStateRole,
|
||||||
CurrentRoomRole,
|
CurrentRoomRole,
|
||||||
CategoryVisibleRole,
|
CategoryVisibleRole,
|
||||||
|
SubtitleTextRole,
|
||||||
};
|
};
|
||||||
Q_ENUM(EventRoles)
|
Q_ENUM(EventRoles)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user