Skip to content
Snippets Groups Projects
Commit a70caeaf authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Remove special handling of invites in Roomlist

parent 69296e1e
No related branches found
No related tags found
No related merge requests found
......@@ -64,7 +64,6 @@ int main(int argc, char *argv[]) {
Sync sync(rooms, &login);
QObject::connect(&login, &Login::loginSuccess, &sync, &Sync::startSync, Qt::QueuedConnection);
QObject::connect(&sync, &Sync::newRoom, &rooms, &RoomListModel::addRoom, Qt::QueuedConnection);
QObject::connect(&sync, &Sync::newInvite, &rooms, &RoomListModel::addInvite, Qt::QueuedConnection);
QObject::connect(&sync, &Sync::roomUpdated, &rooms, &RoomListModel::updateRoom, Qt::QueuedConnection);
QObject::connect(app.data(), &QGuiApplication::aboutToQuit, &sync, &Sync::exitSync, Qt::QueuedConnection);
RoomListSortProxy roomsSorted;
......
......@@ -4,16 +4,9 @@
#include <QDebug>
QModelIndex RoomListModel::calcIndex(std::string id, const std::vector<QSharedPointer<Room>> &invites,
const std::vector<QSharedPointer<Room>> &other) {
QModelIndex RoomListModel::calcIndex(std::string id) {
int pos = 0;
for (const auto &r : invites) {
if (r->id == id)
return index(pos, 0);
else
pos++;
}
for (const auto &r : other) {
for (const auto &r : rooms) {
if (r->id == id)
return index(pos, 0);
else
......@@ -24,26 +17,18 @@ QModelIndex RoomListModel::calcIndex(std::string id, const std::vector<QSharedPo
}
void RoomListModel::addRoom(QSharedPointer<Room> room) {
int posIdx = (int)(invites.size() + joinedRooms.size());
int posIdx = (int)(rooms.size());
beginInsertRows(QModelIndex(), posIdx, posIdx);
joinedRooms.push_back(room);
rooms.push_back(room);
endInsertRows();
rooms[room->id] = room;
}
void RoomListModel::addInvite(QSharedPointer<Room> room) {
beginInsertRows(QModelIndex(), (int)invites.size(), (int)invites.size());
invites.push_back(room);
endInsertRows();
rooms[room->id] = room;
roomById[room->id] = room;
}
void RoomListModel::updateRoom(QSharedPointer<Room> room) {
rooms[room->id] = room;
roomById[room->id] = room;
auto idx = calcIndex(room->id, invites, joinedRooms);
auto idx = calcIndex(room->id);
if (idx.row() != -1)
emit dataChanged(idx, idx);
}
......@@ -62,7 +47,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
int RoomListModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return (int)invites.size() + joinedRooms.size();
return (int)rooms.size();
}
QVariant RoomListModel::data(const QModelIndex &index, int role) const {
......@@ -70,12 +55,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const {
if (index.row() < 0 || index.row() >= rowCount())
return QVariant();
const auto &room = [this, index]() {
if (index.row() < (int)invites.size())
return invites[index.row()];
else
return joinedRooms[index.row() - invites.size()];
}();
const auto &room = [this, index]() { return rooms[index.row()]; }();
switch (role) {
case RoomModelRole:
......
......@@ -38,21 +38,18 @@ class RoomListModel : public QAbstractListModel {
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QSharedPointer<Room> room(std::string id) { return rooms[id]; }
QSharedPointer<Room> room(std::string id) { return roomById[id]; }
explicit RoomListModel(QObject *parent = 0);
public slots:
void addRoom(QSharedPointer<Room> room);
void addInvite(QSharedPointer<Room> room);
void updateRoom(QSharedPointer<Room> room);
private:
QModelIndex calcIndex(std::string id, const std::vector<QSharedPointer<Room>> &invites,
const std::vector<QSharedPointer<Room>> &other);
std::vector<QSharedPointer<Room>> invites;
std::vector<QSharedPointer<Room>> joinedRooms;
std::map<std::string, QSharedPointer<Room>> rooms;
QModelIndex calcIndex(std::string id);
std::vector<QSharedPointer<Room>> rooms;
std::map<std::string, QSharedPointer<Room>> roomById;
};
#endif // ROOMMODEL_H
......@@ -182,7 +182,7 @@ void Sync::sync() {
room->applyEvents(timeline, "", res.next_batch);
if (createRoom)
emit newInvite(room);
emit newRoom(room);
else
emit roomUpdated(room);
}
......
......@@ -28,7 +28,6 @@ class Sync : public QThread {
signals:
void newRoom(QSharedPointer<Room> room);
void newInvite(QSharedPointer<Room> room);
void roomUpdated(QSharedPointer<Room> room);
void nextSync();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment