Enable read receipts action and sync read receipts from cache
This commit is contained in:
parent
240b3a566b
commit
d34067a257
@ -180,6 +180,7 @@ Rectangle {
|
||||
|
||||
MenuItem {
|
||||
text: "Read receipts"
|
||||
onTriggered: chat.model.readReceiptsAction(model.id)
|
||||
}
|
||||
MenuItem {
|
||||
text: "Mark as read"
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "ChatPage.h"
|
||||
#include "Logging.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Olm.h"
|
||||
#include "Utils.h"
|
||||
#include "dialogs/RawMessage.h"
|
||||
@ -376,6 +377,8 @@ TimelineModel::data(const QModelIndex &index, int role) const
|
||||
return qml_mtx_events::Failed;
|
||||
else if (pending.contains(id))
|
||||
return qml_mtx_events::Sent;
|
||||
else if (read.contains(id))
|
||||
return qml_mtx_events::Read;
|
||||
else
|
||||
return qml_mtx_events::Received;
|
||||
default:
|
||||
@ -664,7 +667,13 @@ TimelineModel::replyAction(QString id)
|
||||
if (related.quoted_body.isEmpty())
|
||||
return;
|
||||
|
||||
emit ChatPage::instance()->messageReply(related);
|
||||
ChatPage::instance()->messageReply(related);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineModel::readReceiptsAction(QString id) const
|
||||
{
|
||||
MainWindow::instance()->openReadReceiptsDialog(id);
|
||||
}
|
||||
|
||||
int
|
||||
@ -685,3 +694,17 @@ TimelineModel::indexToId(int index) const
|
||||
return "";
|
||||
return eventOrder[index];
|
||||
}
|
||||
|
||||
void
|
||||
TimelineModel::markEventsAsRead(const std::vector<QString> &event_ids)
|
||||
{
|
||||
for (const auto &id : event_ids) {
|
||||
read.insert(id);
|
||||
int idx = idToIndex(id);
|
||||
if (idx < 0) {
|
||||
nhlog::ui()->warn("Read index out of range");
|
||||
return;
|
||||
}
|
||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
||||
Q_INVOKABLE void viewRawMessage(QString id) const;
|
||||
Q_INVOKABLE void replyAction(QString id);
|
||||
Q_INVOKABLE void readReceiptsAction(QString id) const;
|
||||
Q_INVOKABLE int idToIndex(QString id) const;
|
||||
Q_INVOKABLE QString indexToId(int index) const;
|
||||
|
||||
@ -146,10 +147,10 @@ public slots:
|
||||
emit currentIndexChanged(index);
|
||||
}
|
||||
int currentIndex() const { return idToIndex(currentId); }
|
||||
void markEventsAsRead(const std::vector<QString> &event_ids);
|
||||
|
||||
private slots:
|
||||
// Add old events at the top of the timeline.
|
||||
|
||||
void addBackwardsEvents(const mtx::responses::Messages &msgs);
|
||||
|
||||
signals:
|
||||
@ -165,7 +166,7 @@ private:
|
||||
const std::vector<mtx::events::collections::TimelineEvents> &timeline);
|
||||
|
||||
QHash<QString, mtx::events::collections::TimelineEvents> events;
|
||||
QSet<QString> pending, failed;
|
||||
QSet<QString> pending, failed, read;
|
||||
std::vector<QString> eventOrder;
|
||||
|
||||
QString room_id_;
|
||||
|
@ -52,6 +52,16 @@ TimelineViewManager::setHistoryView(const QString &room_id)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewManager::updateReadReceipts(const QString &room_id,
|
||||
const std::vector<QString> &event_ids)
|
||||
{
|
||||
auto room = models.find(room_id);
|
||||
if (room != models.end()) {
|
||||
room.value()->markEventsAsRead(event_ids);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ signals:
|
||||
void activeTimelineChanged(TimelineModel *timeline);
|
||||
|
||||
public slots:
|
||||
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids) {}
|
||||
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
||||
void removeTimelineEvent(const QString &room_id, const QString &event_id) {}
|
||||
void initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user