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
@@ -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"},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user