Skip to content

Commit

Permalink
Merge #738(kitsune): Last fixes before 0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Apr 14, 2024
2 parents 73d236f + 27249ee commit d1f5bb1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ QVector<Room*> Connection::allRooms() const
QVector<Room*> Connection::rooms(JoinStates joinStates) const
{
QVector<Room*> result;
for (auto* r: qAsConst(d->roomMap))
for (auto* r: std::as_const(d->roomMap))
if (joinStates.testFlag(r->joinState()))
result.push_back(r);
return result;
Expand Down Expand Up @@ -1229,7 +1229,7 @@ void Connection::setAccountData(const QString& type, const QJsonObject& content)
QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
{
QHash<QString, QVector<Room*>> result;
for (auto* r : qAsConst(d->roomMap)) {
for (auto* r : std::as_const(d->roomMap)) {
const auto& tagNames = r->tagNames();
for (const auto& tagName : tagNames)
result[tagName].push_back(r);
Expand All @@ -1244,7 +1244,7 @@ QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
QStringList Connection::tagNames() const
{
QStringList tags({ FavouriteTag });
for (auto* r : qAsConst(d->roomMap)) {
for (auto* r : std::as_const(d->roomMap)) {
const auto& tagNames = r->tagNames();
for (const auto& tag : tagNames)
if (tag != LowPriorityTag && !tags.contains(tag))
Expand Down
2 changes: 1 addition & 1 deletion Quotient/e2ee/qolmsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class QUOTIENT_API QOlmSession

//! Decrypts a message using this session. Decoding is lossy, meaning if
//! the decrypted plaintext contains invalid UTF-8 symbols, they will
//! be returned as `U+FFFD` (�).
//! be returned as `U+FFFD`.
QOlmExpected<QByteArray> decrypt(const QOlmMessage &message) const;

//! Get a base64-encoded identifier for this session.
Expand Down
18 changes: 12 additions & 6 deletions Quotient/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ class {
public:
void addBaseUrl(const QString& accountId, const QUrl& baseUrl)
{
QWriteLocker{ &namLock }, baseUrls.insert(accountId, baseUrl);
const QWriteLocker _(&namLock);
baseUrls.insert(accountId, baseUrl);
}
void dropBaseUrl(const QString& accountId)
{
QWriteLocker{ &namLock }, baseUrls.remove(accountId);
const QWriteLocker _(&namLock);
baseUrls.remove(accountId);
}
QUrl getBaseUrl(const QString& accountId) const
{
return QReadLocker{ &namLock }, baseUrls.value(accountId);
const QReadLocker _(&namLock);
return baseUrls.value(accountId);
}
void addIgnoredSslError(const QSslError& error)
{
QWriteLocker{ &namLock }, ignoredSslErrors.push_back(error);
const QWriteLocker _(&namLock);
ignoredSslErrors.push_back(error);
}
void clearIgnoredSslErrors()
{
QWriteLocker{ &namLock }, ignoredSslErrors.clear();
const QWriteLocker _(&namLock);
ignoredSslErrors.clear();
}
QList<QSslError> getIgnoredSslErrors() const
{
return QReadLocker{ &namLock }, ignoredSslErrors;
const QReadLocker _(&namLock);
return ignoredSslErrors;
}

private:
Expand Down
22 changes: 12 additions & 10 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Q_DECL_HIDDEN Room::Private {

addInboundGroupSession(currentOutboundMegolmSession->sessionId(),
currentOutboundMegolmSession->sessionKey(),
q->localUser()->id(), QByteArrayLiteral("SELF"));
q->localMember().id(), QByteArrayLiteral("SELF"));
}

QMultiHash<QString, QString> getDevicesWithoutKey() const
Expand Down Expand Up @@ -670,8 +670,10 @@ QImage Room::avatar(int width, int height)
// Use the first (excluding self) user's avatar for direct chats
const auto dcUsers = directChatUsers();
for (auto* u : dcUsers)
if (u != localUser())
return u->avatar(width, height, this, [this] { emit avatarChanged(); });
QT_IGNORE_DEPRECATIONS(
if (u != localUser())
return u->avatar(width, height, this, [this] { emit avatarChanged(); });
)

return {};
}
Expand Down Expand Up @@ -1026,7 +1028,7 @@ void Room::setReadReceipt(const QString& atEventId)
QString::fromUtf8(QUrl::toPercentEncoding(atEventId)));
d->postprocessChanges(changes);
} else
qCDebug(EPHEMERAL) << "The new read receipt for" << localUser()->id()
qCDebug(EPHEMERAL) << "The new read receipt for" << localMember().id()
<< "in" << objectName()
<< "is at or behind the old one, skipping";
}
Expand Down Expand Up @@ -1070,7 +1072,7 @@ bool Room::canSwitchVersions() const

if (const auto* plEvt = currentState().get<RoomPowerLevelsEvent>()) {
const auto currentUserLevel =
plEvt->powerLevelForUser(localUser()->id());
plEvt->powerLevelForUser(localMember().id());
const auto tombstonePowerLevel =
plEvt->powerLevelForState("m.room.tombstone"_ls);
return currentUserLevel >= tombstonePowerLevel;
Expand All @@ -1087,7 +1089,7 @@ bool Room::isEventNotable(const TimelineItem &ti) const
|| is<RoomAvatarEvent>(evt) || is<RoomTombstoneEvent>(evt)
|| (rme && rme->msgtype() != MessageEventType::Notice
&& rme->replacedEvent().isEmpty()))
&& evt.senderId() != localUser()->id();
&& evt.senderId() != localMember().id();
}

Notification Room::notificationFor(const TimelineItem &ti) const
Expand Down Expand Up @@ -1297,7 +1299,7 @@ ReadReceipt Room::lastReadReceipt(const QString& userId) const

ReadReceipt Room::lastLocalReadReceipt() const
{
return d->lastReadReceipts.value(localUser()->id());
return d->lastReadReceipts.value(localMember().id());
}

Room::rev_iter_t Room::localReadReceiptMarker() const
Expand Down Expand Up @@ -1403,7 +1405,7 @@ void Room::addTag(const QString& name, const TagRecord& record)
emit tagsAboutToChange();
d->tags.insert(checkRes.second, record);
emit tagsChanged();
connection()->callApi<SetRoomTagJob>(localUser()->id(), id(),
connection()->callApi<SetRoomTagJob>(localMember().id(), id(),
checkRes.second, record.order);
}

Expand All @@ -1418,7 +1420,7 @@ void Room::removeTag(const QString& name)
emit tagsAboutToChange();
d->tags.remove(name);
emit tagsChanged();
connection()->callApi<DeleteRoomTagJob>(localUser()->id(), id(), name);
connection()->callApi<DeleteRoomTagJob>(localMember().id(), id(), name);
} else if (!name.startsWith("u."_ls))
removeTag("u."_ls + name);
else
Expand All @@ -1440,7 +1442,7 @@ void Room::setTags(TagsMap newTags, ActionScope applyOn)

d->setTags(std::move(newTags));
connection()->callApi<SetAccountDataPerRoomJob>(
localUser()->id(), id(), TagEvent::TypeId,
localMember().id(), id(), TagEvent::TypeId,
Quotient::toJson(TagEvent::content_type { d->tags }));

if (propagate) {
Expand Down
8 changes: 4 additions & 4 deletions Quotient/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ void User::removeAvatar()

void User::requestDirectChat() { connection()->requestDirectChat(this); }

void User::ignore() { connection()->addToIgnoredUsers(this); }
void User::ignore() { connection()->addToIgnoredUsers(d->id); }

void User::unmarkIgnore() { connection()->removeFromIgnoredUsers(this); }
void User::unmarkIgnore() { connection()->removeFromIgnoredUsers(d->id); }

bool User::isIgnored() const { return connection()->isIgnored(this); }

Expand Down Expand Up @@ -200,12 +200,12 @@ QImage User::avatar(int width, int height, const Room* room,

QString User::avatarMediaId(const Room* room) const
{
return avatarObject(room).mediaId();
QT_IGNORE_DEPRECATIONS(return avatarObject(room).mediaId();)
}

QUrl User::avatarUrl(const Room* room) const
{
return avatarObject(room).url();
QT_IGNORE_DEPRECATIONS(return avatarObject(room).url();)
}

qreal User::hueF() const { return d->hueF; }
43 changes: 25 additions & 18 deletions quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,26 @@ struct DownloadRunner {

using result_type = QNetworkReply::NetworkError;

QNetworkReply::NetworkError operator()(int) const
void runRequest(QScopedPointer<QNetworkReply, QScopedPointerDeleteLater>& r,
QEventLoop& el) const
{
QEventLoop el;
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply {
NetworkAccessManager::instance()->get(QNetworkRequest(url))
};
r.reset(NetworkAccessManager::instance()->get(QNetworkRequest(url)));
QObject::connect(
reply.data(), &QNetworkReply::finished, &el, [&el] { el.exit(); },
r.data(), &QNetworkReply::finished, &el,
[this, &r, &el] {
if (r->error() != QNetworkReply::NoError)
runRequest(r, el);
else
el.exit();
},
Qt::QueuedConnection);
}

QNetworkReply::NetworkError operator()(int) const
{
thread_local QEventLoop el;
thread_local QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply{};
runRequest(reply, el);
el.exec();
return reply->error();
}
Expand Down Expand Up @@ -929,19 +940,15 @@ void TestManager::conclude()
auto txnId = room->postHtmlText(plainReport, htmlReport);
// Now just wait until all the pending events reach the server
connectUntil(room, &Room::messageSent, this,
[this, txnId, room, plainReport] (const QString& sentTxnId) {
if (sentTxnId != txnId)
return false;
[this, txnId, room, plainReport] {
const auto& pendingEvents = room->pendingEvents();
if (auto c = std::count_if(pendingEvents.cbegin(),
pendingEvents.cend(),
[](const PendingEventItem& pe) {
return pe.deliveryStatus()
< EventStatus::ReachedServer;
});
c > 0) {
clog << "Events to reach the server: " << c
<< ", not leaving yet" << endl;
if (auto stillFlyingCount = std::count_if(pendingEvents.cbegin(), pendingEvents.cend(),
[](const PendingEventItem& pe) {
return pe.deliveryStatus()
< EventStatus::ReachedServer;
});
stillFlyingCount > 0) {
clog << "Events to reach the server: " << stillFlyingCount << ", not leaving yet\n";
return false;
}

Expand Down

0 comments on commit d1f5bb1

Please sign in to comment.