Keep track of newly joined rooms in the settings manager

fixes #134
This commit is contained in:
Konstantinos Sideris 2017-11-21 17:34:32 +02:00
parent 21fdb26bd4
commit 937caddacd
4 changed files with 23 additions and 30 deletions

View file

@ -44,11 +44,12 @@ public:
void setInitialRooms(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
const QMap<QString, RoomState> &states);
void sync(const QMap<QString, RoomState> &states);
void sync(const QMap<QString, RoomState> &states,
QMap<QString, QSharedPointer<RoomSettings>> &settings);
void clear();
void addRoom(const QSharedPointer<RoomSettings> &settings,
void addRoom(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
const RoomState &state,
const QString &room_id);
void removeRoom(const QString &room_id, bool reset);

View file

@ -362,7 +362,7 @@ ChatPage::syncCompleted(const SyncResponse &response)
auto stateDiff = generateMembershipDifference(response.rooms().join(), state_manager_);
QtConcurrent::run(cache_.data(), &Cache::setState, response.nextBatch(), stateDiff);
room_list_->sync(state_manager_);
room_list_->sync(state_manager_, settingsManager_);
view_manager_->sync(response.rooms());
client_->setNextBatchToken(response.nextBatch());
@ -570,7 +570,7 @@ ChatPage::addRoom(const QString &room_id)
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_, state_manager_[room_id], room_id);
room_list_->highlightSelectedRoom(room_id);
changeTopRoomInfo(room_id);
@ -710,7 +710,6 @@ ChatPage::updateJoinedRooms(const QMap<QString, JoinedRoom> &rooms)
state_manager_.insert(it.key(), room_state);
// TODO Doesn't work on the sidebar.
settingsManager_.insert(
it.key(), QSharedPointer<RoomSettings>(new RoomSettings(it.key())));

View file

@ -72,19 +72,22 @@ RoomList::clear()
}
void
RoomList::addRoom(const QSharedPointer<RoomSettings> &settings,
RoomList::addRoom(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
const RoomState &state,
const QString &room_id)
{
RoomInfoListItem *room_item = new RoomInfoListItem(settings, state, room_id, scrollArea_);
RoomInfoListItem *room_item =
new RoomInfoListItem(settings[room_id], state, room_id, scrollArea_);
connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom);
connect(room_item, &RoomInfoListItem::leaveRoom, this, &RoomList::openLeaveRoomDialog);
rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
client_->fetchRoomAvatar(room_id, state.getAvatar());
if (!state.getAvatar().toString().isEmpty())
client_->fetchRoomAvatar(room_id, state.getAvatar());
contentsLayout_->insertWidget(0, room_item);
int pos = contentsLayout_->count() - 1;
contentsLayout_->insertWidget(pos, room_item);
}
void
@ -138,23 +141,10 @@ RoomList::setInitialRooms(const QMap<QString, QSharedPointer<RoomSettings>> &set
}
for (auto it = states.constBegin(); it != states.constEnd(); ++it) {
auto room_id = it.key();
auto state = it.value();
const auto room_id = it.key();
const auto state = it.value();
if (!state.getAvatar().toString().isEmpty())
client_->fetchRoomAvatar(room_id, state.getAvatar());
RoomInfoListItem *room_item =
new RoomInfoListItem(settings[room_id], state, room_id, scrollArea_);
connect(
room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom);
connect(
room_item, &RoomInfoListItem::leaveRoom, this, &RoomList::openLeaveRoomDialog);
rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
int pos = contentsLayout_->count() - 1;
contentsLayout_->insertWidget(pos, room_item);
addRoom(settings, state, room_id);
}
if (rooms_.isEmpty())
@ -189,15 +179,18 @@ RoomList::openLeaveRoomDialog(const QString &room_id)
}
void
RoomList::sync(const QMap<QString, RoomState> &states)
RoomList::sync(const QMap<QString, RoomState> &states,
QMap<QString, QSharedPointer<RoomSettings>> &settings)
{
for (auto it = states.constBegin(); it != states.constEnd(); ++it) {
auto room_id = it.key();
auto state = it.value();
if (!rooms_.contains(room_id)) {
addRoom(
QSharedPointer<RoomSettings>(new RoomSettings(room_id)), state, room_id);
settings.insert(room_id,
QSharedPointer<RoomSettings>(new RoomSettings(room_id)));
addRoom(settings, state, room_id);
}
auto room = rooms_[room_id];

View file

@ -133,8 +133,8 @@ FilteredTextEdit::minimumSizeHint() const
void
FilteredTextEdit::submit()
{
if (toPlainText().trimmed().isEmpty())
return;
if (toPlainText().trimmed().isEmpty())
return;
if (true_history_.size() == INPUT_HISTORY_SIZE)
true_history_.pop_back();