2021-05-19 20:34:10 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QSharedPointer>
|
2021-05-22 01:57:14 +03:00
|
|
|
#include <QSortFilterProxyModel>
|
2021-05-19 20:34:10 +03:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <mtx/responses/sync.hpp>
|
|
|
|
|
|
|
|
class TimelineModel;
|
|
|
|
class TimelineViewManager;
|
|
|
|
|
|
|
|
class RoomlistModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
AvatarUrl = Qt::UserRole,
|
|
|
|
RoomName,
|
2021-05-21 22:19:03 +03:00
|
|
|
RoomId,
|
2021-05-19 20:34:10 +03:00
|
|
|
LastMessage,
|
2021-05-22 01:57:14 +03:00
|
|
|
Time,
|
2021-05-21 22:19:03 +03:00
|
|
|
Timestamp,
|
2021-05-19 20:34:10 +03:00
|
|
|
HasUnreadMessages,
|
2021-05-21 22:19:03 +03:00
|
|
|
HasLoudNotification,
|
2021-05-19 20:34:10 +03:00
|
|
|
NotificationCount,
|
2021-05-22 01:57:14 +03:00
|
|
|
IsInvite,
|
|
|
|
IsSpace,
|
2021-05-19 20:34:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
RoomlistModel(TimelineViewManager *parent = nullptr);
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
|
|
|
{
|
|
|
|
(void)parent;
|
|
|
|
return (int)roomids.size();
|
|
|
|
}
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
QSharedPointer<TimelineModel> getRoomById(QString id) const
|
|
|
|
{
|
|
|
|
if (models.contains(id))
|
|
|
|
return models.value(id);
|
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void initializeRooms(const std::vector<QString> &roomids);
|
|
|
|
void sync(const mtx::responses::Rooms &rooms);
|
|
|
|
void clear();
|
2021-05-21 22:19:03 +03:00
|
|
|
int roomidToIndex(QString roomid)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < (int)roomids.size(); i++) {
|
|
|
|
if (roomids[i] == roomid)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateReadStatus(const std::map<QString, bool> roomReadStatus_);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void totalUnreadMessageCountUpdated(int unreadMessages);
|
2021-05-19 20:34:10 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void addRoom(const QString &room_id, bool suppressInsertNotification = false);
|
|
|
|
|
|
|
|
TimelineViewManager *manager = nullptr;
|
|
|
|
std::vector<QString> roomids;
|
|
|
|
QHash<QString, QSharedPointer<TimelineModel>> models;
|
2021-05-21 22:19:03 +03:00
|
|
|
std::map<QString, bool> roomReadStatus;
|
2021-05-22 01:57:14 +03:00
|
|
|
|
|
|
|
friend class FilteredRoomlistModel;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FilteredRoomlistModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr);
|
|
|
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
int roomidToIndex(QString roomid)
|
|
|
|
{
|
|
|
|
return mapFromSource(roomlistmodel->index(roomlistmodel->roomidToIndex(roomid)))
|
|
|
|
.row();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
short int calculateImportance(const QModelIndex &idx) const;
|
|
|
|
RoomlistModel *roomlistmodel;
|
|
|
|
bool sortByImportance = true;
|
2021-05-19 20:34:10 +03:00
|
|
|
};
|