mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Update roomlist on new messages
This commit is contained in:
parent
aee29c6ed5
commit
1dd1a19b06
4 changed files with 32 additions and 4 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "Olm.h"
|
#include "Olm.h"
|
||||||
|
#include "TimelineViewManager.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "dialogs/RawMessage.h"
|
#include "dialogs/RawMessage.h"
|
||||||
|
|
||||||
|
@ -282,9 +283,10 @@ eventPropHeight(const mtx::events::RoomEvent<T> &e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineModel::TimelineModel(QString room_id, QObject *parent)
|
TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, room_id_(room_id)
|
, room_id_(room_id)
|
||||||
|
, manager_(manager)
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents);
|
this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents);
|
||||||
|
@ -481,6 +483,26 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
|
||||||
static_cast<int>(this->eventOrder.size() + ids.size() - 1));
|
static_cast<int>(this->eventOrder.size() + ids.size() - 1));
|
||||||
this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
|
this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
for (auto id = ids.rbegin(); id != ids.rend(); id++) {
|
||||||
|
auto event = events.value(*id);
|
||||||
|
if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
||||||
|
&event)) {
|
||||||
|
event = decryptEvent(*e).event;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto type = boost::apply_visitor(
|
||||||
|
[](const auto &e) -> mtx::events::EventType { return e.type; }, event);
|
||||||
|
if (type == mtx::events::EventType::RoomMessage ||
|
||||||
|
type == mtx::events::EventType::Sticker) {
|
||||||
|
auto description = utils::getMessageDescription(
|
||||||
|
event,
|
||||||
|
QString::fromStdString(http::client()->user_id().to_string()),
|
||||||
|
room_id_);
|
||||||
|
emit manager_->updateRoomsLastMessage(room_id_, description);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QString>
|
std::vector<QString>
|
||||||
|
|
|
@ -108,6 +108,8 @@ struct DecryptionResult
|
||||||
bool isDecrypted = false;
|
bool isDecrypted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TimelineViewManager;
|
||||||
|
|
||||||
class TimelineModel : public QAbstractListModel
|
class TimelineModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -115,7 +117,7 @@ class TimelineModel : public QAbstractListModel
|
||||||
int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TimelineModel(QString room_id, QObject *parent = 0);
|
explicit TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent = 0);
|
||||||
|
|
||||||
enum Roles
|
enum Roles
|
||||||
{
|
{
|
||||||
|
@ -145,6 +147,7 @@ public:
|
||||||
Q_INVOKABLE QString displayName(QString id) const;
|
Q_INVOKABLE QString displayName(QString id) const;
|
||||||
Q_INVOKABLE QString avatarUrl(QString id) const;
|
Q_INVOKABLE QString avatarUrl(QString id) const;
|
||||||
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
||||||
|
|
||||||
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
||||||
Q_INVOKABLE void viewRawMessage(QString id) const;
|
Q_INVOKABLE void viewRawMessage(QString id) const;
|
||||||
Q_INVOKABLE void replyAction(QString id);
|
Q_INVOKABLE void replyAction(QString id);
|
||||||
|
@ -204,6 +207,8 @@ private:
|
||||||
|
|
||||||
QHash<QString, QColor> userColors;
|
QHash<QString, QColor> userColors;
|
||||||
QString currentId;
|
QString currentId;
|
||||||
|
|
||||||
|
TimelineViewManager *manager_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
@ -40,7 +40,8 @@ void
|
||||||
TimelineViewManager::addRoom(const QString &room_id)
|
TimelineViewManager::addRoom(const QString &room_id)
|
||||||
{
|
{
|
||||||
if (!models.contains(room_id))
|
if (!models.contains(room_id))
|
||||||
models.insert(room_id, QSharedPointer<TimelineModel>(new TimelineModel(room_id)));
|
models.insert(room_id,
|
||||||
|
QSharedPointer<TimelineModel>(new TimelineModel(this, room_id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clearRoomMessageCount(QString roomid);
|
void clearRoomMessageCount(QString roomid);
|
||||||
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
|
void updateRoomsLastMessage(QString roomid, const DescInfo &info);
|
||||||
void activeTimelineChanged(TimelineModel *timeline);
|
void activeTimelineChanged(TimelineModel *timeline);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Reference in a new issue