React correctly to remotely joined rooms
This commit is contained in:
parent
9a11b73c3c
commit
49acb1a1db
@ -40,6 +40,10 @@ public:
|
||||
void initialize(const Rooms &rooms);
|
||||
// Empty initialization.
|
||||
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 clearAll();
|
||||
|
||||
|
@ -121,7 +121,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||
connect(room_list_, &RoomList::roomChanged, this, &ChatPage::changeTopRoomInfo);
|
||||
connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::focusLineEdit);
|
||||
connect(
|
||||
room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView);
|
||||
room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView);
|
||||
|
||||
connect(view_manager_,
|
||||
&TimelineViewManager::unreadMessages,
|
||||
@ -305,8 +305,9 @@ ChatPage::syncCompleted(const SyncResponse &response)
|
||||
RoomState room_state;
|
||||
|
||||
// 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.updateFromEvents(it.value().state().events());
|
||||
room_state.updateFromEvents(it.value().timeline().events());
|
||||
@ -319,8 +320,35 @@ ChatPage::syncCompleted(const SyncResponse &response)
|
||||
oldState.update(room_state);
|
||||
state_manager_.insert(it.key(), oldState);
|
||||
} else {
|
||||
// TODO: Add newly joined room
|
||||
qWarning() << "New rooms cannot be added after initial sync, yet.";
|
||||
RoomState room_state;
|
||||
|
||||
// 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_)
|
||||
@ -561,15 +589,19 @@ ChatPage::showQuickSwitcher()
|
||||
void
|
||||
ChatPage::joinedRoom(const QString &room_id)
|
||||
{
|
||||
RoomState room_state;
|
||||
if (!state_manager_.contains(room_id)) {
|
||||
RoomState room_state;
|
||||
|
||||
state_manager_.insert(room_id, room_state);
|
||||
settingsManager_.insert(room_id,
|
||||
QSharedPointer<RoomSettings>(new RoomSettings(room_id)));
|
||||
state_manager_.insert(room_id, room_state);
|
||||
settingsManager_.insert(room_id,
|
||||
QSharedPointer<RoomSettings>(new RoomSettings(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);
|
||||
room_list_->highlightSelectedRoom(room_id);
|
||||
}
|
||||
|
||||
this->changeTopRoomInfo(room_id);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -103,9 +103,7 @@ RoomList::addRoom(const QSharedPointer<RoomSettings> &settings,
|
||||
|
||||
rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
|
||||
|
||||
int pos = contentsLayout_->count() - 1;
|
||||
contentsLayout_->insertWidget(pos, room_item);
|
||||
}
|
||||
contentsLayout_->insertWidget(0, room_item);}
|
||||
|
||||
void
|
||||
RoomList::removeRoom(const QString &room_id, bool reset)
|
||||
@ -196,8 +194,9 @@ RoomList::sync(const QMap<QString, RoomState> &states)
|
||||
auto state = it.value();
|
||||
|
||||
// TODO: Add the new room to the list.
|
||||
if (!rooms_.contains(room_id))
|
||||
continue;
|
||||
if (!rooms_.contains(room_id)) {
|
||||
addRoom(QSharedPointer<RoomSettings>(new RoomSettings(room_id)), state, room_id);
|
||||
}
|
||||
|
||||
auto room = rooms_[room_id];
|
||||
|
||||
|
@ -101,19 +101,7 @@ void
|
||||
TimelineViewManager::initialize(const Rooms &rooms)
|
||||
{
|
||||
for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) {
|
||||
auto roomid = 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);
|
||||
addRoom(it.value(), it.key());
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,20 +109,42 @@ void
|
||||
TimelineViewManager::initialize(const QList<QString> &rooms)
|
||||
{
|
||||
for (const auto &roomid : rooms) {
|
||||
// Create a history view without any events.
|
||||
TimelineView *view = new TimelineView(client_, roomid);
|
||||
views_.insert(roomid, QSharedPointer<TimelineView>(view));
|
||||
|
||||
connect(view,
|
||||
&TimelineView::updateLastTimelineMessage,
|
||||
this,
|
||||
&TimelineViewManager::updateRoomsLastMessage);
|
||||
|
||||
// Add the view in the widget stack.
|
||||
addWidget(view);
|
||||
addRoom(roomid);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
&TimelineView::updateLastTimelineMessage,
|
||||
this,
|
||||
&TimelineViewManager::updateRoomsLastMessage);
|
||||
|
||||
// Add the view in the widget stack.
|
||||
addWidget(view);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewManager::sync(const Rooms &rooms)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user