React correctly to remotely joined rooms

This commit is contained in:
Max Sandholm 2017-09-28 15:31:59 +03:00 committed by vurpo
parent 9a11b73c3c
commit 49acb1a1db
4 changed files with 84 additions and 39 deletions

View File

@ -40,6 +40,10 @@ public:
void initialize(const Rooms &rooms); void initialize(const Rooms &rooms);
// Empty initialization. // Empty initialization.
void initialize(const QList<QString> &rooms); void initialize(const QList<QString> &rooms);
void addRoom(const JoinedRoom &room, const QString &room_id);
void addRoom(const QString &room_id);
void sync(const Rooms &rooms); void sync(const Rooms &rooms);
void clearAll(); void clearAll();

View File

@ -305,8 +305,9 @@ ChatPage::syncCompleted(const SyncResponse &response)
RoomState room_state; RoomState room_state;
// Merge the new updates for rooms that we are tracking. // Merge the new updates for rooms that we are tracking.
if (state_manager_.contains(it.key())) if (state_manager_.contains(it.key())) {
room_state = state_manager_[it.key()]; room_state = state_manager_[it.key()];
}
room_state.updateFromEvents(it.value().state().events()); room_state.updateFromEvents(it.value().state().events());
room_state.updateFromEvents(it.value().timeline().events()); room_state.updateFromEvents(it.value().timeline().events());
@ -319,8 +320,35 @@ ChatPage::syncCompleted(const SyncResponse &response)
oldState.update(room_state); oldState.update(room_state);
state_manager_.insert(it.key(), oldState); state_manager_.insert(it.key(), oldState);
} else { } else {
// TODO: Add newly joined room RoomState room_state;
qWarning() << "New rooms cannot be added after initial sync, yet.";
// Build the current state from the timeline and state events.
room_state.updateFromEvents(it.value().state().events());
room_state.updateFromEvents(it.value().timeline().events());
// Remove redundant memberships.
room_state.removeLeaveMemberships();
// Resolve room name and avatar. e.g in case of one-to-one chats.
room_state.resolveName();
room_state.resolveAvatar();
updateDisplayNames(room_state);
state_manager_.insert(it.key(), room_state);
settingsManager_.insert(it.key(),
QSharedPointer<RoomSettings>(new RoomSettings(it.key())));
for (const auto membership : room_state.memberships) {
auto uid = membership.sender();
auto url = membership.content().avatarUrl();
if (!url.toString().isEmpty())
AvatarProvider::setAvatarUrl(uid, url);
}
view_manager_->addRoom(it.value(), it.key());
} }
if (it.key() == current_room_) if (it.key() == current_room_)
@ -561,6 +589,7 @@ ChatPage::showQuickSwitcher()
void void
ChatPage::joinedRoom(const QString &room_id) ChatPage::joinedRoom(const QString &room_id)
{ {
if (!state_manager_.contains(room_id)) {
RoomState room_state; RoomState room_state;
state_manager_.insert(room_id, room_state); state_manager_.insert(room_id, room_state);
@ -570,6 +599,9 @@ ChatPage::joinedRoom(const QString &room_id)
room_list_->addRoom(settingsManager_[room_id], state_manager_[room_id], room_id); room_list_->addRoom(settingsManager_[room_id], state_manager_[room_id], room_id);
this->changeTopRoomInfo(room_id); this->changeTopRoomInfo(room_id);
room_list_->highlightSelectedRoom(room_id);
}
} }
void void

View File

@ -103,9 +103,7 @@ RoomList::addRoom(const QSharedPointer<RoomSettings> &settings,
rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item)); rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
int pos = contentsLayout_->count() - 1; contentsLayout_->insertWidget(0, room_item);}
contentsLayout_->insertWidget(pos, room_item);
}
void void
RoomList::removeRoom(const QString &room_id, bool reset) RoomList::removeRoom(const QString &room_id, bool reset)
@ -196,8 +194,9 @@ RoomList::sync(const QMap<QString, RoomState> &states)
auto state = it.value(); auto state = it.value();
// TODO: Add the new room to the list. // TODO: Add the new room to the list.
if (!rooms_.contains(room_id)) if (!rooms_.contains(room_id)) {
continue; addRoom(QSharedPointer<RoomSettings>(new RoomSettings(room_id)), state, room_id);
}
auto room = rooms_[room_id]; auto room = rooms_[room_id];

View File

@ -101,19 +101,7 @@ void
TimelineViewManager::initialize(const Rooms &rooms) TimelineViewManager::initialize(const Rooms &rooms)
{ {
for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) {
auto roomid = it.key(); addRoom(it.value(), it.key());
// Create a history view with the room events.
TimelineView *view = new TimelineView(it.value().timeline(), client_, it.key());
views_.insert(it.key(), QSharedPointer<TimelineView>(view));
connect(view,
&TimelineView::updateLastTimelineMessage,
this,
&TimelineViewManager::updateRoomsLastMessage);
// Add the view in the widget stack.
addWidget(view);
} }
} }
@ -121,9 +109,32 @@ void
TimelineViewManager::initialize(const QList<QString> &rooms) TimelineViewManager::initialize(const QList<QString> &rooms)
{ {
for (const auto &roomid : rooms) { for (const auto &roomid : rooms) {
// Create a history view without any events. addRoom(roomid);
TimelineView *view = new TimelineView(client_, roomid); }
views_.insert(roomid, QSharedPointer<TimelineView>(view)); }
void
TimelineViewManager::addRoom(const JoinedRoom &room, const QString &room_id)
{
// Create a history view with the room events.
TimelineView *view = new TimelineView(room.timeline(), client_, room_id);
views_.insert(room_id, QSharedPointer<TimelineView>(view));
connect(view,
&TimelineView::updateLastTimelineMessage,
this,
&TimelineViewManager::updateRoomsLastMessage);
// Add the view in the widget stack.
addWidget(view);
}
void
TimelineViewManager::addRoom(const QString &room_id)
{
// Create a history view without any events.
TimelineView *view = new TimelineView(client_, room_id);
views_.insert(room_id, QSharedPointer<TimelineView>(view));
connect(view, connect(view,
&TimelineView::updateLastTimelineMessage, &TimelineView::updateLastTimelineMessage,
@ -132,7 +143,6 @@ TimelineViewManager::initialize(const QList<QString> &rooms)
// Add the view in the widget stack. // Add the view in the widget stack.
addWidget(view); addWidget(view);
}
} }
void void