|
|
@ -1202,25 +1202,24 @@ Cache::calculateRoomReadStatus(const std::string &room_id) |
|
|
|
const auto last_event_id = getLastEventId(txn, room_id); |
|
|
|
const auto last_event_id = getLastEventId(txn, room_id); |
|
|
|
const auto localUser = utils::localUser().toStdString(); |
|
|
|
const auto localUser = utils::localUser().toStdString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string fullyReadEventId; |
|
|
|
|
|
|
|
if (auto ev = getAccountData(txn, mtx::events::EventType::FullyRead, room_id)) { |
|
|
|
|
|
|
|
if (auto fr = std::get_if< |
|
|
|
|
|
|
|
mtx::events::AccountDataEvent<mtx::events::account_data::FullyRead>>( |
|
|
|
|
|
|
|
&ev.value())) { |
|
|
|
|
|
|
|
fullyReadEventId = fr->content.event_id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
txn.commit(); |
|
|
|
txn.commit(); |
|
|
|
|
|
|
|
|
|
|
|
if (last_event_id.empty()) |
|
|
|
if (last_event_id.empty() || fullyReadEventId.empty()) |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Retrieve all read receipts for that event.
|
|
|
|
|
|
|
|
const auto receipts = |
|
|
|
|
|
|
|
readReceipts(QString::fromStdString(last_event_id), QString::fromStdString(room_id)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (receipts.size() == 0) |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
// Check if the local user has a read receipt for it.
|
|
|
|
if (last_event_id == fullyReadEventId) |
|
|
|
for (auto it = receipts.cbegin(); it != receipts.cend(); it++) { |
|
|
|
|
|
|
|
if (it->second == localUser) |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
// Retrieve all read receipts for that event.
|
|
|
|
|
|
|
|
return getEventIndex(room_id, last_event_id) > getEventIndex(room_id, fullyReadEventId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
@ -1918,7 +1917,6 @@ Cache::getEventIndex(const std::string &room_id, std::string_view event_id) |
|
|
|
|
|
|
|
|
|
|
|
bool success = lmdb::dbi_get(txn, orderDb, indexVal, val); |
|
|
|
bool success = lmdb::dbi_get(txn, orderDb, indexVal, val); |
|
|
|
if (!success) { |
|
|
|
if (!success) { |
|
|
|
nhlog::db()->critical("Could not find event id: {}", event_id); |
|
|
|
|
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3320,8 +3318,11 @@ Cache::getAccountData(lmdb::txn &txn, mtx::events::EventType type, const std::st |
|
|
|
lmdb::val data; |
|
|
|
lmdb::val data; |
|
|
|
if (lmdb::dbi_get(txn, db, lmdb::val(to_string(type)), data)) { |
|
|
|
if (lmdb::dbi_get(txn, db, lmdb::val(to_string(type)), data)) { |
|
|
|
mtx::responses::utils::RoomAccountDataEvents events; |
|
|
|
mtx::responses::utils::RoomAccountDataEvents events; |
|
|
|
mtx::responses::utils::parse_room_account_data_events( |
|
|
|
json j = json::array({ |
|
|
|
std::string_view(data.data(), data.size()), events); |
|
|
|
json::parse(std::string_view(data.data(), data.size())), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
mtx::responses::utils::parse_room_account_data_events(j, events); |
|
|
|
|
|
|
|
if (events.size() == 1) |
|
|
|
return events.front(); |
|
|
|
return events.front(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (...) { |
|
|
|
} catch (...) { |
|
|
|