Add highlight support.
This commit is contained in:
parent
c3bf4d75e5
commit
cfc32289d1
|
@ -48,7 +48,7 @@ RowLayout {
|
||||||
id: genericBubble
|
id: genericBubble
|
||||||
|
|
||||||
highlighted: !sentByMe
|
highlighted: !sentByMe
|
||||||
colored: highlighted && eventType === "notice"
|
colored: highlighted && (eventType === "notice" || highlight)
|
||||||
|
|
||||||
contentItem: ColumnLayout {
|
contentItem: ColumnLayout {
|
||||||
id: messageColumn
|
id: messageColumn
|
||||||
|
|
|
@ -241,6 +241,8 @@ Item {
|
||||||
boundsBehavior: Flickable.DragOverBounds
|
boundsBehavior: Flickable.DragOverBounds
|
||||||
maximumFlickVelocity: 2048
|
maximumFlickVelocity: 2048
|
||||||
|
|
||||||
|
cacheBuffer: 200
|
||||||
|
|
||||||
model: MessageEventModel {
|
model: MessageEventModel {
|
||||||
id: messageEventModel
|
id: messageEventModel
|
||||||
room: currentRoom
|
room: currentRoom
|
||||||
|
|
|
@ -123,7 +123,7 @@ Item {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
visible: highlighted
|
visible: highlightCount > 0 || highlighted
|
||||||
color: Material.accent
|
color: Material.accent
|
||||||
opacity: 0.1
|
opacity: 0.1
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
|
|
||||||
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,
|
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,
|
||||||
JoinState joinState)
|
JoinState joinState)
|
||||||
: Room(connection, std::move(roomId), joinState) {}
|
: Room(connection, std::move(roomId), joinState) {
|
||||||
|
connect(this, &MatriqueRoom::notificationCountChanged, this,
|
||||||
|
&MatriqueRoom::countChanged);
|
||||||
|
connect(this, &MatriqueRoom::highlightCountChanged, this,
|
||||||
|
&MatriqueRoom::countChanged);
|
||||||
|
}
|
||||||
|
|
||||||
void MatriqueRoom::chooseAndUploadFile() {
|
void MatriqueRoom::chooseAndUploadFile() {
|
||||||
auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as"));
|
auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as"));
|
||||||
|
@ -87,3 +92,35 @@ QString MatriqueRoom::lastEvent() {
|
||||||
return user(lastEvent->senderId())->displayname() + ": " +
|
return user(lastEvent->senderId())->displayname() + ": " +
|
||||||
lastEvent->contentJson().value("body").toString();
|
lastEvent->contentJson().value("body").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MatriqueRoom::isEventHighlighted(const RoomEvent* e) const {
|
||||||
|
return highlights.contains(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatriqueRoom::checkForHighlights(const QMatrixClient::TimelineItem& ti) {
|
||||||
|
auto localUserId = localUser()->id();
|
||||||
|
if (ti->senderId() == localUserId) return;
|
||||||
|
if (auto* e = ti.viewAs<RoomMessageEvent>()) {
|
||||||
|
const auto& text = e->plainBody();
|
||||||
|
if (text.contains(localUserId) ||
|
||||||
|
text.contains(roomMembername(localUserId)))
|
||||||
|
highlights.insert(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatriqueRoom::onAddNewTimelineEvents(timeline_iter_t from) {
|
||||||
|
std::for_each(from, messageEvents().cend(),
|
||||||
|
[this](const TimelineItem& ti) { checkForHighlights(ti); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatriqueRoom::onAddHistoricalTimelineEvents(rev_iter_t from) {
|
||||||
|
std::for_each(from, messageEvents().crend(),
|
||||||
|
[this](const TimelineItem& ti) { checkForHighlights(ti); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatriqueRoom::countChanged() {
|
||||||
|
if (displayed() && !hasUnreadMessages()) {
|
||||||
|
resetNotificationCount();
|
||||||
|
resetHighlightCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,13 +30,23 @@ class MatriqueRoom : public Room {
|
||||||
QString getUsersTyping();
|
QString getUsersTyping();
|
||||||
|
|
||||||
QString lastEvent();
|
QString lastEvent();
|
||||||
|
bool isEventHighlighted(const QMatrixClient::RoomEvent* e) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_cachedInput;
|
QString m_cachedInput;
|
||||||
|
QSet<const QMatrixClient::RoomEvent*> highlights;
|
||||||
|
|
||||||
QString getMIME(const QUrl& fileUrl) const;
|
QString getMIME(const QUrl& fileUrl) const;
|
||||||
void postFile(const QUrl& localFile, const QUrl& mxcUrl);
|
void postFile(const QUrl& localFile, const QUrl& mxcUrl);
|
||||||
|
|
||||||
|
void checkForHighlights(const QMatrixClient::TimelineItem& ti);
|
||||||
|
|
||||||
|
void onAddNewTimelineEvents(timeline_iter_t from) override;
|
||||||
|
void onAddHistoricalTimelineEvents(rev_iter_t from) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void countChanged();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cachedInputChanged();
|
void cachedInputChanged();
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ MessageEventModel::MessageEventModel(QObject* parent)
|
||||||
|
|
||||||
MessageEventModel::~MessageEventModel() {}
|
MessageEventModel::~MessageEventModel() {}
|
||||||
|
|
||||||
void MessageEventModel::setRoom(QMatrixClient::Room* room) {
|
void MessageEventModel::setRoom(MatriqueRoom* room) {
|
||||||
if (room == m_currentRoom) return;
|
if (room == m_currentRoom) return;
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
@ -567,6 +567,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == HighlightRole) return m_currentRoom->isEventHighlighted(&evt);
|
||||||
|
|
||||||
if (role == ReadMarkerRole) return evt.id() == lastReadEventId;
|
if (role == ReadMarkerRole) return evt.id() == lastReadEventId;
|
||||||
|
|
||||||
if (role == SpecialMarksRole) {
|
if (role == SpecialMarksRole) {
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
#define MESSAGEEVENTMODEL_H
|
#define MESSAGEEVENTMODEL_H
|
||||||
|
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "matriqueroom.h"
|
||||||
|
|
||||||
#include <QtCore/QAbstractListModel>
|
#include <QtCore/QAbstractListModel>
|
||||||
|
|
||||||
class MessageEventModel : public QAbstractListModel {
|
class MessageEventModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
QMatrixClient::Room* room READ getRoom WRITE setRoom NOTIFY roomChanged)
|
MatriqueRoom* room READ getRoom WRITE setRoom NOTIFY roomChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -35,8 +36,8 @@ class MessageEventModel : public QAbstractListModel {
|
||||||
explicit MessageEventModel(QObject* parent = nullptr);
|
explicit MessageEventModel(QObject* parent = nullptr);
|
||||||
~MessageEventModel();
|
~MessageEventModel();
|
||||||
|
|
||||||
QMatrixClient::Room* getRoom() { return m_currentRoom; }
|
MatriqueRoom* getRoom() { return m_currentRoom; }
|
||||||
void setRoom(QMatrixClient::Room* room);
|
void setRoom(MatriqueRoom* room);
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex& index,
|
QVariant data(const QModelIndex& index,
|
||||||
|
@ -48,7 +49,7 @@ class MessageEventModel : public QAbstractListModel {
|
||||||
void refreshRow(int row);
|
void refreshRow(int row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMatrixClient::Room* m_currentRoom = nullptr;
|
MatriqueRoom* m_currentRoom = nullptr;
|
||||||
QString lastReadEventId;
|
QString lastReadEventId;
|
||||||
int rowBelowInserted = -1;
|
int rowBelowInserted = -1;
|
||||||
bool movingEvent = 0;
|
bool movingEvent = 0;
|
||||||
|
|
|
@ -153,6 +153,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
|
||||||
return RoomType::Normal;
|
return RoomType::Normal;
|
||||||
}
|
}
|
||||||
if (role == UnreadCountRole) return room->unreadCount();
|
if (role == UnreadCountRole) return room->unreadCount();
|
||||||
|
if (role == HighlightCountRole) return room->highlightCount();
|
||||||
if (role == LastEventRole) return room->lastEvent();
|
if (role == LastEventRole) return room->lastEvent();
|
||||||
if (role == CurrentRoomRole) return QVariant::fromValue(room);
|
if (role == CurrentRoomRole) return QVariant::fromValue(room);
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -185,6 +186,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
|
||||||
roles[TopicRole] = "topic";
|
roles[TopicRole] = "topic";
|
||||||
roles[CategoryRole] = "category";
|
roles[CategoryRole] = "category";
|
||||||
roles[UnreadCountRole] = "unreadCount";
|
roles[UnreadCountRole] = "unreadCount";
|
||||||
|
roles[HighlightCountRole] = "highlightCount";
|
||||||
roles[LastEventRole] = "lastEvent";
|
roles[LastEventRole] = "lastEvent";
|
||||||
roles[CurrentRoomRole] = "currentRoom";
|
roles[CurrentRoomRole] = "currentRoom";
|
||||||
return roles;
|
return roles;
|
||||||
|
|
|
@ -35,6 +35,7 @@ class RoomListModel : public QAbstractListModel {
|
||||||
TopicRole,
|
TopicRole,
|
||||||
CategoryRole,
|
CategoryRole,
|
||||||
UnreadCountRole,
|
UnreadCountRole,
|
||||||
|
HighlightCountRole,
|
||||||
LastEventRole,
|
LastEventRole,
|
||||||
CurrentRoomRole,
|
CurrentRoomRole,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue