Add migration for room version empty in db

This commit is contained in:
Joseph Donofry 2021-04-18 13:41:55 -04:00
parent 01ee25cee4
commit 42621a7da2
No known key found for this signature in database
GPG key ID: E8A1D78EF044B0CB
2 changed files with 44 additions and 4 deletions

View file

@ -35,7 +35,7 @@
//! Should be changed when a breaking change occurs in the cache format.
//! This will reset client's data.
static const std::string CURRENT_CACHE_FORMAT_VERSION("2020.10.20");
static const std::string CURRENT_CACHE_FORMAT_VERSION("2021.04.18");
static const std::string SECRET("secret");
//! Keys used for the DB
@ -977,6 +977,45 @@ Cache::runMigrations()
nhlog::db()->info("Successfully migrated olm sessions.");
return true;
}},
{"2021.04.18",
[this]() {
try {
using namespace mtx::events;
using namespace mtx::events::state;
auto txn = lmdb::txn::begin(env_, nullptr);
auto room_ids = getRoomIds(txn);
for (const auto &room_id : room_ids) {
auto statesdb = getStatesDb(txn, room_id);
std::string_view event;
bool res = statesdb.get(
txn, to_string(mtx::events::EventType::RoomCreate), event);
if (res) {
try {
StateEvent<Create> msg = json::parse(event);
if (msg.content.room_version.empty()) {
msg.content.room_version = "1";
statesdb.put(txn,
to_string(msg.type),
json(msg).dump());
}
} catch (const json::exception &e) {
nhlog::db()->warn(
"failed to parse m.room.create event: {}",
e.what());
}
}
}
} catch (const lmdb::error &) {
nhlog::db()->critical("Failed to migrate room versions");
return false;
}
nhlog::db()->info("Successfully migrated room versions.");
return true;
}},
};
nhlog::db()->info("Running migrations, this may take a while!");

View file

@ -1463,9 +1463,8 @@ TimelineModel::formatMemberEvent(QString id)
}
}
QString user = QString::fromStdString(event->state_key);
QString name = utils::replaceEmoji(displayName(user));
QString oldName = QString::fromStdString(prevEvent->content.display_name);
QString user = QString::fromStdString(event->state_key);
QString name = utils::replaceEmoji(displayName(user));
QString rendered;
// see table https://matrix.org/docs/spec/client_server/latest#m-room-member
@ -1476,6 +1475,8 @@ TimelineModel::formatMemberEvent(QString id)
break;
case Membership::Join:
if (prevEvent && prevEvent->content.membership == Membership::Join) {
QString oldName = QString::fromStdString(prevEvent->content.display_name);
bool displayNameChanged =
prevEvent->content.display_name != event->content.display_name;
bool avatarChanged =