mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
Actually fix updating roomlist on new messages
This commit is contained in:
parent
3c9ddc2afb
commit
6b6085b270
3 changed files with 32 additions and 29 deletions
|
@ -105,4 +105,3 @@ qml()
|
|||
return qml_logger;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -348,6 +348,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
|||
events.remove(txn_id);
|
||||
events.insert(event_id, ev);
|
||||
|
||||
// mark our messages as read
|
||||
readEvent(event_id.toStdString());
|
||||
|
||||
// ask to be notified for read receipts
|
||||
cache::client()->addPendingReceipt(room_id_, event_id);
|
||||
|
||||
|
@ -525,25 +528,20 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
|
|||
this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
|
||||
endInsertRows();
|
||||
|
||||
for (auto id = eventOrder.rbegin(); id != eventOrder.rend(); id++) {
|
||||
auto event = events.value(*id);
|
||||
if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
||||
&event)) {
|
||||
event = decryptEvent(*e).event;
|
||||
}
|
||||
updateLastMessage();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
void
|
||||
TimelineModel::updateLastMessage()
|
||||
{
|
||||
auto event = events.value(eventOrder.back());
|
||||
if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&event)) {
|
||||
event = decryptEvent(*e).event;
|
||||
}
|
||||
|
||||
auto description = utils::getMessageDescription(
|
||||
event, QString::fromStdString(http::client()->user_id().to_string()), room_id_);
|
||||
emit manager_->updateRoomsLastMessage(room_id_, description);
|
||||
}
|
||||
|
||||
std::vector<QString>
|
||||
|
@ -634,20 +632,23 @@ TimelineModel::setCurrentIndex(int index)
|
|||
currentId = indexToId(index);
|
||||
emit currentIndexChanged(index);
|
||||
|
||||
if (oldIndex < index) {
|
||||
http::client()->read_event(room_id_.toStdString(),
|
||||
currentId.toStdString(),
|
||||
[this](mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
nhlog::net()->warn(
|
||||
"failed to read_event ({}, {})",
|
||||
room_id_.toStdString(),
|
||||
currentId.toStdString());
|
||||
}
|
||||
});
|
||||
if (oldIndex < index && !pending.contains(currentId)) {
|
||||
readEvent(currentId.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TimelineModel::readEvent(const std::string &id)
|
||||
{
|
||||
http::client()->read_event(room_id_.toStdString(), id, [this](mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
nhlog::net()->warn("failed to read_event ({}, {})",
|
||||
room_id_.toStdString(),
|
||||
currentId.toStdString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
|
||||
{
|
||||
|
|
|
@ -192,6 +192,8 @@ private:
|
|||
const std::string &user_id,
|
||||
const mtx::responses::ClaimKeys &res,
|
||||
mtx::http::RequestErr err);
|
||||
void updateLastMessage();
|
||||
void readEvent(const std::string &id);
|
||||
|
||||
QHash<QString, mtx::events::collections::TimelineEvents> events;
|
||||
QSet<QString> pending, failed, read;
|
||||
|
@ -229,6 +231,7 @@ TimelineModel::sendMessage(const T &msg)
|
|||
pending.insert(txn_id_qstr);
|
||||
this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr);
|
||||
endInsertRows();
|
||||
updateLastMessage();
|
||||
|
||||
if (cache::client()->isRoomEncrypted(room_id_.toStdString()))
|
||||
sendEncryptedMessage(txn_id, nlohmann::json(msg));
|
||||
|
|
Loading…
Reference in a new issue