Cleanup userlistmodel
This commit is contained in:
@@ -55,7 +55,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const
|
||||
return m_filterModel->data(filterIndex, UserListModel::NameRole);
|
||||
}
|
||||
if (role == Subtitle) {
|
||||
return m_filterModel->data(filterIndex, UserListModel::UserIDRole);
|
||||
return m_filterModel->data(filterIndex, UserListModel::UserIdRole);
|
||||
}
|
||||
if (role == Icon) {
|
||||
return m_filterModel->data(filterIndex, UserListModel::AvatarRole);
|
||||
@@ -114,7 +114,7 @@ void CompletionModel::updateCompletion()
|
||||
{
|
||||
if (text().startsWith(QLatin1Char('@'))) {
|
||||
m_filterModel->setSourceModel(m_userListModel);
|
||||
m_filterModel->setFilterRole(UserListModel::UserIDRole);
|
||||
m_filterModel->setFilterRole(UserListModel::UserIdRole);
|
||||
m_filterModel->setSecondaryFilterRole(UserListModel::NameRole);
|
||||
m_filterModel->setFullText(m_fullText);
|
||||
m_filterModel->setFilterText(m_text);
|
||||
|
||||
@@ -17,7 +17,7 @@ UserListModel::UserListModel(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
void UserListModel::setRoom(Quotient::Room *room)
|
||||
void UserListModel::setRoom(NeoChatRoom *room)
|
||||
{
|
||||
if (m_currentRoom == room) {
|
||||
return;
|
||||
@@ -51,15 +51,19 @@ void UserListModel::setRoom(Quotient::Room *room)
|
||||
connect(user, &User::avatarChanged, this, &UserListModel::avatarChanged);
|
||||
#endif
|
||||
}
|
||||
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this] {
|
||||
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this]() {
|
||||
setRoom(nullptr);
|
||||
});
|
||||
qDebug() << m_users.count() << "user(s) in the room";
|
||||
}
|
||||
endResetModel();
|
||||
Q_EMIT roomChanged();
|
||||
}
|
||||
|
||||
NeoChatRoom *UserListModel::room() const
|
||||
{
|
||||
return m_currentRoom;
|
||||
}
|
||||
|
||||
Quotient::User *UserListModel::userAt(QModelIndex index) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_users.size()) {
|
||||
@@ -75,14 +79,13 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
if (index.row() >= m_users.count()) {
|
||||
qDebug() << "UserListModel, something's wrong: index.row() >= m_users.count()";
|
||||
return {};
|
||||
return QStringLiteral("DEADBEEF");
|
||||
}
|
||||
auto user = m_users.at(index.row());
|
||||
if (role == NameRole) {
|
||||
return user->displayname(m_currentRoom);
|
||||
}
|
||||
if (role == UserIDRole) {
|
||||
if (role == UserIdRole) {
|
||||
return user->id();
|
||||
}
|
||||
if (role == AvatarRole) {
|
||||
@@ -187,7 +190,7 @@ void UserListModel::avatarChanged(Quotient::User *user, const Quotient::Room *co
|
||||
}
|
||||
}
|
||||
|
||||
int UserListModel::findUserPos(User *user) const
|
||||
int UserListModel::findUserPos(Quotient::User *user) const
|
||||
{
|
||||
return findUserPos(m_currentRoom->roomMembername(user));
|
||||
}
|
||||
@@ -202,7 +205,7 @@ QHash<int, QByteArray> UserListModel::roleNames() const
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[NameRole] = "name";
|
||||
roles[UserIDRole] = "userId";
|
||||
roles[UserIdRole] = "userId";
|
||||
roles[AvatarRole] = "avatar";
|
||||
roles[ObjectRole] = "user";
|
||||
roles[PermRole] = "perm";
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QObject>
|
||||
|
||||
class NeoChatRoom;
|
||||
|
||||
namespace Quotient
|
||||
{
|
||||
class Connection;
|
||||
class Room;
|
||||
class User;
|
||||
class Room;
|
||||
}
|
||||
|
||||
class UserType : public QObject
|
||||
@@ -31,11 +32,11 @@ public:
|
||||
class UserListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Quotient::Room *room READ room WRITE setRoom NOTIFY roomChanged)
|
||||
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
|
||||
public:
|
||||
enum EventRoles {
|
||||
NameRole = Qt::DisplayRole,
|
||||
UserIDRole,
|
||||
NameRole = Qt::UserRole + 1,
|
||||
UserIdRole,
|
||||
AvatarRole,
|
||||
ObjectRole,
|
||||
PermRole,
|
||||
@@ -43,11 +44,9 @@ public:
|
||||
|
||||
UserListModel(QObject *parent = nullptr);
|
||||
|
||||
[[nodiscard]] Quotient::Room *room() const
|
||||
{
|
||||
return m_currentRoom;
|
||||
}
|
||||
void setRoom(Quotient::Room *room);
|
||||
[[nodiscard]] NeoChatRoom *room() const;
|
||||
void setRoom(NeoChatRoom *room);
|
||||
|
||||
[[nodiscard]] Quotient::User *userAt(QModelIndex index) const;
|
||||
|
||||
[[nodiscard]] QVariant data(const QModelIndex &index, int role = NameRole) const override;
|
||||
@@ -65,7 +64,7 @@ private Q_SLOTS:
|
||||
void avatarChanged(Quotient::User *user, const Quotient::Room *context);
|
||||
|
||||
private:
|
||||
Quotient::Room *m_currentRoom;
|
||||
NeoChatRoom *m_currentRoom;
|
||||
QList<Quotient::User *> m_users;
|
||||
|
||||
int findUserPos(Quotient::User *user) const;
|
||||
|
||||
Reference in New Issue
Block a user