mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +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;
|
return qml_logger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
||||||
events.remove(txn_id);
|
events.remove(txn_id);
|
||||||
events.insert(event_id, ev);
|
events.insert(event_id, ev);
|
||||||
|
|
||||||
|
// mark our messages as read
|
||||||
|
readEvent(event_id.toStdString());
|
||||||
|
|
||||||
// ask to be notified for read receipts
|
// ask to be notified for read receipts
|
||||||
cache::client()->addPendingReceipt(room_id_, event_id);
|
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());
|
this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end());
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
for (auto id = eventOrder.rbegin(); id != eventOrder.rend(); id++) {
|
updateLastMessage();
|
||||||
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(
|
void
|
||||||
[](const auto &e) -> mtx::events::EventType { return e.type; }, event);
|
TimelineModel::updateLastMessage()
|
||||||
if (type == mtx::events::EventType::RoomMessage ||
|
{
|
||||||
type == mtx::events::EventType::Sticker) {
|
auto event = events.value(eventOrder.back());
|
||||||
auto description = utils::getMessageDescription(
|
if (auto e = boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&event)) {
|
||||||
event,
|
event = decryptEvent(*e).event;
|
||||||
QString::fromStdString(http::client()->user_id().to_string()),
|
|
||||||
room_id_);
|
|
||||||
emit manager_->updateRoomsLastMessage(room_id_, description);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto description = utils::getMessageDescription(
|
||||||
|
event, QString::fromStdString(http::client()->user_id().to_string()), room_id_);
|
||||||
|
emit manager_->updateRoomsLastMessage(room_id_, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QString>
|
std::vector<QString>
|
||||||
|
@ -634,20 +632,23 @@ TimelineModel::setCurrentIndex(int index)
|
||||||
currentId = indexToId(index);
|
currentId = indexToId(index);
|
||||||
emit currentIndexChanged(index);
|
emit currentIndexChanged(index);
|
||||||
|
|
||||||
if (oldIndex < index) {
|
if (oldIndex < index && !pending.contains(currentId)) {
|
||||||
http::client()->read_event(room_id_.toStdString(),
|
readEvent(currentId.toStdString());
|
||||||
currentId.toStdString(),
|
|
||||||
[this](mtx::http::RequestErr err) {
|
|
||||||
if (err) {
|
|
||||||
nhlog::net()->warn(
|
|
||||||
"failed to read_event ({}, {})",
|
|
||||||
room_id_.toStdString(),
|
|
||||||
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
|
void
|
||||||
TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
|
TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -192,6 +192,8 @@ private:
|
||||||
const std::string &user_id,
|
const std::string &user_id,
|
||||||
const mtx::responses::ClaimKeys &res,
|
const mtx::responses::ClaimKeys &res,
|
||||||
mtx::http::RequestErr err);
|
mtx::http::RequestErr err);
|
||||||
|
void updateLastMessage();
|
||||||
|
void readEvent(const std::string &id);
|
||||||
|
|
||||||
QHash<QString, mtx::events::collections::TimelineEvents> events;
|
QHash<QString, mtx::events::collections::TimelineEvents> events;
|
||||||
QSet<QString> pending, failed, read;
|
QSet<QString> pending, failed, read;
|
||||||
|
@ -229,6 +231,7 @@ TimelineModel::sendMessage(const T &msg)
|
||||||
pending.insert(txn_id_qstr);
|
pending.insert(txn_id_qstr);
|
||||||
this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr);
|
this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
updateLastMessage();
|
||||||
|
|
||||||
if (cache::client()->isRoomEncrypted(room_id_.toStdString()))
|
if (cache::client()->isRoomEncrypted(room_id_.toStdString()))
|
||||||
sendEncryptedMessage(txn_id, nlohmann::json(msg));
|
sendEncryptedMessage(txn_id, nlohmann::json(msg));
|
||||||
|
|
Loading…
Reference in a new issue