mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 19:38:48 +03:00
Add migration for room version empty in db
This commit is contained in:
parent
01ee25cee4
commit
42621a7da2
2 changed files with 44 additions and 4 deletions
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
//! Should be changed when a breaking change occurs in the cache format.
|
//! Should be changed when a breaking change occurs in the cache format.
|
||||||
//! This will reset client's data.
|
//! 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");
|
static const std::string SECRET("secret");
|
||||||
|
|
||||||
//! Keys used for the DB
|
//! Keys used for the DB
|
||||||
|
@ -977,6 +977,45 @@ Cache::runMigrations()
|
||||||
nhlog::db()->info("Successfully migrated olm sessions.");
|
nhlog::db()->info("Successfully migrated olm sessions.");
|
||||||
return true;
|
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!");
|
nhlog::db()->info("Running migrations, this may take a while!");
|
||||||
|
|
|
@ -1463,9 +1463,8 @@ TimelineModel::formatMemberEvent(QString id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString user = QString::fromStdString(event->state_key);
|
QString user = QString::fromStdString(event->state_key);
|
||||||
QString name = utils::replaceEmoji(displayName(user));
|
QString name = utils::replaceEmoji(displayName(user));
|
||||||
QString oldName = QString::fromStdString(prevEvent->content.display_name);
|
|
||||||
QString rendered;
|
QString rendered;
|
||||||
|
|
||||||
// see table https://matrix.org/docs/spec/client_server/latest#m-room-member
|
// see table https://matrix.org/docs/spec/client_server/latest#m-room-member
|
||||||
|
@ -1476,6 +1475,8 @@ TimelineModel::formatMemberEvent(QString id)
|
||||||
break;
|
break;
|
||||||
case Membership::Join:
|
case Membership::Join:
|
||||||
if (prevEvent && prevEvent->content.membership == Membership::Join) {
|
if (prevEvent && prevEvent->content.membership == Membership::Join) {
|
||||||
|
QString oldName = QString::fromStdString(prevEvent->content.display_name);
|
||||||
|
|
||||||
bool displayNameChanged =
|
bool displayNameChanged =
|
||||||
prevEvent->content.display_name != event->content.display_name;
|
prevEvent->content.display_name != event->content.display_name;
|
||||||
bool avatarChanged =
|
bool avatarChanged =
|
||||||
|
|
Loading…
Reference in a new issue