Compare commits
2 Commits
master
...
work/tobia
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ab8f796d8 | ||
|
|
2e0c074a9b |
@@ -50,7 +50,7 @@ void ChatBarCacheTest::empty()
|
|||||||
QCOMPARE(chatBarCache->replyId(), QString());
|
QCOMPARE(chatBarCache->replyId(), QString());
|
||||||
QCOMPARE(chatBarCache->isEditing(), false);
|
QCOMPARE(chatBarCache->isEditing(), false);
|
||||||
QCOMPARE(chatBarCache->editId(), QString());
|
QCOMPARE(chatBarCache->editId(), QString());
|
||||||
QCOMPARE(chatBarCache->relationUser(), room->getUser(nullptr));
|
QCOMPARE(chatBarCache->relationUser(), room->getUser(QString()));
|
||||||
QCOMPARE(chatBarCache->relationMessage(), QString());
|
QCOMPARE(chatBarCache->relationMessage(), QString());
|
||||||
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ void ChatBarCacheTest::reply()
|
|||||||
QCOMPARE(chatBarCache->replyId(), QLatin1String("$153456789:example.org"));
|
QCOMPARE(chatBarCache->replyId(), QLatin1String("$153456789:example.org"));
|
||||||
QCOMPARE(chatBarCache->isEditing(), false);
|
QCOMPARE(chatBarCache->isEditing(), false);
|
||||||
QCOMPARE(chatBarCache->editId(), QString());
|
QCOMPARE(chatBarCache->editId(), QString());
|
||||||
QCOMPARE(chatBarCache->relationUser(), room->getUser(room->user(QLatin1String("@example:example.org"))));
|
QCOMPARE(chatBarCache->relationUser(), room->getUser(QLatin1String("@example:example.org")));
|
||||||
QCOMPARE(chatBarCache->relationMessage(), QLatin1String("This is an example\ntext message"));
|
QCOMPARE(chatBarCache->relationMessage(), QLatin1String("This is an example\ntext message"));
|
||||||
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ void ChatBarCacheTest::edit()
|
|||||||
QCOMPARE(chatBarCache->replyId(), QString());
|
QCOMPARE(chatBarCache->replyId(), QString());
|
||||||
QCOMPARE(chatBarCache->isEditing(), true);
|
QCOMPARE(chatBarCache->isEditing(), true);
|
||||||
QCOMPARE(chatBarCache->editId(), QLatin1String("$153456789:example.org"));
|
QCOMPARE(chatBarCache->editId(), QLatin1String("$153456789:example.org"));
|
||||||
QCOMPARE(chatBarCache->relationUser(), room->getUser(room->user(QLatin1String("@example:example.org"))));
|
QCOMPARE(chatBarCache->relationUser(), room->getUser(QLatin1String("@example:example.org")));
|
||||||
QCOMPARE(chatBarCache->relationMessage(), QLatin1String("This is an example\ntext message"));
|
QCOMPARE(chatBarCache->relationMessage(), QLatin1String("This is an example\ntext message"));
|
||||||
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
QCOMPARE(chatBarCache->attachmentPath(), QString());
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ void ChatBarCacheTest::attachment()
|
|||||||
QCOMPARE(chatBarCache->replyId(), QString());
|
QCOMPARE(chatBarCache->replyId(), QString());
|
||||||
QCOMPARE(chatBarCache->isEditing(), false);
|
QCOMPARE(chatBarCache->isEditing(), false);
|
||||||
QCOMPARE(chatBarCache->editId(), QString());
|
QCOMPARE(chatBarCache->editId(), QString());
|
||||||
QCOMPARE(chatBarCache->relationUser(), room->getUser(nullptr));
|
QCOMPARE(chatBarCache->relationUser(), room->getUser(QString()));
|
||||||
QCOMPARE(chatBarCache->relationMessage(), QString());
|
QCOMPARE(chatBarCache->relationMessage(), QString());
|
||||||
QCOMPARE(chatBarCache->attachmentPath(), QLatin1String("some/path"));
|
QCOMPARE(chatBarCache->attachmentPath(), QLatin1String("some/path"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,17 +101,17 @@ void EventHandlerTest::nullEventId()
|
|||||||
void EventHandlerTest::author()
|
void EventHandlerTest::author()
|
||||||
{
|
{
|
||||||
auto event = room->messageEvents().at(0).get();
|
auto event = room->messageEvents().at(0).get();
|
||||||
auto author = room->user(event->senderId());
|
auto author = room->member(event->senderId());
|
||||||
EventHandler eventHandler(room, event);
|
EventHandler eventHandler(room, event);
|
||||||
|
|
||||||
auto eventHandlerAuthor = eventHandler.getAuthor();
|
auto eventHandlerAuthor = eventHandler.getAuthor();
|
||||||
|
|
||||||
QCOMPARE(eventHandlerAuthor["isLocalUser"_ls], author->id() == room->localUser()->id());
|
QCOMPARE(eventHandlerAuthor["isLocalUser"_ls], author.id() == room->localMember().id());
|
||||||
QCOMPARE(eventHandlerAuthor["id"_ls], author->id());
|
QCOMPARE(eventHandlerAuthor["id"_ls], author.id());
|
||||||
QCOMPARE(eventHandlerAuthor["displayName"_ls], author->displayname(room));
|
QCOMPARE(eventHandlerAuthor["displayName"_ls], author.displayName());
|
||||||
QCOMPARE(eventHandlerAuthor["avatarSource"_ls], room->avatarForMember(author));
|
QCOMPARE(eventHandlerAuthor["avatarSource"_ls], room->avatarForMember(author));
|
||||||
QCOMPARE(eventHandlerAuthor["avatarMediaId"_ls], author->avatarMediaId(room));
|
QCOMPARE(eventHandlerAuthor["avatarMediaId"_ls], author.avatarMediaId());
|
||||||
QCOMPARE(eventHandlerAuthor["color"_ls], Utils::getUserColor(author->hueF()));
|
QCOMPARE(eventHandlerAuthor["color"_ls], Utils::getUserColor(author.hueF()));
|
||||||
QCOMPARE(eventHandlerAuthor["object"_ls], QVariant::fromValue(author));
|
QCOMPARE(eventHandlerAuthor["object"_ls], QVariant::fromValue(author));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ void EventHandlerTest::nullAuthor()
|
|||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
EventHandler noEventHandler(room, nullptr);
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getAuthor called with m_event set to nullptr. Returning empty user.");
|
QTest::ignoreMessage(QtWarningMsg, "getAuthor called with m_event set to nullptr. Returning empty user.");
|
||||||
QCOMPARE(noEventHandler.getAuthor(), room->getUser(nullptr));
|
QCOMPARE(noEventHandler.getAuthor(), room->getUser(QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::authorDisplayName()
|
void EventHandlerTest::authorDisplayName()
|
||||||
@@ -393,21 +393,21 @@ void EventHandlerTest::nullReplyId()
|
|||||||
void EventHandlerTest::replyAuthor()
|
void EventHandlerTest::replyAuthor()
|
||||||
{
|
{
|
||||||
auto replyEvent = room->messageEvents().at(0).get();
|
auto replyEvent = room->messageEvents().at(0).get();
|
||||||
auto replyAuthor = room->user(replyEvent->senderId());
|
auto replyAuthor = room->member(replyEvent->senderId());
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(5).get());
|
EventHandler eventHandler(room, room->messageEvents().at(5).get());
|
||||||
|
|
||||||
auto eventHandlerReplyAuthor = eventHandler.getReplyAuthor();
|
auto eventHandlerReplyAuthor = eventHandler.getReplyAuthor();
|
||||||
|
|
||||||
QCOMPARE(eventHandlerReplyAuthor["isLocalUser"_ls], replyAuthor->id() == room->localUser()->id());
|
QCOMPARE(eventHandlerReplyAuthor["isLocalUser"_ls], replyAuthor.id() == room->localMember().id());
|
||||||
QCOMPARE(eventHandlerReplyAuthor["id"_ls], replyAuthor->id());
|
QCOMPARE(eventHandlerReplyAuthor["id"_ls], replyAuthor.id());
|
||||||
QCOMPARE(eventHandlerReplyAuthor["displayName"_ls], replyAuthor->displayname(room));
|
QCOMPARE(eventHandlerReplyAuthor["displayName"_ls], replyAuthor.displayName());
|
||||||
QCOMPARE(eventHandlerReplyAuthor["avatarSource"_ls], room->avatarForMember(replyAuthor));
|
QCOMPARE(eventHandlerReplyAuthor["avatarSource"_ls], room->avatarForMember(replyAuthor));
|
||||||
QCOMPARE(eventHandlerReplyAuthor["avatarMediaId"_ls], replyAuthor->avatarMediaId(room));
|
QCOMPARE(eventHandlerReplyAuthor["avatarMediaId"_ls], replyAuthor.avatarMediaId());
|
||||||
QCOMPARE(eventHandlerReplyAuthor["color"_ls], Utils::getUserColor(replyAuthor->hueF()));
|
QCOMPARE(eventHandlerReplyAuthor["color"_ls], Utils::getUserColor(replyAuthor.hueF()));
|
||||||
QCOMPARE(eventHandlerReplyAuthor["object"_ls], QVariant::fromValue(replyAuthor));
|
QCOMPARE(eventHandlerReplyAuthor["object"_ls], QVariant::fromValue(replyAuthor));
|
||||||
|
|
||||||
EventHandler eventHandlerNoAuthor(room, room->messageEvents().at(0).get());
|
EventHandler eventHandlerNoAuthor(room, room->messageEvents().at(0).get());
|
||||||
QCOMPARE(eventHandlerNoAuthor.getReplyAuthor(), room->getUser(nullptr));
|
QCOMPARE(eventHandlerNoAuthor.getReplyAuthor(), room->getUser(QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyAuthor()
|
void EventHandlerTest::nullReplyAuthor()
|
||||||
@@ -417,7 +417,7 @@ void EventHandlerTest::nullReplyAuthor()
|
|||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
EventHandler noEventHandler(room, nullptr);
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyAuthor called with m_event set to nullptr. Returning empty user.");
|
QTest::ignoreMessage(QtWarningMsg, "getReplyAuthor called with m_event set to nullptr. Returning empty user.");
|
||||||
QCOMPARE(noEventHandler.getReplyAuthor(), room->getUser(nullptr));
|
QCOMPARE(noEventHandler.getReplyAuthor(), room->getUser(QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::replyBody()
|
void EventHandlerTest::replyBody()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void ReactionModelTest::basicReaction()
|
|||||||
QCOMPARE(model.data(model.index(0), ReactionModel::ReactionRole), QStringLiteral("👍"));
|
QCOMPARE(model.data(model.index(0), ReactionModel::ReactionRole), QStringLiteral("👍"));
|
||||||
QCOMPARE(model.data(model.index(0), ReactionModel::ToolTipRole),
|
QCOMPARE(model.data(model.index(0), ReactionModel::ToolTipRole),
|
||||||
QStringLiteral("@alice:matrix.org reacted with <span style=\"font-family: 'emoji';\">👍</span>"));
|
QStringLiteral("@alice:matrix.org reacted with <span style=\"font-family: 'emoji';\">👍</span>"));
|
||||||
auto authorList = QVariantList{room->getUser(room->user(QStringLiteral("@alice:matrix.org")))};
|
auto authorList = QVariantList{room->getUser(QStringLiteral("@alice:matrix.org"))};
|
||||||
QCOMPARE(model.data(model.index(0), ReactionModel::AuthorsRole), authorList);
|
QCOMPARE(model.data(model.index(0), ReactionModel::AuthorsRole), authorList);
|
||||||
QCOMPARE(model.data(model.index(0), ReactionModel::HasLocalUser), false);
|
QCOMPARE(model.data(model.index(0), ReactionModel::HasLocalUser), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void ActionsHandler::handleMessage(const QString &text, QString handledText, Cha
|
|||||||
|
|
||||||
for (auto it = m_room->messageEvents().crbegin(); it != m_room->messageEvents().crend(); it++) {
|
for (auto it = m_room->messageEvents().crbegin(); it != m_room->messageEvents().crend(); it++) {
|
||||||
if (const auto event = eventCast<const RoomMessageEvent>(&**it)) {
|
if (const auto event = eventCast<const RoomMessageEvent>(&**it)) {
|
||||||
if (event->senderId() == m_room->localUser()->id() && event->hasTextContent()) {
|
if (event->senderId() == m_room->localMember().id() && event->hasTextContent()) {
|
||||||
QString originalString;
|
QString originalString;
|
||||||
if (event->content()) {
|
if (event->content()) {
|
||||||
originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content())->body;
|
originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content())->body;
|
||||||
|
|||||||
@@ -96,9 +96,9 @@ QVariantMap ChatBarCache::relationUser() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_relationId.isEmpty()) {
|
if (m_relationId.isEmpty()) {
|
||||||
return room->getUser(nullptr);
|
return room->getUser(QString());
|
||||||
}
|
}
|
||||||
return room->getUser(room->user((*room->findInTimeline(m_relationId))->senderId()));
|
return room->getUser((*room->findInTimeline(m_relationId))->senderId());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatBarCache::relationMessage() const
|
QString ChatBarCache::relationMessage() const
|
||||||
|
|||||||
11
src/definitions.h
Normal file
11
src/definitions.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
|
||||||
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
|
|
||||||
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
#define Omittable std::optional
|
||||||
|
#define quotientNone std::nullopt
|
||||||
|
#else
|
||||||
|
#include <Quotient/omittable.h>
|
||||||
|
#define Omittable Quotient::Omittable
|
||||||
|
#define quotientNone Quotient::none
|
||||||
|
#endif
|
||||||
@@ -70,10 +70,10 @@ QVariantMap EventHandler::getAuthor(bool isPending) const
|
|||||||
// If we have a room we can return an empty user by handing nullptr to m_room->getUser.
|
// If we have a room we can return an empty user by handing nullptr to m_room->getUser.
|
||||||
if (m_event == nullptr) {
|
if (m_event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getAuthor called with m_event set to nullptr. Returning empty user.";
|
qCWarning(EventHandling) << "getAuthor called with m_event set to nullptr. Returning empty user.";
|
||||||
return m_room->getUser(nullptr);
|
return m_room->getUser(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId());
|
const auto author = isPending ? m_room->localMember() : m_room->member(m_event->senderId());
|
||||||
return m_room->getUser(author);
|
return m_room->getUser(author);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ QString EventHandler::getAuthorDisplayName(bool isPending) const
|
|||||||
}
|
}
|
||||||
return previousDisplayName;
|
return previousDisplayName;
|
||||||
} else {
|
} else {
|
||||||
const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId());
|
const auto author = isPending ? m_room->localMember() : m_room->member(m_event->senderId());
|
||||||
return m_room->htmlSafeMemberName(author->id());
|
return author.htmlSafeDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +112,8 @@ QString EventHandler::singleLineAuthorDisplayname(bool isPending) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId());
|
const auto author = isPending ? m_room->localMember() : m_room->member(m_event->senderId());
|
||||||
auto displayName = m_room->safeMemberName(author->id());
|
auto displayName = author.displayName();
|
||||||
displayName.replace(QStringLiteral("<br>\n"), QStringLiteral(" "));
|
displayName.replace(QStringLiteral("<br>\n"), QStringLiteral(" "));
|
||||||
displayName.replace(QStringLiteral("<br>"), QStringLiteral(" "));
|
displayName.replace(QStringLiteral("<br>"), QStringLiteral(" "));
|
||||||
displayName.replace(QStringLiteral("<br />\n"), QStringLiteral(" "));
|
displayName.replace(QStringLiteral("<br />\n"), QStringLiteral(" "));
|
||||||
@@ -220,7 +220,7 @@ bool EventHandler::isHidden()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_room->connection()->isIgnored(m_room->user(m_event->senderId()))) {
|
if (m_room->connection()->isIgnored(m_event->senderId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
|||||||
|
|
||||||
QString body;
|
QString body;
|
||||||
if (event.hasTextContent() && event.content()) {
|
if (event.hasTextContent() && event.content()) {
|
||||||
body = static_cast<const MessageEventContent::TextContent *>(event.content())->body;
|
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
||||||
} else {
|
} else {
|
||||||
body = event.plainBody();
|
body = event.plainBody();
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat f
|
|||||||
},
|
},
|
||||||
[this, prettyPrint](const RoomMemberEvent &e) {
|
[this, prettyPrint](const RoomMemberEvent &e) {
|
||||||
// FIXME: Rewind to the name that was at the time of this event
|
// FIXME: Rewind to the name that was at the time of this event
|
||||||
auto subjectName = m_room->htmlSafeMemberName(e.userId());
|
auto subjectName = m_room->member(e.userId()).htmlSafeDisplayName();
|
||||||
if (e.membership() == Membership::Leave) {
|
if (e.membership() == Membership::Leave) {
|
||||||
if (e.prevContent() && e.prevContent()->displayName) {
|
if (e.prevContent() && e.prevContent()->displayName) {
|
||||||
subjectName = sanitized(*e.prevContent()->displayName).toHtmlEscaped();
|
subjectName = sanitized(*e.prevContent()->displayName).toHtmlEscaped();
|
||||||
@@ -479,7 +479,7 @@ QString EventHandler::getMessageBody(const RoomMessageEvent &event, Qt::TextForm
|
|||||||
|
|
||||||
QString body;
|
QString body;
|
||||||
if (event.hasTextContent() && event.content()) {
|
if (event.hasTextContent() && event.content()) {
|
||||||
body = static_cast<const MessageEventContent::TextContent *>(event.content())->body;
|
body = static_cast<const EventContent::TextContent *>(event.content())->body;
|
||||||
} else {
|
} else {
|
||||||
body = event.plainBody();
|
body = event.plainBody();
|
||||||
}
|
}
|
||||||
@@ -809,16 +809,15 @@ QVariantMap EventHandler::getReplyAuthor() const
|
|||||||
// If we have a room we can return an empty user by handing nullptr to m_room->getUser.
|
// If we have a room we can return an empty user by handing nullptr to m_room->getUser.
|
||||||
if (m_event == nullptr) {
|
if (m_event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getReplyAuthor called with m_event set to nullptr. Returning empty user.";
|
qCWarning(EventHandling) << "getReplyAuthor called with m_event set to nullptr. Returning empty user.";
|
||||||
return m_room->getUser(nullptr);
|
return m_room->getUser(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto replyPtr = m_room->getReplyForEvent(*m_event);
|
auto replyPtr = m_room->getReplyForEvent(*m_event);
|
||||||
|
|
||||||
if (replyPtr) {
|
if (replyPtr) {
|
||||||
auto replyUser = m_room->user(replyPtr->senderId());
|
return m_room->getUser(replyPtr->senderId());
|
||||||
return m_room->getUser(replyUser);
|
|
||||||
} else {
|
} else {
|
||||||
return m_room->getUser(nullptr);
|
return m_room->getUser(QString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -966,7 +965,7 @@ bool EventHandler::hasReadMarkers() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
||||||
userIds.remove(m_room->localUser()->id());
|
userIds.remove(m_room->localMember().id());
|
||||||
return userIds.size() > 0;
|
return userIds.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -982,7 +981,7 @@ QVariantList EventHandler::getReadMarkers(int maxMarkers) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto userIds_temp = m_room->userIdsAtEvent(m_event->id());
|
auto userIds_temp = m_room->userIdsAtEvent(m_event->id());
|
||||||
userIds_temp.remove(m_room->localUser()->id());
|
userIds_temp.remove(m_room->localMember().id());
|
||||||
|
|
||||||
auto userIds = userIds_temp.values();
|
auto userIds = userIds_temp.values();
|
||||||
if (userIds.count() > maxMarkers) {
|
if (userIds.count() > maxMarkers) {
|
||||||
@@ -992,7 +991,7 @@ QVariantList EventHandler::getReadMarkers(int maxMarkers) const
|
|||||||
QVariantList users;
|
QVariantList users;
|
||||||
users.reserve(userIds.size());
|
users.reserve(userIds.size());
|
||||||
for (const auto &userId : userIds) {
|
for (const auto &userId : userIds) {
|
||||||
auto user = m_room->user(userId);
|
auto user = m_room->member(userId);
|
||||||
users += m_room->getUser(user);
|
users += m_room->getUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1011,7 +1010,7 @@ QString EventHandler::getNumberExcessReadMarkers(int maxMarkers) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
||||||
userIds.remove(m_room->localUser()->id());
|
userIds.remove(m_room->localMember().id());
|
||||||
|
|
||||||
if (userIds.count() > maxMarkers) {
|
if (userIds.count() > maxMarkers) {
|
||||||
return QStringLiteral("+ ") + QString::number(userIds.count() - maxMarkers);
|
return QStringLiteral("+ ") + QString::number(userIds.count() - maxMarkers);
|
||||||
@@ -1032,7 +1031,7 @@ QString EventHandler::getReadMarkersString() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
auto userIds = m_room->userIdsAtEvent(m_event->id());
|
||||||
userIds.remove(m_room->localUser()->id());
|
userIds.remove(m_room->localMember().id());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The string ends up in the form
|
* The string ends up in the form
|
||||||
@@ -1040,8 +1039,8 @@ QString EventHandler::getReadMarkersString() const
|
|||||||
*/
|
*/
|
||||||
QString readMarkersString = i18np("1 user: ", "%1 users: ", userIds.size());
|
QString readMarkersString = i18np("1 user: ", "%1 users: ", userIds.size());
|
||||||
for (const auto &userId : userIds) {
|
for (const auto &userId : userIds) {
|
||||||
auto user = m_room->user(userId);
|
auto user = m_room->member(userId);
|
||||||
auto displayName = user->displayname(m_room);
|
auto displayName = user.displayName();
|
||||||
if (displayName.isEmpty()) {
|
if (displayName.isEmpty()) {
|
||||||
displayName = userId;
|
displayName = userId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json)
|
|||||||
fromJson<Omittable<QString>>(json["pack"_ls].toObject()["attribution"_ls]),
|
fromJson<Omittable<QString>>(json["pack"_ls].toObject()["attribution"_ls]),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
pack = none;
|
pack = quotientNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &keys = json["images"_ls].toObject().keys();
|
const auto &keys = json["images"_ls].toObject().keys();
|
||||||
@@ -25,7 +25,7 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json)
|
|||||||
if (json["images"_ls][k].toObject().contains(QStringLiteral("info"))) {
|
if (json["images"_ls][k].toObject().contains(QStringLiteral("info"))) {
|
||||||
info = EventContent::ImageInfo(QUrl(json["images"_ls][k]["url"_ls].toString()), json["images"_ls][k]["info"_ls].toObject(), k);
|
info = EventContent::ImageInfo(QUrl(json["images"_ls][k]["url"_ls].toString()), json["images"_ls][k]["info"_ls].toObject(), k);
|
||||||
} else {
|
} else {
|
||||||
info = none;
|
info = quotientNone;
|
||||||
}
|
}
|
||||||
images += ImagePackImage{
|
images += ImagePackImage{
|
||||||
k,
|
k,
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <Quotient/events/eventcontent.h>
|
#include <Quotient/events/eventcontent.h>
|
||||||
#include <Quotient/events/stateevent.h>
|
#include <Quotient/events/stateevent.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -26,10 +28,10 @@ public:
|
|||||||
* @brief Defines the properties of an image pack.
|
* @brief Defines the properties of an image pack.
|
||||||
*/
|
*/
|
||||||
struct Pack {
|
struct Pack {
|
||||||
Quotient::Omittable<QString> displayName; /**< The display name of the pack. */
|
Omittable<QString> displayName; /**< The display name of the pack. */
|
||||||
Quotient::Omittable<QUrl> avatarUrl; /**< The source mxc URL for the pack avatar. */
|
Omittable<QUrl> avatarUrl; /**< The source mxc URL for the pack avatar. */
|
||||||
Quotient::Omittable<QStringList> usage; /**< An array of the usages for this pack. Possible usages are "emoticon" and "sticker". */
|
Omittable<QStringList> usage; /**< An array of the usages for this pack. Possible usages are "emoticon" and "sticker". */
|
||||||
Quotient::Omittable<QString> attribution; /**< The attribution for the pack author(s). */
|
Omittable<QString> attribution; /**< The attribution for the pack author(s). */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,14 +40,14 @@ public:
|
|||||||
struct ImagePackImage {
|
struct ImagePackImage {
|
||||||
QString shortcode; /**< The shortcode for the image. */
|
QString shortcode; /**< The shortcode for the image. */
|
||||||
QUrl url; /**< The mxc URL for this image. */
|
QUrl url; /**< The mxc URL for this image. */
|
||||||
Quotient::Omittable<QString> body; /**< An optional text body for this image. */
|
Omittable<QString> body; /**< An optional text body for this image. */
|
||||||
Quotient::Omittable<Quotient::EventContent::ImageInfo> info; /**< The ImageInfo object used for the info block of m.sticker events. */
|
Omittable<Quotient::EventContent::ImageInfo> info; /**< The ImageInfo object used for the info block of m.sticker events. */
|
||||||
/**
|
/**
|
||||||
* @brief An array of the usages for this image.
|
* @brief An array of the usages for this image.
|
||||||
*
|
*
|
||||||
* The possible values match those of the usage key of a pack object.
|
* The possible values match those of the usage key of a pack object.
|
||||||
*/
|
*/
|
||||||
Quotient::Omittable<QStringList> usage;
|
Omittable<QStringList> usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +55,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @sa Pack
|
* @sa Pack
|
||||||
*/
|
*/
|
||||||
Quotient::Omittable<Pack> pack;
|
Omittable<Pack> pack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a vector of images in the pack.
|
* @brief Return a vector of images in the pack.
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/omittable.h>
|
#include <Quotient/omittable.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
class NeochatAdd3PIdJob : public Quotient::BaseJob
|
class NeochatAdd3PIdJob : public Quotient::BaseJob
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NeochatAdd3PIdJob(const QString &clientSecret, const QString &sid, const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
explicit NeochatAdd3PIdJob(const QString &clientSecret, const QString &sid, const Omittable<QJsonObject> &auth = {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/omittable.h>
|
#include <Quotient/omittable.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
class NeochatChangePasswordJob : public Quotient::BaseJob
|
class NeochatChangePasswordJob : public Quotient::BaseJob
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
explicit NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Omittable<QJsonObject> &auth = {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/omittable.h>
|
#include <Quotient/omittable.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
class NeoChatDeactivateAccountJob : public Quotient::BaseJob
|
class NeoChatDeactivateAccountJob : public Quotient::BaseJob
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NeoChatDeactivateAccountJob(const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
explicit NeoChatDeactivateAccountJob(const Omittable<QJsonObject> &auth = {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/omittable.h>
|
#include <Quotient/omittable.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
class NeochatDeleteDeviceJob : public Quotient::BaseJob
|
class NeochatDeleteDeviceJob : public Quotient::BaseJob
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NeochatDeleteDeviceJob(const QString &deviceId, const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
explicit NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth = {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -202,11 +202,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));
|
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is banned from this room.", "%1 is banned from this room.", text));
|
||||||
return QString();
|
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."));
|
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18n("You are already in this room."));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if (room->users().contains(room->user(text))) {
|
if (room->memberIds().contains(text)) {
|
||||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is already in this room.", "%1 is already in this room.", text));
|
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is already in this room.", "%1 is already in this room.", text));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is already ignored.", "%1 is already ignored.", text));
|
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is already ignored.", "%1 is already ignored.", text));
|
||||||
return QString();
|
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));
|
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18nc("<username> is now ignored", "%1 is now ignored.", text));
|
||||||
return QString();
|
return QString();
|
||||||
},
|
},
|
||||||
@@ -382,7 +382,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is not ignored.", "%1 is not ignored.", text));
|
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<username> is not ignored.", "%1 is not ignored.", text));
|
||||||
return QString();
|
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));
|
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18nc("<username> is no longer ignored.", "%1 is no longer ignored.", text));
|
||||||
return QString();
|
return QString();
|
||||||
},
|
},
|
||||||
@@ -431,11 +431,11 @@ QList<ActionsModel::Action> actions{
|
|||||||
if (!plEvent) {
|
if (!plEvent) {
|
||||||
return QString();
|
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."));
|
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to ban users from this room."));
|
||||||
return QString();
|
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(
|
Q_EMIT room->showMessage(
|
||||||
NeoChatRoom::Error,
|
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]));
|
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 +464,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
if (!plEvent) {
|
if (!plEvent) {
|
||||||
return QString();
|
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."));
|
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to unban users from this room."));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -495,7 +495,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
i18nc("'<text>' does not look like a matrix id.", "'%1' does not look like a matrix id.", parts[0]));
|
i18nc("'<text>' does not look like a matrix id.", "'%1' does not look like a matrix id.", parts[0]));
|
||||||
return QString();
|
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."));
|
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You cannot kick yourself from the room."));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -508,11 +508,11 @@ QList<ActionsModel::Action> actions{
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
auto kick = plEvent->kick();
|
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."));
|
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to kick users from this room."));
|
||||||
return QString();
|
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(
|
Q_EMIT room->showMessage(
|
||||||
NeoChatRoom::Error,
|
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]));
|
i18nc("You are not allowed to kick <username> from this room", "You are not allowed to kick %1 from this room.", parts[0]));
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void LocationsModel::addLocation(const RoomMessageEvent *event)
|
|||||||
.latitude = latitude,
|
.latitude = latitude,
|
||||||
.longitude = longitude,
|
.longitude = longitude,
|
||||||
.content = event->contentJson(),
|
.content = event->contentJson(),
|
||||||
.author = m_room->user(event->senderId()),
|
.author = event->senderId(),
|
||||||
};
|
};
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ private:
|
|||||||
float latitude;
|
float latitude;
|
||||||
float longitude;
|
float longitude;
|
||||||
QJsonObject content;
|
QJsonObject content;
|
||||||
Quotient::User *author;
|
QString author;
|
||||||
};
|
};
|
||||||
QList<LocationData> m_locations;
|
QList<LocationData> m_locations;
|
||||||
void addLocation(const Quotient::RoomMessageEvent *event);
|
void addLocation(const Quotient::RoomMessageEvent *event);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
|
|||||||
beginResetModel();
|
beginResetModel();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
});
|
});
|
||||||
qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localUser()->id();
|
qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localMember().id();
|
||||||
} else {
|
} else {
|
||||||
lastReadEventId.clear();
|
lastReadEventId.clear();
|
||||||
}
|
}
|
||||||
@@ -592,7 +592,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == IsEditableRole) {
|
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 {};
|
return {};
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ void NotificationsModel::loadData()
|
|||||||
if (!room) {
|
if (!room) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto u = room->memberAvatarUrl(authorId);
|
auto u = room->member(authorId).avatarUrl();
|
||||||
auto avatar = u.isEmpty() ? QUrl() : connection()->makeMediaUrl(u);
|
auto avatar = u.isEmpty() ? QUrl() : connection()->makeMediaUrl(u);
|
||||||
const auto &authorAvatar = avatar.isValid() && avatar.scheme() == QStringLiteral("mxc") ? avatar : QUrl();
|
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());
|
beginInsertRows({}, m_notifications.length(), m_notifications.length());
|
||||||
m_notifications += Notification{
|
m_notifications += Notification{
|
||||||
.roomId = notification.roomId,
|
.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),
|
+ eventHandler.getPlainBody(true),
|
||||||
.authorName = room->htmlSafeMemberName(authorId),
|
.authorName = room->member(authorId).htmlSafeDisplayName(),
|
||||||
.authorAvatar = authorAvatar,
|
.authorAvatar = authorAvatar,
|
||||||
.eventId = roomEvent->id(),
|
.eventId = roomEvent->id(),
|
||||||
.roomDisplayName = room->displayName(),
|
.roomDisplayName = room->displayName(),
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ QVariant ReactionModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
if (role == HasLocalUser) {
|
if (role == HasLocalUser) {
|
||||||
for (auto author : reaction.authors) {
|
for (auto author : reaction.authors) {
|
||||||
if (author.toMap()[QStringLiteral("id")] == m_room->localUser()->id()) {
|
if (author.toMap()[QStringLiteral("id")] == m_room->localMember().id()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,13 +121,13 @@ void ReactionModel::updateReactions()
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<QString, QList<Quotient::User *>> reactions = {};
|
QMap<QString, QList<Quotient::RoomMember>> reactions = {};
|
||||||
for (const auto &a : annotations) {
|
for (const auto &a : annotations) {
|
||||||
if (a->isRedacted()) { // Just in case?
|
if (a->isRedacted()) { // Just in case?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (const auto &e = eventCast<const Quotient::ReactionEvent>(a)) {
|
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()) {
|
if (e->contentJson()[QStringLiteral("shortcode")].toString().length()) {
|
||||||
m_shortcodes[e->key()] = e->contentJson()[QStringLiteral("shortcode")].toString().toHtmlEscaped();
|
m_shortcodes[e->key()] = e->contentJson()[QStringLiteral("shortcode")].toString().toHtmlEscaped();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void SearchModel::search()
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoomEventFilter filter;
|
RoomEventFilter filter;
|
||||||
filter.unreadThreadNotifications = none;
|
filter.unreadThreadNotifications = {};
|
||||||
filter.lazyLoadMembers = true;
|
filter.lazyLoadMembers = true;
|
||||||
filter.includeRedundantMembers = false;
|
filter.includeRedundantMembers = false;
|
||||||
filter.notRooms = QStringList();
|
filter.notRooms = QStringList();
|
||||||
@@ -58,7 +58,7 @@ void SearchModel::search()
|
|||||||
.orderBy = "recent"_ls,
|
.orderBy = "recent"_ls,
|
||||||
.eventContext = SearchJob::IncludeEventContext{3, 3, true},
|
.eventContext = SearchJob::IncludeEventContext{3, 3, true},
|
||||||
.includeState = false,
|
.includeState = false,
|
||||||
.groupings = none,
|
.groupings = {},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/room.h>
|
#include <Quotient/room.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ void SpaceChildrenModel::refreshModel()
|
|||||||
m_rootItem =
|
m_rootItem =
|
||||||
new SpaceTreeItem(dynamic_cast<NeoChatConnection *>(m_space->connection()), nullptr, m_space->id(), m_space->displayName(), m_space->canonicalAlias());
|
new SpaceTreeItem(dynamic_cast<NeoChatConnection *>(m_space->connection()), nullptr, m_space->id(), m_space->displayName(), m_space->canonicalAlias());
|
||||||
endResetModel();
|
endResetModel();
|
||||||
auto job = m_space->connection()->callApi<Quotient::GetSpaceHierarchyJob>(m_space->id(), Quotient::none, Quotient::none, 1);
|
auto job = m_space->connection()->callApi<Quotient::GetSpaceHierarchyJob>(m_space->id(), quotientNone, quotientNone, 1);
|
||||||
m_currentJobs.append(job);
|
m_currentJobs.append(job);
|
||||||
connect(job, &Quotient::BaseJob::success, this, [this, job]() {
|
connect(job, &Quotient::BaseJob::success, this, [this, job]() {
|
||||||
insertChildren(job->rooms());
|
insertChildren(job->rooms());
|
||||||
@@ -136,7 +137,7 @@ void SpaceChildrenModel::insertChildren(std::vector<Quotient::GetSpaceHierarchyJ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (children[i].childrenState.size() > 0) {
|
if (children[i].childrenState.size() > 0) {
|
||||||
auto job = m_space->connection()->callApi<Quotient::GetSpaceHierarchyJob>(children[i].roomId, Quotient::none, Quotient::none, 1);
|
auto job = m_space->connection()->callApi<Quotient::GetSpaceHierarchyJob>(children[i].roomId, quotientNone, quotientNone, 1);
|
||||||
m_currentJobs.append(job);
|
m_currentJobs.append(job);
|
||||||
connect(job, &Quotient::BaseJob::success, this, [this, parent, insertRow, job]() {
|
connect(job, &Quotient::BaseJob::success, this, [this, parent, insertRow, job]() {
|
||||||
insertChildren(job->rooms(), index(insertRow, 0, parent));
|
insertChildren(job->rooms(), index(insertRow, 0, parent));
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
|
#include <Quotient/avatar.h>
|
||||||
#include <Quotient/events/roompowerlevelsevent.h>
|
#include <Quotient/events/roompowerlevelsevent.h>
|
||||||
|
#include <Quotient/room.h>
|
||||||
|
|
||||||
#include "enums/powerlevel.h"
|
#include "enums/powerlevel.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
@@ -26,18 +28,26 @@ void UserListModel::setRoom(NeoChatRoom *room)
|
|||||||
|
|
||||||
if (m_currentRoom) {
|
if (m_currentRoom) {
|
||||||
m_currentRoom->disconnect(this);
|
m_currentRoom->disconnect(this);
|
||||||
|
m_currentRoom->connection()->disconnect(this);
|
||||||
}
|
}
|
||||||
m_currentRoom = room;
|
m_currentRoom = room;
|
||||||
|
|
||||||
if (m_currentRoom) {
|
if (m_currentRoom) {
|
||||||
connect(m_currentRoom, &Room::userAdded, this, &UserListModel::userAdded);
|
connect(m_currentRoom, &Room::memberJoined, this, &UserListModel::memberJoined);
|
||||||
connect(m_currentRoom, &Room::userRemoved, this, &UserListModel::userRemoved);
|
connect(m_currentRoom, &Room::memberLeft, this, &UserListModel::memberLeft);
|
||||||
connect(m_currentRoom, &Room::memberAboutToRename, this, &UserListModel::userRemoved);
|
connect(m_currentRoom, &Room::memberNameUpdated, this, [this](RoomMember member) {
|
||||||
connect(m_currentRoom, &Room::memberRenamed, this, &UserListModel::userAdded);
|
refreshMember(member, {DisplayNameRole});
|
||||||
connect(m_currentRoom, &Room::changed, this, &UserListModel::refreshAllUsers);
|
});
|
||||||
|
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();
|
Q_EMIT roomChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,44 +56,36 @@ NeoChatRoom *UserListModel::room() const
|
|||||||
return m_currentRoom;
|
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
|
QVariant UserListModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index.row() >= m_users.count()) {
|
if (index.row() >= m_members.count()) {
|
||||||
qDebug() << "UserListModel, something's wrong: index.row() >= "
|
qDebug() << "UserListModel, something's wrong: index.row() >= "
|
||||||
"users.count()";
|
"users.count()";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
auto user = m_users.at(index.row());
|
auto member = m_members.at(index.row());
|
||||||
if (role == DisplayNameRole) {
|
if (role == DisplayNameRole) {
|
||||||
return user->displayname(m_currentRoom);
|
return m_currentRoom->member(member).disambiguatedName();
|
||||||
}
|
}
|
||||||
if (role == UserIdRole) {
|
if (role == UserIdRole) {
|
||||||
return user->id();
|
return member;
|
||||||
}
|
}
|
||||||
if (role == AvatarRole) {
|
if (role == AvatarRole) {
|
||||||
return m_currentRoom->avatarForMember(user);
|
return m_currentRoom->memberAvatar(member).url();
|
||||||
}
|
}
|
||||||
if (role == ObjectRole) {
|
if (role == ObjectRole) {
|
||||||
return QVariant::fromValue(user);
|
return QVariant::fromValue(member);
|
||||||
}
|
}
|
||||||
if (role == PowerLevelRole) {
|
if (role == PowerLevelRole) {
|
||||||
auto plEvent = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
auto plEvent = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
||||||
if (!plEvent) {
|
if (!plEvent) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return plEvent->powerLevelForUser(user->id());
|
return plEvent->powerLevelForUser(member);
|
||||||
}
|
}
|
||||||
if (role == PowerLevelStringRole) {
|
if (role == PowerLevelStringRole) {
|
||||||
auto pl = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
auto pl = m_currentRoom->currentState().get<RoomPowerLevelsEvent>();
|
||||||
@@ -93,7 +95,7 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
|
|||||||
return QStringLiteral("Not Available");
|
return QStringLiteral("Not Available");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto userPl = pl->powerLevelForUser(user->id());
|
auto userPl = pl->powerLevelForUser(member);
|
||||||
|
|
||||||
return i18nc("%1 is the name of the power level, e.g. admin and %2 is the value that represents.",
|
return i18nc("%1 is the name of the power level, e.g. admin and %2 is the value that represents.",
|
||||||
"%1 (%2)",
|
"%1 (%2)",
|
||||||
@@ -109,87 +111,77 @@ int UserListModel::rowCount(const QModelIndex &parent) const
|
|||||||
if (parent.isValid()) {
|
if (parent.isValid()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m_users.count();
|
return m_members.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UserListModel::event(QEvent *event)
|
bool UserListModel::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::ApplicationPaletteChange) {
|
if (event->type() == QEvent::ApplicationPaletteChange) {
|
||||||
refreshAllUsers();
|
refreshAllMembers();
|
||||||
}
|
}
|
||||||
return QObject::event(event);
|
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);
|
beginInsertRows(QModelIndex(), pos, pos);
|
||||||
m_users.insert(pos, user);
|
m_members.insert(pos, member.id());
|
||||||
endInsertRows();
|
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);
|
auto pos = findUserPos(member);
|
||||||
if (pos != m_users.size()) {
|
if (pos != m_members.size()) {
|
||||||
beginRemoveRows(QModelIndex(), pos, pos);
|
beginRemoveRows(QModelIndex(), pos, pos);
|
||||||
m_users.removeAt(pos);
|
m_members.removeAt(pos);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
user->disconnect(this);
|
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Trying to remove a room member not in the user list";
|
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);
|
auto pos = findUserPos(member);
|
||||||
if (pos != m_users.size()) {
|
if (pos != m_members.size()) {
|
||||||
Q_EMIT dataChanged(index(pos), index(pos), roles);
|
Q_EMIT dataChanged(index(pos), index(pos), roles);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Trying to access a room member not in the user list";
|
qWarning() << "Trying to access a room member not in the user list";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserListModel::refreshAllUsers()
|
void UserListModel::refreshAllMembers()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
for (User *user : std::as_const(m_users)) {
|
m_members.clear();
|
||||||
user->disconnect(this);
|
|
||||||
}
|
|
||||||
m_users.clear();
|
|
||||||
|
|
||||||
if (m_currentRoom != nullptr) {
|
if (m_currentRoom != nullptr) {
|
||||||
m_users = m_currentRoom->users();
|
m_members = m_currentRoom->joinedMemberIds();
|
||||||
std::sort(m_users.begin(), m_users.end(), m_currentRoom->memberSorter());
|
std::sort(m_members.begin(), m_members.end(), [this](const auto &left, const auto &right) {
|
||||||
|
return m_currentRoom->member(left).displayName() < m_currentRoom->member(right).displayName();
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
Q_EMIT usersRefreshed();
|
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.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
int UserListModel::findUserPos(const QString &username) const
|
int UserListModel::findUserPos(const QString &userId) const
|
||||||
{
|
{
|
||||||
if (!m_currentRoom) {
|
if (!m_currentRoom) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m_currentRoom->memberSorter().lowerBoundIndex(m_users, username);
|
#if Quotient_VERSION_MINOR > 8
|
||||||
|
return Quotient::lowerBoundMemberIndex(m_members, m_currentRoom->member(userId).displayName(), m_currentRoom);
|
||||||
|
#else
|
||||||
|
return m_currentRoom->memberSorter().lowerBoundIndex(m_currentRoom->members(), m_currentRoom->member(userId));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> UserListModel::roleNames() const
|
QHash<int, QByteArray> UserListModel::roleNames() const
|
||||||
|
|||||||
@@ -56,11 +56,6 @@ public:
|
|||||||
[[nodiscard]] NeoChatRoom *room() const;
|
[[nodiscard]] NeoChatRoom *room() const;
|
||||||
void setRoom(NeoChatRoom *room);
|
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.
|
* @brief Get the given role value at the given index.
|
||||||
*
|
*
|
||||||
@@ -90,15 +85,15 @@ protected:
|
|||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void userAdded(Quotient::User *user);
|
void memberJoined(const Quotient::RoomMember &member);
|
||||||
void userRemoved(Quotient::User *user);
|
void memberLeft(const Quotient::RoomMember &member);
|
||||||
void refreshUser(Quotient::User *user, const QList<int> &roles = {});
|
void refreshMember(const Quotient::RoomMember &member, const QList<int> &roles = {});
|
||||||
void refreshAllUsers();
|
void refreshAllMembers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<NeoChatRoom> m_currentRoom;
|
QPointer<NeoChatRoom> m_currentRoom;
|
||||||
QList<Quotient::User *> m_users;
|
QList<QString> m_members;
|
||||||
|
|
||||||
int findUserPos(Quotient::User *user) const;
|
int findUserPos(const Quotient::RoomMember &member) const;
|
||||||
[[nodiscard]] int findUserPos(const QString &username) const;
|
[[nodiscard]] int findUserPos(const QString &userId) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -381,34 +381,30 @@ bool NeoChatConnection::directChatExists(Quotient::User *user)
|
|||||||
void NeoChatConnection::openOrCreateDirectChat(const QString &userId)
|
void NeoChatConnection::openOrCreateDirectChat(const QString &userId)
|
||||||
{
|
{
|
||||||
if (auto user = this->user(userId)) {
|
if (auto user = this->user(userId)) {
|
||||||
openOrCreateDirectChat(user);
|
const auto existing = directChats();
|
||||||
|
|
||||||
|
if (existing.contains(user)) {
|
||||||
|
const auto room = this->room(existing.value(user));
|
||||||
|
if (room) {
|
||||||
|
RoomManager::instance().resolveResource(room->id());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestDirectChat(userId);
|
||||||
|
connect(
|
||||||
|
this,
|
||||||
|
&Connection::directChatAvailable,
|
||||||
|
this,
|
||||||
|
[=](auto room) {
|
||||||
|
room->activateEncryption();
|
||||||
|
},
|
||||||
|
Qt::SingleShotConnection);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "openOrCreateDirectChat: Couldn't get user object for ID " << userId << ", unable to open/request direct chat.";
|
qWarning() << "openOrCreateDirectChat: Couldn't get user object for ID " << userId << ", unable to open/request direct chat.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoChatConnection::openOrCreateDirectChat(User *user)
|
|
||||||
{
|
|
||||||
const auto existing = directChats();
|
|
||||||
|
|
||||||
if (existing.contains(user)) {
|
|
||||||
const auto room = this->room(existing.value(user));
|
|
||||||
if (room) {
|
|
||||||
RoomManager::instance().resolveResource(room->id());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requestDirectChat(user);
|
|
||||||
connect(
|
|
||||||
this,
|
|
||||||
&Connection::directChatAvailable,
|
|
||||||
this,
|
|
||||||
[=](auto room) {
|
|
||||||
room->activateEncryption();
|
|
||||||
},
|
|
||||||
Qt::SingleShotConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype NeoChatConnection::directChatNotifications() const
|
qsizetype NeoChatConnection::directChatNotifications() const
|
||||||
{
|
{
|
||||||
qsizetype notifications = 0;
|
qsizetype notifications = 0;
|
||||||
|
|||||||
@@ -151,13 +151,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE void openOrCreateDirectChat(const QString &userId);
|
Q_INVOKABLE void openOrCreateDirectChat(const QString &userId);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Join a direct chat with the given user object.
|
|
||||||
*
|
|
||||||
* If a direct chat with the user doesn't exist one is created and then joined.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the account data with \param type as a formatted JSON string.
|
* @brief Get the account data with \param type as a formatted JSON string.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -100,22 +100,25 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
|||||||
this,
|
this,
|
||||||
&Room::baseStateLoaded,
|
&Room::baseStateLoaded,
|
||||||
this,
|
this,
|
||||||
[this]() {
|
[this, connection]() {
|
||||||
updatePushNotificationState(QStringLiteral("m.push_rules"));
|
updatePushNotificationState(QStringLiteral("m.push_rules"));
|
||||||
|
|
||||||
Q_EMIT canEncryptRoomChanged();
|
Q_EMIT canEncryptRoomChanged();
|
||||||
if (this->joinState() != JoinState::Invite) {
|
if (this->joinState() != JoinState::Invite) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localUser()->id());
|
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localMember().id());
|
||||||
QImage avatar_image;
|
QImage avatar_image;
|
||||||
if (roomMemberEvent && !user(roomMemberEvent->senderId())->avatarUrl(this).isEmpty()) {
|
if (roomMemberEvent && !member(roomMemberEvent->senderId()).avatarUrl().isEmpty()) {
|
||||||
avatar_image = user(roomMemberEvent->senderId())->avatar(128, this);
|
avatar_image = memberAvatar(roomMemberEvent->senderId()).get(connection, 128, {});
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "using this room's avatar";
|
qWarning() << "using this room's avatar";
|
||||||
avatar_image = avatar(128);
|
avatar_image = avatar(128);
|
||||||
}
|
}
|
||||||
NotificationsManager::instance().postInviteNotification(this, displayName(), htmlSafeMemberName(roomMemberEvent->senderId()), avatar_image);
|
NotificationsManager::instance().postInviteNotification(this,
|
||||||
|
displayName(),
|
||||||
|
member(roomMemberEvent->senderId()).htmlSafeDisplayName(),
|
||||||
|
avatar_image);
|
||||||
},
|
},
|
||||||
Qt::SingleShotConnection);
|
Qt::SingleShotConnection);
|
||||||
connect(this, &Room::changed, this, [this] {
|
connect(this, &Room::changed, this, [this] {
|
||||||
@@ -264,18 +267,18 @@ void NeoChatRoom::forget()
|
|||||||
|
|
||||||
QVariantList NeoChatRoom::getUsersTyping() const
|
QVariantList NeoChatRoom::getUsersTyping() const
|
||||||
{
|
{
|
||||||
auto users = usersTyping();
|
auto users = membersTyping();
|
||||||
users.removeAll(localUser());
|
users.removeAll(localMember());
|
||||||
QVariantList userVariants;
|
QVariantList userVariants;
|
||||||
for (const auto &user : users) {
|
for (const auto &user : users) {
|
||||||
if (connection()->isIgnored(user->id())) {
|
if (connection()->isIgnored(user.id())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
userVariants.append(QVariantMap{
|
userVariants.append(QVariantMap{
|
||||||
{"id"_ls, user->id()},
|
{"id"_ls, user.id()},
|
||||||
{"avatarMediaId"_ls, user->avatarMediaId(this)},
|
{"avatarMediaId"_ls, user.avatarMediaId()},
|
||||||
{"displayName"_ls, user->displayname(this)},
|
{"displayName"_ls, user.displayName()},
|
||||||
{"display"_ls, user->name()},
|
{"display"_ls, user.name()},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return userVariants;
|
return userVariants;
|
||||||
@@ -283,7 +286,7 @@ QVariantList NeoChatRoom::getUsersTyping() const
|
|||||||
|
|
||||||
void NeoChatRoom::sendTypingNotification(bool isTyping)
|
void NeoChatRoom::sendTypingNotification(bool isTyping)
|
||||||
{
|
{
|
||||||
connection()->callApi<SetTypingJob>(BackgroundRequest, localUser()->id(), id(), isTyping, 10000);
|
connection()->callApi<SetTypingJob>(BackgroundRequest, localMember().id(), id(), isTyping, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const RoomEvent *NeoChatRoom::lastEvent() const
|
const RoomEvent *NeoChatRoom::lastEvent() const
|
||||||
@@ -321,7 +324,7 @@ const RoomEvent *NeoChatRoom::lastEvent() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection()->isIgnored(user(event->senderId()))) {
|
if (connection()->isIgnored(event->senderId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,13 +384,13 @@ bool NeoChatRoom::isEventHighlighted(const RoomEvent *e) const
|
|||||||
|
|
||||||
void NeoChatRoom::checkForHighlights(const Quotient::TimelineItem &ti)
|
void NeoChatRoom::checkForHighlights(const Quotient::TimelineItem &ti)
|
||||||
{
|
{
|
||||||
auto localUserId = localUser()->id();
|
auto localUserId = localMember().id();
|
||||||
if (ti->senderId() == localUserId) {
|
if (ti->senderId() == localUserId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto *e = ti.viewAs<RoomMessageEvent>()) {
|
if (auto *e = ti.viewAs<RoomMessageEvent>()) {
|
||||||
const auto &text = e->plainBody();
|
const auto &text = e->plainBody();
|
||||||
if (text.contains(localUserId) || text.contains(safeMemberName(localUserId))) {
|
if (text.contains(localUserId) || text.contains(localUserId)) {
|
||||||
highlights.insert(e);
|
highlights.insert(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,24 +449,20 @@ static const QVariantMap emptyUser = {
|
|||||||
|
|
||||||
QVariantMap NeoChatRoom::getUser(const QString &userID) const
|
QVariantMap NeoChatRoom::getUser(const QString &userID) const
|
||||||
{
|
{
|
||||||
return getUser(user(userID));
|
return getUser(member(userID));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap NeoChatRoom::getUser(User *user) const
|
QVariantMap NeoChatRoom::getUser(RoomMember member) const
|
||||||
{
|
{
|
||||||
if (user == nullptr) {
|
|
||||||
return emptyUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariantMap{
|
return QVariantMap{
|
||||||
{QStringLiteral("isLocalUser"), user->id() == localUser()->id()},
|
{QStringLiteral("isLocalUser"), member.id() == localMember().id()},
|
||||||
{QStringLiteral("id"), user->id()},
|
{QStringLiteral("id"), member.id()},
|
||||||
{QStringLiteral("displayName"), user->displayname(this)},
|
{QStringLiteral("displayName"), member.displayName()},
|
||||||
{QStringLiteral("escapedDisplayName"), htmlSafeMemberName(user->id())},
|
{QStringLiteral("escapedDisplayName"), member.htmlSafeDisplayName()},
|
||||||
{QStringLiteral("avatarSource"), avatarForMember(user)},
|
{QStringLiteral("avatarSource"), member.avatarUrl()},
|
||||||
{QStringLiteral("avatarMediaId"), user->avatarMediaId(this)},
|
{QStringLiteral("avatarMediaId"), member.avatarMediaId()},
|
||||||
{QStringLiteral("color"), Utils::getUserColor(user->hueF())},
|
{QStringLiteral("color"), Utils::getUserColor(member.hueF())},
|
||||||
{QStringLiteral("object"), QVariant::fromValue(user)},
|
{QStringLiteral("object"), QVariant::fromValue(member)},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,10 +473,10 @@ QString NeoChatRoom::avatarMediaId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use the first (excluding self) user's avatar for direct chats
|
// Use the first (excluding self) user's avatar for direct chats
|
||||||
const auto dcUsers = directChatUsers();
|
const auto dcUsers = directChatMembers();
|
||||||
for (const auto u : dcUsers) {
|
for (const auto u : dcUsers) {
|
||||||
if (u != localUser()) {
|
if (u != localMember()) {
|
||||||
return u->avatarMediaId(this);
|
return u.avatarMediaId().mid(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -644,7 +643,7 @@ void NeoChatRoom::toggleReaction(const QString &eventId, const QString &reaction
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->senderId() == localUser()->id()) {
|
if (e->senderId() == localMember().id()) {
|
||||||
redactEventIds.push_back(e->id());
|
redactEventIds.push_back(e->id());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -673,7 +672,7 @@ bool NeoChatRoom::canSendEvent(const QString &eventType) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto pl = plEvent->powerLevelForEvent(eventType);
|
auto pl = plEvent->powerLevelForEvent(eventType);
|
||||||
auto currentPl = plEvent->powerLevelForUser(localUser()->id());
|
auto currentPl = plEvent->powerLevelForUser(localMember().id());
|
||||||
|
|
||||||
return currentPl >= pl;
|
return currentPl >= pl;
|
||||||
}
|
}
|
||||||
@@ -685,7 +684,7 @@ bool NeoChatRoom::canSendState(const QString &eventType) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto pl = plEvent->powerLevelForState(eventType);
|
auto pl = plEvent->powerLevelForState(eventType);
|
||||||
auto currentPl = plEvent->powerLevelForUser(localUser()->id());
|
auto currentPl = plEvent->powerLevelForUser(localMember().id());
|
||||||
|
|
||||||
return currentPl >= pl;
|
return currentPl >= pl;
|
||||||
}
|
}
|
||||||
@@ -863,7 +862,7 @@ void NeoChatRoom::setUrlPreviewEnabled(const bool &urlPreviewEnabled)
|
|||||||
* "type": "org.matrix.room.preview_urls",
|
* "type": "org.matrix.room.preview_urls",
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
connection()->callApi<SetAccountDataPerRoomJob>(localUser()->id(),
|
connection()->callApi<SetAccountDataPerRoomJob>(localMember().id(),
|
||||||
id(),
|
id(),
|
||||||
"org.matrix.room.preview_urls"_ls,
|
"org.matrix.room.preview_urls"_ls,
|
||||||
QJsonObject{{"disable"_ls, !urlPreviewEnabled}});
|
QJsonObject{{"disable"_ls, !urlPreviewEnabled}});
|
||||||
@@ -1531,7 +1530,7 @@ void NeoChatRoom::editLastMessage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the current message's sender's id is same as the user's id
|
// check if the current message's sender's id is same as the user's id
|
||||||
if ((*it)->senderId() == localUser()->id()) {
|
if ((*it)->senderId() == localMember().id()) {
|
||||||
auto content = (*it)->contentJson();
|
auto content = (*it)->contentJson();
|
||||||
|
|
||||||
if (e->msgtype() != MessageEventType::Unknown) {
|
if (e->msgtype() != MessageEventType::Unknown) {
|
||||||
@@ -1656,13 +1655,13 @@ int NeoChatRoom::maxRoomVersion() const
|
|||||||
return maxVersion;
|
return maxVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quotient::User *NeoChatRoom::directChatRemoteUser() const
|
RoomMember NeoChatRoom::directChatRemoteUser() const
|
||||||
{
|
{
|
||||||
auto users = connection()->directChatUsers(this);
|
auto users = connection()->directChatMemberIds(this);
|
||||||
if (users.isEmpty()) {
|
if (users.isEmpty()) {
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
return users[0];
|
return member(users[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoChatRoom::sendLocation(float lat, float lon, const QString &description)
|
void NeoChatRoom::sendLocation(float lat, float lon, const QString &description)
|
||||||
@@ -1694,9 +1693,9 @@ QByteArray NeoChatRoom::roomAcountDataJson(const QString &eventType)
|
|||||||
return QJsonDocument(accountData(eventType)->fullJson()).toJson();
|
return QJsonDocument(accountData(eventType)->fullJson()).toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl NeoChatRoom::avatarForMember(Quotient::User *user) const
|
QUrl NeoChatRoom::avatarForMember(RoomMember member) const
|
||||||
{
|
{
|
||||||
const auto &url = memberAvatarUrl(user->id());
|
const auto &url = member.avatarUrl();
|
||||||
if (url.isEmpty() || url.scheme() != "mxc"_ls) {
|
if (url.isEmpty() || url.scheme() != "mxc"_ls) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -1780,9 +1779,9 @@ void NeoChatRoom::cleanupExtraEvent(const QString &eventId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
User *NeoChatRoom::invitingUser() const
|
QString NeoChatRoom::invitingUserId() const
|
||||||
{
|
{
|
||||||
return connection()->user(currentState().get<RoomMemberEvent>(connection()->userId())->senderId());
|
return currentState().get<RoomMemberEvent>(connection()->userId())->senderId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoChatRoom::setRoomState(const QString &type, const QString &stateKey, const QByteArray &content)
|
void NeoChatRoom::setRoomState(const QString &type, const QString &stateKey, const QByteArray &content)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class NeoChatRoom : public Quotient::Room
|
|||||||
/**
|
/**
|
||||||
* @brief Get a user object for the other person in a direct chat.
|
* @brief Get a user object for the other person in a direct chat.
|
||||||
*/
|
*/
|
||||||
Q_PROPERTY(Quotient::User *directChatRemoteUser READ directChatRemoteUser CONSTANT)
|
Q_PROPERTY(Quotient::RoomMember directChatRemoteUser READ directChatRemoteUser CONSTANT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The Matrix IDs of this room's parents.
|
* @brief The Matrix IDs of this room's parents.
|
||||||
@@ -285,7 +285,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @sa Quotient::User
|
* @sa Quotient::User
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE [[nodiscard]] QVariantMap getUser(Quotient::User *user) const;
|
Q_INVOKABLE [[nodiscard]] QVariantMap getUser(Quotient::RoomMember member) const;
|
||||||
|
|
||||||
[[nodiscard]] QVariantList getUsersTyping() const;
|
[[nodiscard]] QVariantList getUsersTyping() const;
|
||||||
|
|
||||||
@@ -400,7 +400,7 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] QString avatarMediaId() const;
|
[[nodiscard]] QString avatarMediaId() const;
|
||||||
|
|
||||||
Quotient::User *directChatRemoteUser() const;
|
Quotient::RoomMember directChatRemoteUser() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether this room has one or more parent spaces set.
|
* @brief Whether this room has one or more parent spaces set.
|
||||||
@@ -630,7 +630,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE QByteArray roomAcountDataJson(const QString &eventType);
|
Q_INVOKABLE QByteArray roomAcountDataJson(const QString &eventType);
|
||||||
|
|
||||||
Q_INVOKABLE [[nodiscard]] QUrl avatarForMember(Quotient::User *user) const;
|
Q_INVOKABLE [[nodiscard]] QUrl avatarForMember(Quotient::RoomMember member) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the event with the given id from the server and saves it locally.
|
* @brief Loads the event with the given id from the server and saves it locally.
|
||||||
@@ -660,7 +660,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* If we're invited to this room, the user that invited us. Undefined in other cases.
|
* If we're invited to this room, the user that invited us. Undefined in other cases.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE Quotient::User *invitingUser() const;
|
Q_INVOKABLE QString invitingUserId() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<const Quotient::RoomEvent *> highlights;
|
QSet<const Quotient::RoomEvent *> highlights;
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
|||||||
|
|
||||||
void NotificationsManager::handleNotifications(QPointer<NeoChatConnection> connection)
|
void NotificationsManager::handleNotifications(QPointer<NeoChatConnection> connection)
|
||||||
{
|
{
|
||||||
if (!m_connActiveJob.contains(connection->user()->id())) {
|
if (!m_connActiveJob.contains(connection->userId())) {
|
||||||
auto job = connection->callApi<GetNotificationsJob>();
|
auto job = connection->callApi<GetNotificationsJob>();
|
||||||
m_connActiveJob.append(connection->user()->id());
|
m_connActiveJob.append(connection->user()->id());
|
||||||
connect(job, &BaseJob::success, this, [this, job, connection]() {
|
connect(job, &BaseJob::success, this, [this, job, connection]() {
|
||||||
m_connActiveJob.removeAll(connection->user()->id());
|
m_connActiveJob.removeAll(connection->userId());
|
||||||
processNotificationJob(connection, job, !m_oldNotifications.contains(connection->user()->id()));
|
processNotificationJob(connection, job, !m_oldNotifications.contains(connection->userId()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ void NotificationsManager::processNotificationJob(QPointer<NeoChatConnection> co
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto connectionId = connection->user()->id();
|
const auto connectionId = connection->userId();
|
||||||
|
|
||||||
const auto notifications = job->jsonData()["notifications"_ls].toArray();
|
const auto notifications = job->jsonData()["notifications"_ls].toArray();
|
||||||
if (initialization) {
|
if (initialization) {
|
||||||
@@ -108,7 +108,7 @@ void NotificationsManager::processNotificationJob(QPointer<NeoChatConnection> co
|
|||||||
if (!room) {
|
if (!room) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto sender = room->user(notification["event"_ls]["sender"_ls].toString());
|
auto sender = room->member(notification["event"_ls]["sender"_ls].toString());
|
||||||
|
|
||||||
QString body;
|
QString body;
|
||||||
if (notification["event"_ls]["type"_ls].toString() == "org.matrix.msc3381.poll.start"_ls) {
|
if (notification["event"_ls]["type"_ls].toString() == "org.matrix.msc3381.poll.start"_ls) {
|
||||||
@@ -124,13 +124,13 @@ void NotificationsManager::processNotificationJob(QPointer<NeoChatConnection> co
|
|||||||
}
|
}
|
||||||
|
|
||||||
QImage avatar_image;
|
QImage avatar_image;
|
||||||
if (!sender->avatarUrl(room).isEmpty()) {
|
if (!sender.avatarUrl().isEmpty()) {
|
||||||
avatar_image = sender->avatar(128, room);
|
avatar_image = room->memberAvatar(sender.id()).get(connection, 128, {});
|
||||||
} else {
|
} else {
|
||||||
avatar_image = room->avatar(128);
|
avatar_image = room->avatar(128);
|
||||||
}
|
}
|
||||||
postNotification(dynamic_cast<NeoChatRoom *>(room),
|
postNotification(dynamic_cast<NeoChatRoom *>(room),
|
||||||
sender->displayname(room),
|
sender.displayName(),
|
||||||
body,
|
body,
|
||||||
avatar_image,
|
avatar_image,
|
||||||
notification["event"_ls].toObject()["event_id"_ls].toString(),
|
notification["event"_ls].toObject()["event_id"_ls].toString(),
|
||||||
@@ -213,7 +213,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
|||||||
if (!room) {
|
if (!room) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto connection = dynamic_cast<NeoChatConnection *>(Controller::instance().accounts().get(room->localUser()->id()));
|
auto connection = dynamic_cast<NeoChatConnection *>(Controller::instance().accounts().get(room->localMember().id()));
|
||||||
Controller::instance().setActiveConnection(connection);
|
Controller::instance().setActiveConnection(connection);
|
||||||
RoomManager::instance().setConnection(connection);
|
RoomManager::instance().setConnection(connection);
|
||||||
RoomManager::instance().resolveResource(room->id());
|
RoomManager::instance().resolveResource(room->id());
|
||||||
@@ -230,7 +230,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
|||||||
notification->setReplyAction(std::move(replyAction));
|
notification->setReplyAction(std::move(replyAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localUser()->id());
|
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localMember().id());
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ void NotificationsManager::postInviteNotification(NeoChatRoom *rawRoom, const QS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RoomManager::instance().leaveRoom(room);
|
RoomManager::instance().leaveRoom(room);
|
||||||
room->connection()->addToIgnoredUsers(room->invitingUser());
|
room->connection()->addToIgnoredUsers(room->invitingUserId());
|
||||||
notification->close();
|
notification->close();
|
||||||
});
|
});
|
||||||
connect(notification, &KNotification::closed, this, [this, room]() {
|
connect(notification, &KNotification::closed, this, [this, room]() {
|
||||||
@@ -286,7 +286,7 @@ void NotificationsManager::postInviteNotification(NeoChatRoom *rawRoom, const QS
|
|||||||
m_invitations.remove(room->id());
|
m_invitations.remove(room->id());
|
||||||
});
|
});
|
||||||
|
|
||||||
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localUser()->id());
|
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localMember().id());
|
||||||
|
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ void PollHandler::sendPollAnswer(const QString &eventId, const QString &answerId
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QStringList ownAnswers;
|
QStringList ownAnswers;
|
||||||
for (const auto &answer : m_answers[room->localUser()->id()].toArray()) {
|
for (const auto &answer : m_answers[room->localMember().id()].toArray()) {
|
||||||
ownAnswers += answer.toString();
|
ownAnswers += answer.toString();
|
||||||
}
|
}
|
||||||
if (ownAnswers.contains(answerId)) {
|
if (ownAnswers.contains(answerId)) {
|
||||||
@@ -169,7 +169,7 @@ void PollHandler::sendPollAnswer(const QString &eventId, const QString &answerId
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto response = new PollResponseEvent(eventId, ownAnswers);
|
auto response = new PollResponseEvent(eventId, ownAnswers);
|
||||||
handleAnswer(response->contentJson(), room->localUser()->id(), QDateTime::currentDateTime());
|
handleAnswer(response->contentJson(), room->localMember().id(), QDateTime::currentDateTime());
|
||||||
room->postEvent(response);
|
room->postEvent(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -351,10 +351,10 @@ Kirigami.ApplicationWindow {
|
|||||||
dialog.closeDialog()
|
dialog.closeDialog()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function showUserDetail(user) {
|
function showUserDetail(user, room) {
|
||||||
Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root.QQC2.ApplicationWindow.window, {
|
Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root.QQC2.ApplicationWindow.window, {
|
||||||
room: RoomManager.currentRoom ? RoomManager.currentRoom : null,
|
room: room,
|
||||||
user: RoomManager.currentRoom ? RoomManager.currentRoom.getUser(user.id) : QmlUtils.getUser(user),
|
user: user,
|
||||||
connection: root.connection
|
connection: root.connection
|
||||||
}).open();
|
}).open();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ Kirigami.Dialog {
|
|||||||
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
|
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
|
||||||
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
|
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
|
||||||
|
|
||||||
name: root.user.displayName
|
name: root.room ? root.room.member(root.user.id).displayName : root.user.displayName
|
||||||
source: root.user.avatarSource
|
source: root.room ? root.room.member(root.user.id).avatarUrl : root.user.avatarUrl
|
||||||
color: root.user.color
|
color: root.room ? root.room.member(root.user.id).color : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@@ -63,7 +63,7 @@ Kirigami.Dialog {
|
|||||||
|
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
wrapMode: Text.NoWrap
|
wrapMode: Text.NoWrap
|
||||||
text: root.user.displayName
|
text: root.room ? root.room.member(root.user.id).displayName : root.user.displayName
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +84,10 @@ Kirigami.Dialog {
|
|||||||
onClicked: {
|
onClicked: {
|
||||||
let map = qrMaximizeComponent.createObject(parent, {
|
let map = qrMaximizeComponent.createObject(parent, {
|
||||||
text: barcode.content,
|
text: barcode.content,
|
||||||
title: root.user.displayName,
|
title: root.room ? root.room.member(root.user.id).displayName : root.user.displayName,
|
||||||
subtitle: root.user.id,
|
subtitle: root.user.id,
|
||||||
avatarColor: root.user.color,
|
avatarColor: root.room?.member(root.user.id).color,
|
||||||
avatarSource: root.user.avatarSource
|
avatarSource: root.room? root.room.member(root.user.id).avatarUrl : root.user.avatarUrl
|
||||||
});
|
});
|
||||||
root.close();
|
root.close();
|
||||||
map.open();
|
map.open();
|
||||||
@@ -104,19 +104,19 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: !root.user.isLocalUser && !!root.user.object
|
visible: root.user.id !== root.connection.localUserId && !!root.user
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: !!root.user.object && root.connection.isIgnored(root.user.object) ? i18n("Unignore this user") : i18n("Ignore this user")
|
text: !!root.user && root.connection.isIgnored(root.user.id) ? i18n("Unignore this user") : i18n("Ignore this user")
|
||||||
icon.name: "im-invisible-user"
|
icon.name: "im-invisible-user"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.close();
|
root.close();
|
||||||
root.connection.isIgnored(root.user.object) ? root.connection.removeFromIgnoredUsers(root.user.object) : root.connection.addToIgnoredUsers(root.user.object);
|
root.connection.isIgnored(root.user.id) ? root.connection.removeFromIgnoredUsers(root.user.id) : root.connection.addToIgnoredUsers(root.user.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: root.room && !root.user.isLocalUser && room.canSendState("kick") && room.containsUser(root.user.id) && room.getUserPowerLevel(root.user.id) < room.getUserPowerLevel(root.connection.localUser.id)
|
visible: root.room && root.user.id !== root.connection.localUserId && room.canSendState("kick") && room.containsUser(root.user.id) && room.getUserPowerLevel(root.user.id) < room.getUserPowerLevel(root.connection.localUserId)
|
||||||
|
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18n("Kick this user")
|
text: i18n("Kick this user")
|
||||||
@@ -129,7 +129,7 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: root.room && !root.user.isLocalUser && room.canSendState("invite") && !room.containsUser(root.user.id)
|
visible: root.room && root.user.id !== root.connection.localUserId && room.canSendState("invite") && !room.containsUser(root.user.id)
|
||||||
|
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
enabled: root.room && !root.room.isUserBanned(root.user.id)
|
enabled: root.room && !root.room.isUserBanned(root.user.id)
|
||||||
@@ -143,7 +143,7 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: root.room && !root.user.isLocalUser && room.canSendState("ban") && !room.isUserBanned(root.user.id) && room.getUserPowerLevel(root.user.id) < room.getUserPowerLevel(root.room.connection.localUser.id)
|
visible: root.room && root.user.id !== root.connection.localUserId && room.canSendState("ban") && !room.isUserBanned(root.user.id) && room.getUserPowerLevel(root.user.id) < room.getUserPowerLevel(root.connection.localUserId)
|
||||||
|
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18n("Ban this user")
|
text: i18n("Ban this user")
|
||||||
@@ -163,7 +163,7 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: root.room && !root.user.isLocalUser && room.canSendState("ban") && room.isUserBanned(root.user.id)
|
visible: root.room && root.user.id !== root.connection.localUserId && room.canSendState("ban") && room.isUserBanned(root.user.id)
|
||||||
|
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18n("Unban this user")
|
text: i18n("Unban this user")
|
||||||
@@ -201,7 +201,7 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: root.room && (root.user.isLocalUser || room.canSendState("redact"))
|
visible: root.room && (root.user.id === root.connection.localUserId || room.canSendState("redact"))
|
||||||
|
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18n("Remove recent messages by this user")
|
text: i18n("Remove recent messages by this user")
|
||||||
@@ -221,12 +221,12 @@ Kirigami.Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormButtonDelegate {
|
FormCard.FormButtonDelegate {
|
||||||
visible: !root.user.isLocalUser
|
visible: root.user.id !== root.connection.localUserId
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: root.connection.directChatExists(root.user.object) ? i18nc("%1 is the name of the user.", "Chat with %1", root.user.escapedDisplayName) : i18n("Invite to private chat")
|
text: root.connection.directChatExists(root.user) ? i18nc("%1 is the name of the user.", "Chat with %1", root.room ? root.room.member(root.user.id).htmlSafeDisplayName : QmlUtils.escapeString(root.user.displayName)) : i18n("Invite to private chat")
|
||||||
icon.name: "document-send"
|
icon.name: "document-send"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.connection.openOrCreateDirectChat(root.user.object);
|
root.connection.openOrCreateDirectChat(root.user.id);
|
||||||
root.close();
|
root.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ QString Registration::recaptchaSiteKey() const
|
|||||||
void Registration::registerAccount()
|
void Registration::registerAccount()
|
||||||
{
|
{
|
||||||
setStatus(Working);
|
setStatus(Working);
|
||||||
Omittable<QJsonObject> authData = none;
|
Omittable<QJsonObject> authData;
|
||||||
if (nextStep() == "m.login.recaptcha"_ls) {
|
if (nextStep() == "m.login.recaptcha"_ls) {
|
||||||
authData = QJsonObject{
|
authData = QJsonObject{
|
||||||
{"type"_ls, "m.login.recaptcha"_ls},
|
{"type"_ls, "m.login.recaptcha"_ls},
|
||||||
@@ -185,7 +185,7 @@ void Registration::testHomeserver()
|
|||||||
if (m_testServerJob) {
|
if (m_testServerJob) {
|
||||||
delete m_testServerJob;
|
delete m_testServerJob;
|
||||||
}
|
}
|
||||||
m_testServerJob = m_connection->callApi<NeoChatRegisterJob>("user"_ls, none, "user"_ls, QString(), QString(), QString(), false);
|
m_testServerJob = m_connection->callApi<NeoChatRegisterJob>("user"_ls, quotientNone, "user"_ls, QString(), QString(), QString(), false);
|
||||||
connect(m_testServerJob.data(), &BaseJob::finished, this, [this]() {
|
connect(m_testServerJob.data(), &BaseJob::finished, this, [this]() {
|
||||||
if (m_testServerJob->error() == BaseJob::StatusCode::ContentAccessError) {
|
if (m_testServerJob->error() == BaseJob::StatusCode::ContentAccessError) {
|
||||||
setStatus(ServerNoRegistration);
|
setStatus(ServerNoRegistration);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/util.h>
|
#include <Quotient/util.h>
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
{
|
{
|
||||||
class CheckUsernameAvailabilityJob;
|
class CheckUsernameAvailabilityJob;
|
||||||
@@ -27,12 +29,12 @@ class NeoChatRegisterJob : public Quotient::BaseJob
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NeoChatRegisterJob(const QString &kind = QStringLiteral("user"),
|
explicit NeoChatRegisterJob(const QString &kind = QStringLiteral("user"),
|
||||||
const Quotient::Omittable<QJsonObject> &auth = Quotient::none,
|
const Omittable<QJsonObject> &auth = {},
|
||||||
const QString &username = {},
|
const QString &username = {},
|
||||||
const QString &password = {},
|
const QString &password = {},
|
||||||
const QString &deviceId = {},
|
const QString &deviceId = {},
|
||||||
const QString &initialDeviceDisplayName = {},
|
const QString &initialDeviceDisplayName = {},
|
||||||
Quotient::Omittable<bool> inhibitLogin = Quotient::none);
|
Omittable<bool> inhibitLogin = {});
|
||||||
|
|
||||||
QString userId() const
|
QString userId() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -147,7 +147,10 @@ void RoomManager::resolveResource(const QString &idOrUri, const QString &action)
|
|||||||
Q_EMIT askJoinRoom(uri.primaryId());
|
Q_EMIT askJoinRoom(uri.primaryId());
|
||||||
}
|
}
|
||||||
} else { // Invalid cases should have been eliminated earlier
|
} else { // Invalid cases should have been eliminated earlier
|
||||||
Q_ASSERT(result == Quotient::UriResolved);
|
if (result == Quotient::UriResolved) {
|
||||||
|
// we used to assert here, but we shouldn't assert based on invalid user data
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) {
|
if (uri.type() == Uri::RoomAlias || uri.type() == Uri::RoomId) {
|
||||||
connect(
|
connect(
|
||||||
@@ -255,10 +258,10 @@ void RoomManager::openRoomForActiveConnection()
|
|||||||
|
|
||||||
UriResolveResult RoomManager::visitUser(User *user, const QString &action)
|
UriResolveResult RoomManager::visitUser(User *user, const QString &action)
|
||||||
{
|
{
|
||||||
if (action == "mention"_ls || action.isEmpty()) {
|
if (action == "mention"_ls || action == "qr"_ls || action.isEmpty()) {
|
||||||
// send it has QVariantMap because the properties in the
|
// send it has QVariantMap because the properties in the
|
||||||
user->load();
|
user->load();
|
||||||
Q_EMIT showUserDetail(user);
|
Q_EMIT showUserDetail(user, action == "qr"_ls ? nullptr : currentRoom());
|
||||||
} else if (action == "_interactive"_ls) {
|
} else if (action == "_interactive"_ls) {
|
||||||
user->requestDirectChat();
|
user->requestDirectChat();
|
||||||
} else if (action == "chat"_ls) {
|
} else if (action == "chat"_ls) {
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ Q_SIGNALS:
|
|||||||
* Ask current room to open the user's details for the give user.
|
* Ask current room to open the user's details for the give user.
|
||||||
* This assumes the user is loaded.
|
* This assumes the user is loaded.
|
||||||
*/
|
*/
|
||||||
void showUserDetail(const Quotient::User *user);
|
void showUserDetail(const Quotient::User *user, NeoChatRoom *room);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request a media item is shown maximized.
|
* @brief Request a media item is shown maximized.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ FormCard.FormCardPage {
|
|||||||
QQC2.ToolButton {
|
QQC2.ToolButton {
|
||||||
text: i18nc("@action:button", "Unignore this user")
|
text: i18nc("@action:button", "Unignore this user")
|
||||||
icon.name: "list-remove-symbolic"
|
icon.name: "list-remove-symbolic"
|
||||||
onClicked: root.connection.removeFromIgnoredUsers(root.connection.user(modelData))
|
onClicked: root.connection.removeFromIgnoredUsers(modelData)
|
||||||
display: QQC2.Button.IconOnly
|
display: QQC2.Button.IconOnly
|
||||||
QQC2.ToolTip.text: text
|
QQC2.ToolTip.text: text
|
||||||
QQC2.ToolTip.visible: hovered
|
QQC2.ToolTip.visible: hovered
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent)
|
SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent)
|
||||||
@@ -62,7 +64,7 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_nextBatchTokens[spaceId] = QString();
|
m_nextBatchTokens[spaceId] = QString();
|
||||||
auto job = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, none, none, none, *m_nextBatchTokens[spaceId]);
|
auto job = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, quotientNone, quotientNone, quotientNone, *m_nextBatchTokens[spaceId]);
|
||||||
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
||||||
m_spaceHierarchy.insert(spaceId, group.readEntry(spaceId, QStringList()));
|
m_spaceHierarchy.insert(spaceId, group.readEntry(spaceId, QStringList()));
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ void SpaceHierarchyCache::addBatch(const QString &spaceId, Quotient::GetSpaceHie
|
|||||||
const auto nextBatchToken = job->nextBatch();
|
const auto nextBatchToken = job->nextBatch();
|
||||||
if (!nextBatchToken.isEmpty() && nextBatchToken != *m_nextBatchTokens[spaceId]) {
|
if (!nextBatchToken.isEmpty() && nextBatchToken != *m_nextBatchTokens[spaceId]) {
|
||||||
*m_nextBatchTokens[spaceId] = nextBatchToken;
|
*m_nextBatchTokens[spaceId] = nextBatchToken;
|
||||||
auto nextJob = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, none, none, none, *m_nextBatchTokens[spaceId]);
|
auto nextJob = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, quotientNone, quotientNone, quotientNone, *m_nextBatchTokens[spaceId]);
|
||||||
connect(nextJob, &BaseJob::success, this, [this, nextJob, spaceId]() {
|
connect(nextJob, &BaseJob::success, this, [this, nextJob, spaceId]() {
|
||||||
addBatch(spaceId, nextJob);
|
addBatch(spaceId, nextJob);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -691,9 +691,9 @@ QString TextHandler::emoteString(const NeoChatRoom *room, const Quotient::RoomEv
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto e = eventCast<const Quotient::RoomMessageEvent>(event);
|
auto e = eventCast<const Quotient::RoomMessageEvent>(event);
|
||||||
auto author = room->user(e->senderId());
|
auto author = room->member(e->senderId());
|
||||||
return QStringLiteral("* <a href=\"https://matrix.to/#/") + e->senderId() + QStringLiteral("\" style=\"color:") + Utils::getUserColor(author->hueF()).name()
|
return QStringLiteral("* <a href=\"https://matrix.to/#/") + e->senderId() + QStringLiteral("\" style=\"color:") + Utils::getUserColor(author.hueF()).name()
|
||||||
+ QStringLiteral("\">") + author->displayname(room) + QStringLiteral("</a> ");
|
+ QStringLiteral("\">") + author.displayName() + QStringLiteral("</a> ");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TextHandler::convertCodeLanguageString(const QString &languageString)
|
QString TextHandler::convertCodeLanguageString(const QString &languageString)
|
||||||
|
|||||||
@@ -9,46 +9,14 @@
|
|||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
static const QVariantMap emptyUser = {
|
|
||||||
{"isLocalUser"_ls, false},
|
|
||||||
{"id"_ls, QString()},
|
|
||||||
{"displayName"_ls, QString()},
|
|
||||||
{"avatarSource"_ls, QUrl()},
|
|
||||||
{"avatarMediaId"_ls, QString()},
|
|
||||||
{"color"_ls, QColor()},
|
|
||||||
{"object"_ls, QVariant()},
|
|
||||||
};
|
|
||||||
|
|
||||||
QVariantMap QmlUtils::getUser(User *user) const
|
|
||||||
{
|
|
||||||
if (user == nullptr) {
|
|
||||||
return emptyUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &url = user->avatarUrl();
|
|
||||||
if (url.isEmpty() || url.scheme() != "mxc"_ls) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto avatarSource = user->connection()->makeMediaUrl(url);
|
|
||||||
if (!avatarSource.isValid() || avatarSource.scheme() != QStringLiteral("mxc")) {
|
|
||||||
avatarSource = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariantMap{
|
|
||||||
{QStringLiteral("isLocalUser"), user->id() == user->connection()->user()->id()},
|
|
||||||
{QStringLiteral("id"), user->id()},
|
|
||||||
{QStringLiteral("displayName"), user->displayname()},
|
|
||||||
{QStringLiteral("escapedDisplayName"), user->displayname().toHtmlEscaped()},
|
|
||||||
{QStringLiteral("avatarSource"), avatarSource},
|
|
||||||
{QStringLiteral("avatarMediaId"), user->avatarMediaId()},
|
|
||||||
{QStringLiteral("color"), Utils::getUserColor(user->hueF())},
|
|
||||||
{QStringLiteral("object"), QVariant::fromValue(user)},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlUtils::isValidJson(const QByteArray &json)
|
bool QmlUtils::isValidJson(const QByteArray &json)
|
||||||
{
|
{
|
||||||
return !QJsonDocument::fromJson(json).isNull();
|
return !QJsonDocument::fromJson(json).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QmlUtils::escapeString(const QString &string)
|
||||||
|
{
|
||||||
|
return string.toHtmlEscaped();
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_utils.cpp"
|
#include "moc_utils.cpp"
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ public:
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE QVariantMap getUser(Quotient::User *user) const;
|
|
||||||
Q_INVOKABLE bool isValidJson(const QByteArray &json);
|
Q_INVOKABLE bool isValidJson(const QByteArray &json);
|
||||||
|
Q_INVOKABLE QString escapeString(const QString &string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QmlUtils() = default;
|
QmlUtils() = default;
|
||||||
|
|||||||
Reference in New Issue
Block a user