diff --git a/src/Cache.cpp b/src/Cache.cpp index 3e1057c0..55571152 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -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 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!"); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 1148985b..6108df1c 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -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 =