Make use of new RoomMember item from libquotient
Depends on https://github.com/quotient-im/libQuotient/pull/695 Currently basic just to show a working implementation using RoomMember. Currently only the room event and search models are moved over. Will change everything else over once the dependent pr is complete.
This commit is contained in:
committed by
Tobias Fella
parent
58d727350d
commit
430bafafe7
@@ -9,6 +9,7 @@
|
||||
#include "roommanager.h"
|
||||
#include <Quotient/events/roommemberevent.h>
|
||||
#include <Quotient/events/roompowerlevelsevent.h>
|
||||
#include <Quotient/user.h>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
@@ -202,11 +203,11 @@ QList<ActionsModel::Action> actions{
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is banned from this room.", "%1 is banned from this room.", text));
|
||||
return QString();
|
||||
}
|
||||
if (room->localUser()->id() == text) {
|
||||
if (room->localMember().id() == text) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18n("You are already in this room."));
|
||||
return QString();
|
||||
}
|
||||
if (room->users().contains(room->user(text))) {
|
||||
if (room->members().contains(room->member(text))) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is already in this room.", "%1 is already in this room.", text));
|
||||
return QString();
|
||||
}
|
||||
@@ -359,7 +360,7 @@ QList<ActionsModel::Action> actions{
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is already ignored.", "%1 is already ignored.", text));
|
||||
return QString();
|
||||
}
|
||||
room->connection()->addToIgnoredUsers(room->connection()->user(text));
|
||||
room->connection()->addToIgnoredUsers(text);
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18nc("<username> is now ignored", "%1 is now ignored.", text));
|
||||
return QString();
|
||||
},
|
||||
@@ -382,7 +383,7 @@ QList<ActionsModel::Action> actions{
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is not ignored.", "%1 is not ignored.", text));
|
||||
return QString();
|
||||
}
|
||||
room->connection()->removeFromIgnoredUsers(room->connection()->user(text));
|
||||
room->connection()->removeFromIgnoredUsers(text);
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18nc("<username> is no longer ignored.", "%1 is no longer ignored.", text));
|
||||
return QString();
|
||||
},
|
||||
@@ -431,11 +432,11 @@ QList<ActionsModel::Action> actions{
|
||||
if (!plEvent) {
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) {
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to ban users from this room."));
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
Q_EMIT room->showMessage(
|
||||
NeoChatRoom::Error,
|
||||
i18nc("You are not allowed to ban <username> from this room.", "You are not allowed to ban %1 from this room.", parts[0]));
|
||||
@@ -464,7 +465,7 @@ QList<ActionsModel::Action> actions{
|
||||
if (!plEvent) {
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) {
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to unban users from this room."));
|
||||
return QString();
|
||||
}
|
||||
@@ -495,7 +496,7 @@ QList<ActionsModel::Action> actions{
|
||||
i18nc("'<text>' does not look like a matrix id.", "'%1' does not look like a matrix id.", parts[0]));
|
||||
return QString();
|
||||
}
|
||||
if (parts[0] == room->localUser()->id()) {
|
||||
if (parts[0] == room->localMember().id()) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You cannot kick yourself from the room."));
|
||||
return QString();
|
||||
}
|
||||
@@ -508,11 +509,11 @@ QList<ActionsModel::Action> actions{
|
||||
return QString();
|
||||
}
|
||||
auto kick = plEvent->kick();
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) < kick) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) < kick) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to kick users from this room."));
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
Q_EMIT room->showMessage(
|
||||
NeoChatRoom::Error,
|
||||
i18nc("You are not allowed to kick <username> from this room", "You are not allowed to kick %1 from this room.", parts[0]));
|
||||
|
||||
@@ -80,7 +80,7 @@ QVariant LiveLocationsModel::data(const QModelIndex &index, int roleName) const
|
||||
case AssetRole:
|
||||
return data.beaconInfo["org.matrix.msc3488.asset"_ls].toObject()["type"_ls].toString();
|
||||
case AuthorRole:
|
||||
return m_room->getUser(data.senderId);
|
||||
return QVariant::fromValue(m_room->member(data.senderId));
|
||||
case IsLiveRole: {
|
||||
if (!data.beaconInfo["live"_ls].toBool()) {
|
||||
return false;
|
||||
|
||||
@@ -63,7 +63,7 @@ void LocationsModel::addLocation(const RoomMessageEvent *event)
|
||||
.latitude = latitude,
|
||||
.longitude = longitude,
|
||||
.content = event->contentJson(),
|
||||
.author = m_room->user(event->senderId()),
|
||||
.member = m_room->member(event->senderId()),
|
||||
};
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -105,7 +105,7 @@ QVariant LocationsModel::data(const QModelIndex &index, int roleName) const
|
||||
} else if (roleName == AssetRole) {
|
||||
return m_locations[row].content["org.matrix.msc3488.asset"_ls].toObject()["type"_ls].toString();
|
||||
} else if (roleName == AuthorRole) {
|
||||
return m_room->getUser(m_locations[row].author);
|
||||
return QVariant::fromValue(m_locations[row].member);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "neochatroom.h"
|
||||
|
||||
#include <Quotient/events/roommessageevent.h>
|
||||
#include <Quotient/user.h>
|
||||
#include <Quotient/roommember.h>
|
||||
|
||||
class LocationsModel : public QAbstractListModel
|
||||
{
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
float latitude;
|
||||
float longitude;
|
||||
QJsonObject content;
|
||||
Quotient::User *author;
|
||||
Quotient::RoomMember member;
|
||||
};
|
||||
QList<LocationData> m_locations;
|
||||
void addLocation(const Quotient::RoomMessageEvent *event);
|
||||
|
||||
@@ -194,7 +194,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
||||
return eventHandler.getId();
|
||||
}
|
||||
if (role == AuthorRole) {
|
||||
return eventHandler.getAuthor(false);
|
||||
return QVariant::fromValue(eventHandler.getAuthor(false));
|
||||
}
|
||||
if (role == MediaInfoRole) {
|
||||
return eventHandler.getMediaInfo();
|
||||
@@ -224,7 +224,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
||||
return eventHandler.getReplyId();
|
||||
}
|
||||
if (role == ReplyAuthorRole) {
|
||||
return eventHandler.getReplyAuthor();
|
||||
return QVariant::fromValue(eventHandler.getReplyAuthor());
|
||||
}
|
||||
if (role == ReplyContentModelRole) {
|
||||
return QVariant::fromValue<MessageContentModel *>(m_replyModel);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Quotient/events/redactionevent.h>
|
||||
#include <Quotient/events/roommessageevent.h>
|
||||
#include <Quotient/events/stickerevent.h>
|
||||
#include <Quotient/user.h>
|
||||
#include <Quotient/roommember.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
@@ -222,7 +222,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
});
|
||||
qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localUser()->id();
|
||||
qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localMember().id();
|
||||
} else {
|
||||
lastReadEventId.clear();
|
||||
}
|
||||
@@ -460,7 +460,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
||||
}
|
||||
|
||||
if (role == AuthorRole) {
|
||||
return eventHandler.getAuthor(isPending);
|
||||
return QVariant::fromValue(eventHandler.getAuthor(isPending));
|
||||
}
|
||||
|
||||
if (role == HighlightRole) {
|
||||
@@ -539,7 +539,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
||||
}
|
||||
|
||||
if (role == ReadMarkersRole) {
|
||||
return eventHandler.getReadMarkers();
|
||||
return QVariant::fromValue(eventHandler.getReadMarkers());
|
||||
}
|
||||
|
||||
if (role == ExcessReadMarkersRole) {
|
||||
@@ -592,7 +592,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
||||
}
|
||||
|
||||
if (role == IsEditableRole) {
|
||||
return eventHandler.messageComponentType() == MessageComponentType::Text && evt.senderId() == m_currentRoom->localUser()->id();
|
||||
return eventHandler.messageComponentType() == MessageComponentType::Text && evt.senderId() == m_currentRoom->localMember().id();
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
@@ -116,7 +116,7 @@ void NotificationsModel::loadData()
|
||||
if (!room) {
|
||||
continue;
|
||||
}
|
||||
auto u = room->memberAvatarUrl(authorId);
|
||||
auto u = room->member(authorId).avatarUrl();
|
||||
auto avatar = u.isEmpty() ? QUrl() : connection()->makeMediaUrl(u);
|
||||
const auto &authorAvatar = avatar.isValid() && avatar.scheme() == QStringLiteral("mxc") ? avatar : QUrl();
|
||||
|
||||
@@ -125,9 +125,9 @@ void NotificationsModel::loadData()
|
||||
beginInsertRows({}, m_notifications.length(), m_notifications.length());
|
||||
m_notifications += Notification{
|
||||
.roomId = notification.roomId,
|
||||
.text = room->htmlSafeMemberName(authorId) + (roomEvent->is<StateEvent>() ? QStringLiteral(" ") : QStringLiteral(": "))
|
||||
.text = room->member(authorId).htmlSafeDisplayName() + (roomEvent->is<StateEvent>() ? QStringLiteral(" ") : QStringLiteral(": "))
|
||||
+ eventHandler.getPlainBody(true),
|
||||
.authorName = room->htmlSafeMemberName(authorId),
|
||||
.authorName = room->member(authorId).htmlSafeDisplayName(),
|
||||
.authorAvatar = authorAvatar,
|
||||
.eventId = roomEvent->id(),
|
||||
.roomDisplayName = room->displayName(),
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include <Quotient/user.h>
|
||||
#include <Quotient/roommember.h>
|
||||
|
||||
ReactionModel::ReactionModel(const Quotient::RoomMessageEvent *event, NeoChatRoom *room)
|
||||
: QAbstractListModel(nullptr)
|
||||
@@ -69,8 +69,7 @@ QVariant ReactionModel::data(const QModelIndex &index, int role) const
|
||||
text += i18nc("Separate the usernames of users", " and ");
|
||||
}
|
||||
}
|
||||
auto displayName = reaction.authors.at(i).toMap()[QStringLiteral("displayName")].toString();
|
||||
text += displayName.isEmpty() ? reaction.authors.at(i).toMap()[QStringLiteral("id")].toString() : displayName;
|
||||
text += reaction.authors.at(i).displayName();
|
||||
}
|
||||
|
||||
if (reaction.authors.count() > 3) {
|
||||
@@ -86,13 +85,9 @@ QVariant ReactionModel::data(const QModelIndex &index, int role) const
|
||||
return text;
|
||||
}
|
||||
|
||||
if (role == AuthorsRole) {
|
||||
return reaction.authors;
|
||||
}
|
||||
|
||||
if (role == HasLocalUser) {
|
||||
if (role == HasLocalMember) {
|
||||
for (auto author : reaction.authors) {
|
||||
if (author.toMap()[QStringLiteral("id")] == m_room->localUser()->id()) {
|
||||
if (author.id() == m_room->localMember().id()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -121,13 +116,13 @@ void ReactionModel::updateReactions()
|
||||
return;
|
||||
};
|
||||
|
||||
QMap<QString, QList<Quotient::User *>> reactions = {};
|
||||
QMap<QString, QList<Quotient::RoomMember>> reactions = {};
|
||||
for (const auto &a : annotations) {
|
||||
if (a->isRedacted()) { // Just in case?
|
||||
continue;
|
||||
}
|
||||
if (const auto &e = eventCast<const Quotient::ReactionEvent>(a)) {
|
||||
reactions[e->key()].append(m_room->user(e->senderId()));
|
||||
reactions[e->key()].append(m_room->member(e->senderId()));
|
||||
if (e->contentJson()[QStringLiteral("shortcode")].toString().length()) {
|
||||
m_shortcodes[e->key()] = e->contentJson()[QStringLiteral("shortcode")].toString().toHtmlEscaped();
|
||||
}
|
||||
@@ -138,15 +133,14 @@ void ReactionModel::updateReactions()
|
||||
endResetModel();
|
||||
return;
|
||||
}
|
||||
|
||||
auto i = reactions.constBegin();
|
||||
while (i != reactions.constEnd()) {
|
||||
QVariantList authors;
|
||||
for (const auto &author : i.value()) {
|
||||
authors.append(m_room->getUser(author));
|
||||
QList<Quotient::RoomMember> members;
|
||||
for (const auto &member : i.value()) {
|
||||
members.append(member);
|
||||
}
|
||||
|
||||
m_reactions.append(ReactionModel::Reaction{i.key(), authors});
|
||||
m_reactions.append(ReactionModel::Reaction{i.key(), members});
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -159,8 +153,7 @@ QHash<int, QByteArray> ReactionModel::roleNames() const
|
||||
{TextContentRole, "textContent"},
|
||||
{ReactionRole, "reaction"},
|
||||
{ToolTipRole, "toolTip"},
|
||||
{AuthorsRole, "authors"},
|
||||
{HasLocalUser, "hasLocalUser"},
|
||||
{HasLocalMember, "hasLocalMember"},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,8 @@
|
||||
|
||||
#include "neochatroom.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QQmlEngine>
|
||||
#include <Quotient/events/reactionevent.h>
|
||||
|
||||
namespace Quotient
|
||||
{
|
||||
class User;
|
||||
}
|
||||
#include <Quotient/roommember.h>
|
||||
|
||||
/**
|
||||
* @class ReactionModel
|
||||
@@ -30,7 +25,7 @@ public:
|
||||
*/
|
||||
struct Reaction {
|
||||
QString reaction; /**< The reaction emoji. */
|
||||
QVariantList authors; /**< The list of authors who sent the given reaction. */
|
||||
QList<Quotient::RoomMember> authors; /**< The list of authors who sent the given reaction. */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -40,8 +35,7 @@ public:
|
||||
TextContentRole = Qt::DisplayRole, /**< The text to show in the reaction. */
|
||||
ReactionRole, /**< The reaction emoji. */
|
||||
ToolTipRole, /**< The tool tip to show for the reaction. */
|
||||
AuthorsRole, /**< The list of authors who sent the given reaction. */
|
||||
HasLocalUser, /**< Whether the local user is in the list of authors. */
|
||||
HasLocalMember, /**< Whether the local member is in the list of authors. */
|
||||
};
|
||||
|
||||
explicit ReactionModel(const Quotient::RoomMessageEvent *event, NeoChatRoom *room);
|
||||
|
||||
@@ -85,7 +85,7 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
||||
case ShowAuthorRole:
|
||||
return true;
|
||||
case AuthorRole:
|
||||
return eventHandler.getAuthor();
|
||||
return QVariant::fromValue(eventHandler.getAuthor());
|
||||
case ShowSectionRole:
|
||||
if (row == 0) {
|
||||
return true;
|
||||
|
||||
@@ -26,18 +26,26 @@ void UserListModel::setRoom(NeoChatRoom *room)
|
||||
|
||||
if (m_currentRoom) {
|
||||
m_currentRoom->disconnect(this);
|
||||
m_currentRoom->connection()->disconnect(this);
|
||||
}
|
||||
m_currentRoom = room;
|
||||
|
||||
if (m_currentRoom) {
|
||||
connect(m_currentRoom, &Room::userAdded, this, &UserListModel::userAdded);
|
||||
connect(m_currentRoom, &Room::userRemoved, this, &UserListModel::userRemoved);
|
||||
connect(m_currentRoom, &Room::memberAboutToRename, this, &UserListModel::userRemoved);
|
||||
connect(m_currentRoom, &Room::memberRenamed, this, &UserListModel::userAdded);
|
||||
connect(m_currentRoom, &Room::changed, this, &UserListModel::refreshAllUsers);
|
||||
connect(m_currentRoom, &Room::memberJoined, this, &UserListModel::memberJoined);
|
||||
connect(m_currentRoom, &Room::memberLeft, this, &UserListModel::memberLeft);
|
||||
connect(m_currentRoom, &Room::memberNameUpdated, this, [this](RoomMember member) {
|
||||
refreshMember(member, {DisplayNameRole});
|
||||
});
|
||||
connect(m_currentRoom, &Room::memberAvatarUpdated, this, [this](RoomMember member) {
|
||||
refreshMember(member, {AvatarRole});
|
||||
});
|
||||
connect(m_currentRoom, &Room::changed, this, &UserListModel::refreshAllMembers);
|
||||
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this]() {
|
||||
setRoom(nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
refreshAllUsers();
|
||||
refreshAllMembers();
|
||||
Q_EMIT roomChanged();
|
||||
}
|
||||
|
||||
@@ -46,44 +54,36 @@ NeoChatRoom *UserListModel::room() const
|
||||
return m_currentRoom;
|
||||
}
|
||||
|
||||
Quotient::User *UserListModel::userAt(QModelIndex index) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= m_users.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_users.at(index.row());
|
||||
}
|
||||
|
||||
QVariant UserListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (index.row() >= m_users.count()) {
|
||||
if (index.row() >= m_members.count()) {
|
||||
qDebug() << "UserListModel, something's wrong: index.row() >= "
|
||||
"users.count()";
|
||||
return {};
|
||||
}
|
||||
auto user = m_users.at(index.row());
|
||||
auto member = m_members.at(index.row());
|
||||
if (role == DisplayNameRole) {
|
||||
return user->displayname(m_currentRoom);
|
||||
return member.disambiguatedName();
|
||||
}
|
||||
if (role == UserIdRole) {
|
||||
return user->id();
|
||||
return member.id();
|
||||
}
|
||||
if (role == AvatarRole) {
|
||||
return m_currentRoom->avatarForMember(user);
|
||||
return member.avatarUrl();
|
||||
}
|
||||
if (role == ObjectRole) {
|
||||
return QVariant::fromValue(user);
|
||||
return QVariant::fromValue(member);
|
||||
}
|
||||
if (role == PowerLevelRole) {
|
||||
auto plEvent = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
||||
if (!plEvent) {
|
||||
return 0;
|
||||
}
|
||||
return plEvent->powerLevelForUser(user->id());
|
||||
return plEvent->powerLevelForUser(member.id());
|
||||
}
|
||||
if (role == PowerLevelStringRole) {
|
||||
auto pl = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
||||
@@ -93,7 +93,7 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
|
||||
return QStringLiteral("Not Available");
|
||||
}
|
||||
|
||||
auto userPl = pl->powerLevelForUser(user->id());
|
||||
auto userPl = pl->powerLevelForUser(member.id());
|
||||
|
||||
return i18nc("%1 is the name of the power level, e.g. admin and %2 is the value that represents.",
|
||||
"%1 (%2)",
|
||||
@@ -109,79 +109,63 @@ int UserListModel::rowCount(const QModelIndex &parent) const
|
||||
if (parent.isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return m_users.count();
|
||||
return m_members.count();
|
||||
}
|
||||
|
||||
bool UserListModel::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::ApplicationPaletteChange) {
|
||||
refreshAllUsers();
|
||||
refreshAllMembers();
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void UserListModel::userAdded(Quotient::User *user)
|
||||
void UserListModel::memberJoined(const Quotient::RoomMember &member)
|
||||
{
|
||||
auto pos = findUserPos(user);
|
||||
auto pos = findUserPos(member);
|
||||
beginInsertRows(QModelIndex(), pos, pos);
|
||||
m_users.insert(pos, user);
|
||||
m_members.insert(pos, member);
|
||||
endInsertRows();
|
||||
connect(user, &User::defaultAvatarChanged, this, [this, user]() {
|
||||
refreshUser(user, {AvatarRole});
|
||||
});
|
||||
}
|
||||
|
||||
void UserListModel::userRemoved(Quotient::User *user)
|
||||
void UserListModel::memberLeft(const Quotient::RoomMember &member)
|
||||
{
|
||||
auto pos = findUserPos(user);
|
||||
if (pos != m_users.size()) {
|
||||
auto pos = findUserPos(member);
|
||||
if (pos != m_members.size()) {
|
||||
beginRemoveRows(QModelIndex(), pos, pos);
|
||||
m_users.removeAt(pos);
|
||||
m_members.removeAt(pos);
|
||||
endRemoveRows();
|
||||
user->disconnect(this);
|
||||
} else {
|
||||
qWarning() << "Trying to remove a room member not in the user list";
|
||||
}
|
||||
}
|
||||
|
||||
void UserListModel::refreshUser(Quotient::User *user, const QList<int> &roles)
|
||||
void UserListModel::refreshMember(const Quotient::RoomMember &member, const QList<int> &roles)
|
||||
{
|
||||
auto pos = findUserPos(user);
|
||||
if (pos != m_users.size()) {
|
||||
auto pos = findUserPos(member);
|
||||
if (pos != m_members.size()) {
|
||||
Q_EMIT dataChanged(index(pos), index(pos), roles);
|
||||
} else {
|
||||
qWarning() << "Trying to access a room member not in the user list";
|
||||
}
|
||||
}
|
||||
|
||||
void UserListModel::refreshAllUsers()
|
||||
void UserListModel::refreshAllMembers()
|
||||
{
|
||||
beginResetModel();
|
||||
for (User *user : std::as_const(m_users)) {
|
||||
user->disconnect(this);
|
||||
}
|
||||
m_users.clear();
|
||||
m_members.clear();
|
||||
|
||||
if (m_currentRoom != nullptr) {
|
||||
m_users = m_currentRoom->users();
|
||||
std::sort(m_users.begin(), m_users.end(), m_currentRoom->memberSorter());
|
||||
|
||||
for (User *user : std::as_const(m_users)) {
|
||||
connect(user, &User::defaultAvatarChanged, this, [this, user]() {
|
||||
refreshUser(user, {AvatarRole});
|
||||
});
|
||||
}
|
||||
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this]() {
|
||||
setRoom(nullptr);
|
||||
});
|
||||
m_members = m_currentRoom->members();
|
||||
std::sort(m_members.begin(), m_members.end(), m_currentRoom->memberSorter());
|
||||
}
|
||||
endResetModel();
|
||||
Q_EMIT usersRefreshed();
|
||||
}
|
||||
|
||||
int UserListModel::findUserPos(Quotient::User *user) const
|
||||
int UserListModel::findUserPos(const RoomMember &member) const
|
||||
{
|
||||
return findUserPos(m_currentRoom->safeMemberName(user->id()));
|
||||
return findUserPos(member.displayName());
|
||||
}
|
||||
|
||||
int UserListModel::findUserPos(const QString &username) const
|
||||
@@ -189,7 +173,7 @@ int UserListModel::findUserPos(const QString &username) const
|
||||
if (!m_currentRoom) {
|
||||
return 0;
|
||||
}
|
||||
return m_currentRoom->memberSorter().lowerBoundIndex(m_users, username);
|
||||
return m_currentRoom->memberSorter().lowerBoundIndex(m_members, username);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> UserListModel::roleNames() const
|
||||
|
||||
@@ -56,11 +56,6 @@ public:
|
||||
[[nodiscard]] NeoChatRoom *room() const;
|
||||
void setRoom(NeoChatRoom *room);
|
||||
|
||||
/**
|
||||
* @brief The user at the given index of the model.
|
||||
*/
|
||||
[[nodiscard]] Quotient::User *userAt(QModelIndex index) const;
|
||||
|
||||
/**
|
||||
* @brief Get the given role value at the given index.
|
||||
*
|
||||
@@ -90,15 +85,15 @@ protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void userAdded(Quotient::User *user);
|
||||
void userRemoved(Quotient::User *user);
|
||||
void refreshUser(Quotient::User *user, const QList<int> &roles = {});
|
||||
void refreshAllUsers();
|
||||
void memberJoined(const Quotient::RoomMember &member);
|
||||
void memberLeft(const Quotient::RoomMember &member);
|
||||
void refreshMember(const Quotient::RoomMember &member, const QList<int> &roles = {});
|
||||
void refreshAllMembers();
|
||||
|
||||
private:
|
||||
QPointer<NeoChatRoom> m_currentRoom;
|
||||
QList<Quotient::User *> m_users;
|
||||
QList<Quotient::RoomMember> m_members;
|
||||
|
||||
int findUserPos(Quotient::User *user) const;
|
||||
int findUserPos(const Quotient::RoomMember &member) const;
|
||||
[[nodiscard]] int findUserPos(const QString &username) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user