Compare commits
6 Commits
work/carl/
...
work/adapt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cc68d2658 | ||
|
|
f4b87caefe | ||
|
|
07a9497f4c | ||
|
|
35f1ace458 | ||
|
|
11dd0ee151 | ||
|
|
07e200c74f |
@@ -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));
|
||||
|
||||
@@ -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<const RoomMessageEvent>(&**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<const Quotient::EventContent::TextContent *>(event->content())->body;
|
||||
|
||||
@@ -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("<br>\n"), QStringLiteral(" "));
|
||||
displayName.replace(QStringLiteral("<br>"), 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
|
||||
|
||||
@@ -201,7 +201,7 @@ QList<ActionsModel::Action> actions{
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("<user> is banned from this room.", "%1 is banned from this room.", text));
|
||||
return QString();
|
||||
}
|
||||
if (room->localUser()->id() == text) {
|
||||
if (room->localMember().id() == text) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Positive, i18n("You are already in this room."));
|
||||
return QString();
|
||||
}
|
||||
@@ -430,11 +430,11 @@ QList<ActionsModel::Action> actions{
|
||||
if (!plEvent) {
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) {
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to ban users from this room."));
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
Q_EMIT room->showMessage(
|
||||
NeoChatRoom::Error,
|
||||
i18nc("You are not allowed to ban <username> from this room.", "You are not allowed to ban %1 from this room.", parts[0]));
|
||||
@@ -463,7 +463,7 @@ QList<ActionsModel::Action> actions{
|
||||
if (!plEvent) {
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) {
|
||||
if (plEvent->ban() > plEvent->powerLevelForUser(room->localMember().id())) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to unban users from this room."));
|
||||
return QString();
|
||||
}
|
||||
@@ -494,7 +494,7 @@ QList<ActionsModel::Action> actions{
|
||||
i18nc("'<text>' does not look like a matrix id.", "'%1' does not look like a matrix id.", parts[0]));
|
||||
return QString();
|
||||
}
|
||||
if (parts[0] == room->localUser()->id()) {
|
||||
if (parts[0] == room->localMember().id()) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You cannot kick yourself from the room."));
|
||||
return QString();
|
||||
}
|
||||
@@ -507,11 +507,11 @@ QList<ActionsModel::Action> actions{
|
||||
return QString();
|
||||
}
|
||||
auto kick = plEvent->kick();
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) < kick) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) < kick) {
|
||||
Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to kick users from this room."));
|
||||
return QString();
|
||||
}
|
||||
if (plEvent->powerLevelForUser(room->localUser()->id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
if (plEvent->powerLevelForUser(room->localMember().id()) <= plEvent->powerLevelForUser(parts[0])) {
|
||||
Q_EMIT room->showMessage(
|
||||
NeoChatRoom::Error,
|
||||
i18nc("You are not allowed to kick <username> from this room", "You are not allowed to kick %1 from this room.", parts[0]));
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,15 +101,17 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
||||
if (this->joinState() != JoinState::Invite) {
|
||||
return;
|
||||
}
|
||||
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localUser()->id());
|
||||
auto roomMemberEvent = currentState().get<RoomMemberEvent>(localMember().id());
|
||||
QImage avatar_image;
|
||||
if (roomMemberEvent && !user(roomMemberEvent->senderId())->avatarUrl(this).isEmpty()) {
|
||||
avatar_image = user(roomMemberEvent->senderId())->avatar(128, this);
|
||||
if (roomMemberEvent && !member(roomMemberEvent->senderId()).avatarUrl().isEmpty()) {
|
||||
// TODO: Fix acessing Avatar Image.
|
||||
// avatar_image = member(roomMemberEvent->senderId()).avatarMediaId();
|
||||
avatar_image = avatar(128);
|
||||
} else {
|
||||
qWarning() << "using this room's avatar";
|
||||
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);
|
||||
});
|
||||
connect(this, &Room::changed, this, [this] {
|
||||
Q_EMIT canEncryptRoomChanged();
|
||||
@@ -257,18 +259,18 @@ void NeoChatRoom::forget()
|
||||
|
||||
QVariantList NeoChatRoom::getUsersTyping() const
|
||||
{
|
||||
auto users = usersTyping();
|
||||
users.removeAll(localUser());
|
||||
auto users = membersTyping();
|
||||
users.removeAll(localMember());
|
||||
QVariantList userVariants;
|
||||
for (const auto &user : users) {
|
||||
if (connection()->isIgnored(user->id())) {
|
||||
if (connection()->isIgnored(user.id())) {
|
||||
continue;
|
||||
}
|
||||
userVariants.append(QVariantMap{
|
||||
{"id"_ls, user->id()},
|
||||
{"avatarMediaId"_ls, user->avatarMediaId(this)},
|
||||
{"displayName"_ls, user->displayname(this)},
|
||||
{"display"_ls, user->name()},
|
||||
{"id"_ls, user.id()},
|
||||
{"avatarMediaId"_ls, user.avatarMediaId()},
|
||||
{"displayName"_ls, user.displayName()},
|
||||
{"display"_ls, user.name()},
|
||||
});
|
||||
}
|
||||
return userVariants;
|
||||
@@ -276,7 +278,7 @@ QVariantList NeoChatRoom::getUsersTyping() const
|
||||
|
||||
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
|
||||
@@ -314,7 +316,7 @@ const RoomEvent *NeoChatRoom::lastEvent() const
|
||||
}
|
||||
}
|
||||
|
||||
if (connection()->isIgnored(user(event->senderId()))) {
|
||||
if (connection()->isIgnored(event->senderId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -374,13 +376,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<RoomMessageEvent>()) {
|
||||
const auto &text = e->plainBody();
|
||||
if (text.contains(localUserId) || text.contains(safeMemberName(localUserId))) {
|
||||
if (text.contains(localMemberId) || text.contains(member(localMemberId).htmlSafeDisplayName())) {
|
||||
highlights.insert(e);
|
||||
}
|
||||
}
|
||||
@@ -439,7 +441,8 @@ static const QVariantMap emptyUser = {
|
||||
|
||||
QVariantMap NeoChatRoom::getUser(const QString &userID) const
|
||||
{
|
||||
return getUser(user(userID));
|
||||
auto u = User(userID, connection());
|
||||
return getUser(&u);
|
||||
}
|
||||
|
||||
QVariantMap NeoChatRoom::getUser(User *user) const
|
||||
@@ -449,13 +452,13 @@ 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())},
|
||||
{QStringLiteral("displayName"), user->displayname()},
|
||||
{QStringLiteral("escapedDisplayName"), member(user->id()).htmlSafeDisplayName()},
|
||||
{QStringLiteral("avatarSource"), avatarForMember(user)},
|
||||
{QStringLiteral("avatarMediaId"), user->avatarMediaId(this)},
|
||||
{QStringLiteral("color"), Utils::getUserColor(user->hueF())},
|
||||
{QStringLiteral("avatarMediaId"), user->avatarMediaId()},
|
||||
{QStringLiteral("color"), member(user->id()).hueF()},
|
||||
{QStringLiteral("object"), QVariant::fromValue(user)},
|
||||
};
|
||||
}
|
||||
@@ -467,10 +470,10 @@ QString NeoChatRoom::avatarMediaId() const
|
||||
}
|
||||
|
||||
// Use the first (excluding self) user's avatar for direct chats
|
||||
const auto dcUsers = directChatUsers();
|
||||
const auto dcUsers = directChatMembers();
|
||||
for (const auto u : dcUsers) {
|
||||
if (u != localUser()) {
|
||||
return u->avatarMediaId(this);
|
||||
if (u != localMember()) {
|
||||
return u.avatarMediaId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,7 +640,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 +669,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 +681,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 +859,7 @@ void NeoChatRoom::setUrlPreviewEnabled(const bool &urlPreviewEnabled)
|
||||
* "type": "org.matrix.room.preview_urls",
|
||||
* }
|
||||
*/
|
||||
connection()->callApi<SetAccountDataPerRoomJob>(localUser()->id(),
|
||||
connection()->callApi<SetAccountDataPerRoomJob>(localMember().id(),
|
||||
id(),
|
||||
"org.matrix.room.preview_urls"_ls,
|
||||
QJsonObject{{"disable"_ls, !urlPreviewEnabled}});
|
||||
@@ -1768,7 +1771,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) {
|
||||
@@ -1933,16 +1936,16 @@ QByteArray NeoChatRoom::roomAcountDataJson(const QString &eventType)
|
||||
|
||||
QUrl NeoChatRoom::avatarForMember(Quotient::User *user) const
|
||||
{
|
||||
const auto &url = memberAvatarUrl(user->id());
|
||||
if (url.isEmpty() || url.scheme() != "mxc"_ls) {
|
||||
const auto &avatar = memberAvatar(user->id());
|
||||
if (avatar.url().isEmpty() || avatar.url().scheme() != "mxc"_ls) {
|
||||
return {};
|
||||
}
|
||||
auto avatar = connection()->makeMediaUrl(url);
|
||||
if (avatar.isValid() && avatar.scheme() == QStringLiteral("mxc")) {
|
||||
return avatar;
|
||||
} else {
|
||||
|
||||
auto localFile = connection()->makeMediaUrl(avatar.url());
|
||||
if (!localFile.isValid() || localFile.scheme() != QStringLiteral("mxc")) {
|
||||
return QUrl();
|
||||
}
|
||||
return localFile;
|
||||
}
|
||||
|
||||
const RoomEvent *NeoChatRoom::getReplyForEvent(const RoomEvent &event) const
|
||||
|
||||
@@ -213,7 +213,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
||||
if (!room) {
|
||||
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);
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user