diff --git a/autotests/eventhandlertest.cpp b/autotests/eventhandlertest.cpp index 7df92639a..6f922ebf3 100644 --- a/autotests/eventhandlertest.cpp +++ b/autotests/eventhandlertest.cpp @@ -105,7 +105,7 @@ void EventHandlerTest::author() 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["displayName"_ls], author->displayname(room)); QCOMPARE(eventHandlerAuthor["avatarSource"_ls], room->avatarForMember(author)); @@ -390,7 +390,7 @@ void EventHandlerTest::replyAuthor() 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["displayName"_ls], replyAuthor->displayname(room)); QCOMPARE(eventHandlerReplyAuthor["avatarSource"_ls], room->avatarForMember(replyAuthor)); diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index 8fd3cf535..e5ddaadbd 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -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++) { if (const auto event = eventCast(&**it)) { - if (event->senderId() == m_room->localUser()->id() && event->hasTextContent()) { + if (event->senderId() == m_room->localMember().id() && event->hasTextContent()) { QString originalString; if (event->content()) { originalString = static_cast(event->content())->body; diff --git a/src/eventhandler.cpp b/src/eventhandler.cpp index 4b26411d7..272ef0e33 100644 --- a/src/eventhandler.cpp +++ b/src/eventhandler.cpp @@ -73,7 +73,7 @@ QVariantMap EventHandler::getAuthor(bool isPending) const return m_room->getUser(nullptr); } - const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId()); + const auto author = isPending ? m_room->localMember() : m_room->user(m_event->senderId()); return m_room->getUser(author); } @@ -96,7 +96,7 @@ QString EventHandler::getAuthorDisplayName(bool isPending) const } return previousDisplayName; } else { - const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId()); + const auto author = isPending ? m_room->localMember() : m_room->user(m_event->senderId()); return m_room->htmlSafeMemberName(author->id()); } } @@ -112,7 +112,7 @@ QString EventHandler::singleLineAuthorDisplayname(bool isPending) const return {}; } - const auto author = isPending ? m_room->localUser() : m_room->user(m_event->senderId()); + const auto author = isPending ? m_room->localMember() : m_room->user(m_event->senderId()); auto displayName = m_room->safeMemberName(author->id()); displayName.replace(QStringLiteral("
\n"), QStringLiteral(" ")); displayName.replace(QStringLiteral("
"), QStringLiteral(" ")); @@ -963,7 +963,7 @@ bool EventHandler::hasReadMarkers() const } auto userIds = m_room->userIdsAtEvent(m_event->id()); - userIds.remove(m_room->localUser()->id()); + userIds.remove(m_room->localMember().id()); return userIds.size() > 0; } @@ -979,7 +979,7 @@ QVariantList EventHandler::getReadMarkers(int maxMarkers) const } 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(); if (userIds.count() > maxMarkers) { @@ -1008,7 +1008,7 @@ QString EventHandler::getNumberExcessReadMarkers(int maxMarkers) const } auto userIds = m_room->userIdsAtEvent(m_event->id()); - userIds.remove(m_room->localUser()->id()); + userIds.remove(m_room->localMember().id()); if (userIds.count() > maxMarkers) { return QStringLiteral("+ ") + QString::number(userIds.count() - maxMarkers); @@ -1029,7 +1029,7 @@ QString EventHandler::getReadMarkersString() const } 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 diff --git a/src/models/actionsmodel.cpp b/src/models/actionsmodel.cpp index e59106e80..0e92b87b8 100644 --- a/src/models/actionsmodel.cpp +++ b/src/models/actionsmodel.cpp @@ -201,7 +201,7 @@ QList actions{ Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc(" is banned from this room.", "%1 is banned from this room.", text)); return QString(); } - if (room->localUser()->id() == text) { + if (room->localMember().id() == text) { Q_EMIT room->showMessage(NeoChatRoom::Positive, i18n("You are already in this room.")); return QString(); } @@ -430,11 +430,11 @@ QList actions{ if (!plEvent) { return QString(); } - if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) { + if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to ban users from this room.")); return QString(); } - if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) { + if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) { Q_EMIT room->showMessage( NeoChatRoom::Error, i18nc("You are not allowed to ban from this room.", "You are not allowed to ban %1 from this room.", parts[0])); @@ -463,7 +463,7 @@ QList actions{ if (!plEvent) { return QString(); } - if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) { + if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to unban users from this room.")); return QString(); } @@ -494,7 +494,7 @@ QList actions{ i18nc("'' does not look like a matrix id.", "'%1' does not look like a matrix id.", parts[0])); return QString(); } - if (parts[0] == room->localUser()->id()) { + if (parts[0] == room->localMember().id()) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You cannot kick yourself from the room.")); return QString(); } @@ -507,11 +507,11 @@ QList actions{ return QString(); } auto kick = plEvent->kick(); - if (plEvent->powerLevelForUser(room->localUser()->id()) < kick) { + if (plEvent->powerLevelForUser(room->localMember().id()) < kick) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to kick users from this room.")); return QString(); } - if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) { + if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) { Q_EMIT room->showMessage( NeoChatRoom::Error, i18nc("You are not allowed to kick from this room", "You are not allowed to kick %1 from this room.", parts[0])); diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index a7385c4ee..51749330e 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -251,7 +251,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) beginResetModel(); endResetModel(); }); - qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localUser()->id(); + qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localMember().id(); } else { lastReadEventId.clear(); } @@ -621,7 +621,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == IsEditableRole) { - return eventHandler.messageComponentType() == MessageComponentType::Text && evt.senderId() == m_currentRoom->localUser()->id(); + return eventHandler.messageComponentType() == MessageComponentType::Text && evt.senderId() == m_currentRoom->localMember().id(); } return {}; diff --git a/src/models/reactionmodel.cpp b/src/models/reactionmodel.cpp index 157dc3d03..f0a46de13 100644 --- a/src/models/reactionmodel.cpp +++ b/src/models/reactionmodel.cpp @@ -90,7 +90,7 @@ QVariant ReactionModel::data(const QModelIndex &index, int role) const if (role == HasLocalUser) { 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; } } diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 9cd3ff8da..58cf8264c 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -101,7 +101,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS if (this->joinState() != JoinState::Invite) { return; } - auto roomMemberEvent = currentState().get(localUser()->id()); + auto roomMemberEvent = currentState().get(localMember().id()); QImage avatar_image; if (roomMemberEvent && !user(roomMemberEvent->senderId())->avatarUrl(this).isEmpty()) { avatar_image = user(roomMemberEvent->senderId())->avatar(128, this); @@ -258,7 +258,7 @@ void NeoChatRoom::forget() QVariantList NeoChatRoom::getUsersTyping() const { auto users = usersTyping(); - users.removeAll(localUser()); + users.removeAll(localMember()); QVariantList userVariants; for (const auto &user : users) { if (connection()->isIgnored(user->id())) { @@ -276,7 +276,7 @@ QVariantList NeoChatRoom::getUsersTyping() const void NeoChatRoom::sendTypingNotification(bool isTyping) { - connection()->callApi(BackgroundRequest, localUser()->id(), id(), isTyping, 10000); + connection()->callApi(BackgroundRequest, localMember().id(), id(), isTyping, 10000); } const RoomEvent *NeoChatRoom::lastEvent() const @@ -374,13 +374,13 @@ bool NeoChatRoom::isEventHighlighted(const RoomEvent *e) const void NeoChatRoom::checkForHighlights(const Quotient::TimelineItem &ti) { - auto localUserId = localUser()->id(); - if (ti->senderId() == localUserId) { + auto localMemberId = localMember().id(); + if (ti->senderId() == localMemberId) { return; } if (auto *e = ti.viewAs()) { const auto &text = e->plainBody(); - if (text.contains(localUserId) || text.contains(safeMemberName(localUserId))) { + if (text.contains(localMemberId) || text.contains(safeMemberName(localMemberId))) { highlights.insert(e); } } @@ -449,7 +449,7 @@ QVariantMap NeoChatRoom::getUser(User *user) const } return QVariantMap{ - {QStringLiteral("isLocalUser"), user->id() == localUser()->id()}, + {QStringLiteral("isLocalUser"), user->id() == localMember().id()}, {QStringLiteral("id"), user->id()}, {QStringLiteral("displayName"), user->displayname(this)}, {QStringLiteral("escapedDisplayName"), htmlSafeMemberName(user->id())}, @@ -469,7 +469,7 @@ QString NeoChatRoom::avatarMediaId() const // Use the first (excluding self) user's avatar for direct chats const auto dcUsers = directChatUsers(); for (const auto u : dcUsers) { - if (u != localUser()) { + if (u != localMember()) { return u->avatarMediaId(this); } } @@ -637,7 +637,7 @@ void NeoChatRoom::toggleReaction(const QString &eventId, const QString &reaction continue; } - if (e->senderId() == localUser()->id()) { + if (e->senderId() == localMember().id()) { redactEventIds.push_back(e->id()); break; } @@ -666,7 +666,7 @@ bool NeoChatRoom::canSendEvent(const QString &eventType) const return false; } auto pl = plEvent->powerLevelForEvent(eventType); - auto currentPl = plEvent->powerLevelForUser(localUser()->id()); + auto currentPl = plEvent->powerLevelForUser(localMember().id()); return currentPl >= pl; } @@ -678,7 +678,7 @@ bool NeoChatRoom::canSendState(const QString &eventType) const return false; } auto pl = plEvent->powerLevelForState(eventType); - auto currentPl = plEvent->powerLevelForUser(localUser()->id()); + auto currentPl = plEvent->powerLevelForUser(localMember().id()); return currentPl >= pl; } @@ -856,7 +856,7 @@ void NeoChatRoom::setUrlPreviewEnabled(const bool &urlPreviewEnabled) * "type": "org.matrix.room.preview_urls", * } */ - connection()->callApi(localUser()->id(), + connection()->callApi(localMember().id(), id(), "org.matrix.room.preview_urls"_ls, QJsonObject{{"disable"_ls, !urlPreviewEnabled}}); @@ -1768,7 +1768,7 @@ void NeoChatRoom::editLastMessage() } // 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(); if (e->msgtype() != MessageEventType::Unknown) { diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index ace9fe52e..4d6d51cd5 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -213,7 +213,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room, if (!room) { return; } - auto connection = dynamic_cast(Controller::instance().accounts().get(room->localUser()->id())); + auto connection = dynamic_cast(Controller::instance().accounts().get(room->localMember().id())); Controller::instance().setActiveConnection(connection); RoomManager::instance().setConnection(connection); RoomManager::instance().resolveResource(room->id()); @@ -230,7 +230,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room, 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(); } @@ -286,7 +286,7 @@ void NotificationsManager::postInviteNotification(NeoChatRoom *rawRoom, const QS 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(); m_invitations.insert(room->id(), notification); diff --git a/src/pollhandler.cpp b/src/pollhandler.cpp index 463cbc5fb..30911e220 100644 --- a/src/pollhandler.cpp +++ b/src/pollhandler.cpp @@ -154,7 +154,7 @@ void PollHandler::sendPollAnswer(const QString &eventId, const QString &answerId return; } 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(); } if (ownAnswers.contains(answerId)) { @@ -169,7 +169,7 @@ void PollHandler::sendPollAnswer(const QString &eventId, const QString &answerId } 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); }