Update the cache state at once to avoid being in an invalid state
This commit is contained in:
parent
43b1bdfe63
commit
7fbfe3af15
6 changed files with 844 additions and 831 deletions
|
|
@ -24,36 +24,38 @@
|
|||
class Cache
|
||||
{
|
||||
public:
|
||||
Cache(const QString &userId);
|
||||
Cache(const QString &userId);
|
||||
|
||||
void insertRoomState(const QString &roomid, const RoomState &state);
|
||||
void setNextBatchToken(const QString &token);
|
||||
bool isInitialized();
|
||||
void setState(const QString &nextBatchToken, const QMap<QString, RoomState> &states);
|
||||
bool isInitialized() const;
|
||||
|
||||
QString nextBatchToken();
|
||||
QMap<QString, RoomState> states();
|
||||
QString nextBatchToken() const;
|
||||
QMap<QString, RoomState> states();
|
||||
|
||||
inline void unmount();
|
||||
inline QString memberDbName(const QString &roomid);
|
||||
inline void unmount();
|
||||
inline QString memberDbName(const QString &roomid);
|
||||
|
||||
private:
|
||||
lmdb::env env_;
|
||||
lmdb::dbi stateDb_;
|
||||
lmdb::dbi roomDb_;
|
||||
void setNextBatchToken(lmdb::txn &txn, const QString &token);
|
||||
void insertRoomState(lmdb::txn &txn, const QString &roomid, const RoomState &state);
|
||||
|
||||
bool isMounted_;
|
||||
lmdb::env env_;
|
||||
lmdb::dbi stateDb_;
|
||||
lmdb::dbi roomDb_;
|
||||
|
||||
QString userId_;
|
||||
bool isMounted_;
|
||||
|
||||
QString userId_;
|
||||
};
|
||||
|
||||
inline void
|
||||
Cache::unmount()
|
||||
{
|
||||
isMounted_ = false;
|
||||
isMounted_ = false;
|
||||
}
|
||||
|
||||
inline QString
|
||||
Cache::memberDbName(const QString &roomid)
|
||||
{
|
||||
return QString("m.%1").arg(roomid);
|
||||
return QString("m.%1").arg(roomid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,80 +35,79 @@
|
|||
|
||||
class ChatPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~ChatPage();
|
||||
ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
||||
~ChatPage();
|
||||
|
||||
// Initialize all the components of the UI.
|
||||
void bootstrap(QString userid, QString homeserver, QString token);
|
||||
// Initialize all the components of the UI.
|
||||
void bootstrap(QString userid, QString homeserver, QString token);
|
||||
|
||||
signals:
|
||||
void contentLoaded();
|
||||
void close();
|
||||
void changeWindowTitle(const QString &msg);
|
||||
void unreadMessages(int count);
|
||||
void contentLoaded();
|
||||
void close();
|
||||
void changeWindowTitle(const QString &msg);
|
||||
void unreadMessages(int count);
|
||||
|
||||
private slots:
|
||||
void showUnreadMessageNotification(int count);
|
||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
||||
void setOwnAvatar(const QPixmap &img);
|
||||
void initialSyncCompleted(const SyncResponse &response);
|
||||
void syncCompleted(const SyncResponse &response);
|
||||
void syncFailed(const QString &msg);
|
||||
void changeTopRoomInfo(const QString &room_id);
|
||||
void startSync();
|
||||
void logout();
|
||||
void showUnreadMessageNotification(int count);
|
||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
||||
void setOwnAvatar(const QPixmap &img);
|
||||
void initialSyncCompleted(const SyncResponse &response);
|
||||
void syncCompleted(const SyncResponse &response);
|
||||
void syncFailed(const QString &msg);
|
||||
void changeTopRoomInfo(const QString &room_id);
|
||||
void startSync();
|
||||
void logout();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
void updateDisplayNames(const RoomState &state);
|
||||
void updateRoomState(RoomState &room_state, const QJsonArray &events);
|
||||
void loadStateFromCache();
|
||||
void showQuickSwitcher();
|
||||
void updateDisplayNames(const RoomState &state);
|
||||
void loadStateFromCache();
|
||||
void showQuickSwitcher();
|
||||
|
||||
QHBoxLayout *topLayout_;
|
||||
Splitter *splitter;
|
||||
QHBoxLayout *topLayout_;
|
||||
Splitter *splitter;
|
||||
|
||||
QWidget *sideBar_;
|
||||
QVBoxLayout *sideBarLayout_;
|
||||
QVBoxLayout *sideBarTopLayout_;
|
||||
QVBoxLayout *sideBarMainLayout_;
|
||||
QWidget *sideBarTopWidget_;
|
||||
QVBoxLayout *sideBarTopWidgetLayout_;
|
||||
QWidget *sideBar_;
|
||||
QVBoxLayout *sideBarLayout_;
|
||||
QVBoxLayout *sideBarTopLayout_;
|
||||
QVBoxLayout *sideBarMainLayout_;
|
||||
QWidget *sideBarTopWidget_;
|
||||
QVBoxLayout *sideBarTopWidgetLayout_;
|
||||
|
||||
QWidget *content_;
|
||||
QVBoxLayout *contentLayout_;
|
||||
QHBoxLayout *topBarLayout_;
|
||||
QVBoxLayout *mainContentLayout_;
|
||||
QWidget *content_;
|
||||
QVBoxLayout *contentLayout_;
|
||||
QHBoxLayout *topBarLayout_;
|
||||
QVBoxLayout *mainContentLayout_;
|
||||
|
||||
RoomList *room_list_;
|
||||
TimelineViewManager *view_manager_;
|
||||
RoomList *room_list_;
|
||||
TimelineViewManager *view_manager_;
|
||||
|
||||
TopRoomBar *top_bar_;
|
||||
TextInputWidget *text_input_;
|
||||
TopRoomBar *top_bar_;
|
||||
TextInputWidget *text_input_;
|
||||
|
||||
QTimer *sync_timer_;
|
||||
int sync_interval_;
|
||||
QTimer *sync_timer_;
|
||||
int sync_interval_;
|
||||
|
||||
QString current_room_;
|
||||
QMap<QString, QPixmap> room_avatars_;
|
||||
QString current_room_;
|
||||
QMap<QString, QPixmap> room_avatars_;
|
||||
|
||||
UserInfoWidget *user_info_widget_;
|
||||
UserInfoWidget *user_info_widget_;
|
||||
|
||||
QMap<QString, RoomState> state_manager_;
|
||||
QMap<QString, QSharedPointer<RoomSettings>> settingsManager_;
|
||||
QMap<QString, RoomState> state_manager_;
|
||||
QMap<QString, QSharedPointer<RoomSettings>> settingsManager_;
|
||||
|
||||
QuickSwitcher *quickSwitcher_ = nullptr;
|
||||
OverlayModal *quickSwitcherModal_ = nullptr;
|
||||
QuickSwitcher *quickSwitcher_ = nullptr;
|
||||
OverlayModal *quickSwitcherModal_ = nullptr;
|
||||
|
||||
// Matrix Client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
// Matrix Client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
|
||||
// LMDB wrapper.
|
||||
QSharedPointer<Cache> cache_;
|
||||
// LMDB wrapper.
|
||||
QSharedPointer<Cache> cache_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -41,59 +41,60 @@ namespace events = matrix::events;
|
|||
class RoomState
|
||||
{
|
||||
public:
|
||||
// Calculate room data that are not immediatly accessible. Like room name and avatar.
|
||||
//
|
||||
// e.g If the room is 1-on-1 name and avatar should be extracted from a user.
|
||||
void resolveName();
|
||||
void resolveAvatar();
|
||||
void parse(const QJsonObject &object);
|
||||
// Calculate room data that are not immediatly accessible. Like room name and avatar.
|
||||
//
|
||||
// e.g If the room is 1-on-1 name and avatar should be extracted from a user.
|
||||
void resolveName();
|
||||
void resolveAvatar();
|
||||
void parse(const QJsonObject &object);
|
||||
|
||||
inline QUrl getAvatar() const;
|
||||
inline QString getName() const;
|
||||
inline QString getTopic() const;
|
||||
inline QUrl getAvatar() const;
|
||||
inline QString getName() const;
|
||||
inline QString getTopic() const;
|
||||
|
||||
void removeLeaveMemberships();
|
||||
void update(const RoomState &state);
|
||||
void removeLeaveMemberships();
|
||||
void update(const RoomState &state);
|
||||
void updateFromEvents(const QJsonArray &events);
|
||||
|
||||
QJsonObject serialize() const;
|
||||
QJsonObject serialize() const;
|
||||
|
||||
// The latest state events.
|
||||
events::StateEvent<events::AliasesEventContent> aliases;
|
||||
events::StateEvent<events::AvatarEventContent> avatar;
|
||||
events::StateEvent<events::CanonicalAliasEventContent> canonical_alias;
|
||||
events::StateEvent<events::CreateEventContent> create;
|
||||
events::StateEvent<events::HistoryVisibilityEventContent> history_visibility;
|
||||
events::StateEvent<events::JoinRulesEventContent> join_rules;
|
||||
events::StateEvent<events::NameEventContent> name;
|
||||
events::StateEvent<events::PowerLevelsEventContent> power_levels;
|
||||
events::StateEvent<events::TopicEventContent> topic;
|
||||
// The latest state events.
|
||||
events::StateEvent<events::AliasesEventContent> aliases;
|
||||
events::StateEvent<events::AvatarEventContent> avatar;
|
||||
events::StateEvent<events::CanonicalAliasEventContent> canonical_alias;
|
||||
events::StateEvent<events::CreateEventContent> create;
|
||||
events::StateEvent<events::HistoryVisibilityEventContent> history_visibility;
|
||||
events::StateEvent<events::JoinRulesEventContent> join_rules;
|
||||
events::StateEvent<events::NameEventContent> name;
|
||||
events::StateEvent<events::PowerLevelsEventContent> power_levels;
|
||||
events::StateEvent<events::TopicEventContent> topic;
|
||||
|
||||
// Contains the m.room.member events for all the joined users.
|
||||
QMap<QString, events::StateEvent<events::MemberEventContent>> memberships;
|
||||
// Contains the m.room.member events for all the joined users.
|
||||
QMap<QString, events::StateEvent<events::MemberEventContent>> memberships;
|
||||
|
||||
private:
|
||||
QUrl avatar_;
|
||||
QString name_;
|
||||
QUrl avatar_;
|
||||
QString name_;
|
||||
|
||||
// It defines the user whose avatar is used for the room. If the room has an avatar
|
||||
// event this should be empty.
|
||||
QString userAvatar_;
|
||||
// It defines the user whose avatar is used for the room. If the room has an avatar
|
||||
// event this should be empty.
|
||||
QString userAvatar_;
|
||||
};
|
||||
|
||||
inline QString
|
||||
RoomState::getTopic() const
|
||||
{
|
||||
return topic.content().topic().simplified();
|
||||
return topic.content().topic().simplified();
|
||||
}
|
||||
|
||||
inline QString
|
||||
RoomState::getName() const
|
||||
{
|
||||
return name_;
|
||||
return name_;
|
||||
}
|
||||
|
||||
inline QUrl
|
||||
RoomState::getAvatar() const
|
||||
{
|
||||
return avatar_;
|
||||
return avatar_;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue