Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup/tweaks/docs/etc. across the board #694

Merged
merged 12 commits into from
Aug 9, 2023
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ PenaltyBreakComment: 45
#PenaltyBreakOpenParenthesis: 0 # ClangFormat 14
PenaltyBreakString: 200
#PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 40
PenaltyExcessCharacter: 30
PenaltyReturnTypeOnItsOwnLine: 200
#PenaltyIndentedWhitespace: 0
#PointerAlignment: Left
Expand Down
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ CheckOptions:
# value: 'false'
# - key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
# value: 'false'
# - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
# value: 'false'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 'true'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '1'
- key: google-readability-namespace-comments.ShortNamespaceLines
Expand Down
3 changes: 1 addition & 2 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "user.h"

// NB: since Qt 6, moc_connection.cpp needs Room and User fully defined
#include "moc_connection.cpp"
#include "moc_connection.cpp" // NOLINT(bugprone-suspicious-include)

#include "csapi/account-data.h"
#include "csapi/capabilities.h"
Expand All @@ -33,7 +33,6 @@
#include "jobs/downloadfilejob.h"
#include "jobs/mediathumbnailjob.h"
#include "jobs/syncjob.h"
#include <variant>

#ifdef Quotient_E2EE_ENABLED
# include "connectionencryptiondata_p.h"
Expand Down
8 changes: 4 additions & 4 deletions Quotient/connectionencryptiondata_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void ConnectionEncryptionData::consumeToDeviceEvents(Events&& toDeviceEvents)
if (!toDeviceEvents.empty()) {
qCDebug(E2EE) << "Consuming" << toDeviceEvents.size()
<< "to-device events";
for (auto&& tdEvt : toDeviceEvents) {
for (auto&& tdEvt : std::move(toDeviceEvents)) {
if (processIfVerificationEvent(*tdEvt, false))
continue;
if (auto&& event = eventCast<EncryptedEvent>(std::move(tdEvt))) {
Expand Down Expand Up @@ -350,7 +350,8 @@ void ConnectionEncryptionData::handleEncryptedToDeviceEvent(
{
const auto [decryptedEvent, olmSessionId] = sessionDecryptMessage(event);
if (!decryptedEvent) {
qCWarning(E2EE) << "Failed to decrypt event" << event.id();
qCWarning(E2EE) << "Failed to decrypt to-device event from device"
<< event.deviceId();
return;
}

Expand Down Expand Up @@ -573,8 +574,7 @@ std::pair<QByteArray, QByteArray> ConnectionEncryptionData::sessionDecryptMessag
auto newSessionResult =
olmAccount.createInboundSessionFrom(senderKey, message);
if (!newSessionResult) {
qCWarning(E2EE) << "Failed to create inbound session for" << senderKey
<< "with error" << newSessionResult.error();
qCWarning(E2EE) << "Failed to create inbound session for" << senderKey;
return {};
}
auto&& newSession = std::move(*newSessionResult);
Expand Down
4 changes: 2 additions & 2 deletions Quotient/e2ee/qolmaccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ IdentityKeys QOlmAccount::identityKeys() const
qPrintable("Failed to get "_ls % accountId() % " identity keys"_ls));
}
const auto key = QJsonDocument::fromJson(keyBuffer).object();
return IdentityKeys{ key.value(QStringLiteral("curve25519")).toString(),
key.value(QStringLiteral("ed25519")).toString() };
return { key.value(QStringLiteral("curve25519")).toString(),
key.value(QStringLiteral("ed25519")).toString() };
}

QByteArray QOlmAccount::sign(const QByteArray &message) const
Expand Down
2 changes: 1 addition & 1 deletion Quotient/eventitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ void PendingEventItem::setFileUploaded(const FileSourceInfo& uploadedFileData)

// Not exactly sure why but this helps with the linker not finding
// Quotient::EventStatus::staticMetaObject when building Quaternion
#include "moc_eventitem.cpp"
#include "moc_eventitem.cpp" // NOLINT(bugprone-suspicious-include)
13 changes: 6 additions & 7 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "user.h"

// NB: since Qt 6, moc_room.cpp needs User fully defined
#include "moc_room.cpp"
#include "moc_room.cpp" // NOLINT(bugprone-suspicious-include)

#include "csapi/account-data.h"
#include "csapi/banning.h"
Expand Down Expand Up @@ -611,7 +611,7 @@ QStringList Room::altAliases() const

QString Room::canonicalAlias() const
{
return currentState().queryOr(&RoomCanonicalAliasEvent::alias, QString());
return currentState().content<RoomCanonicalAliasEvent>().canonicalAlias;
}

QString Room::displayName() const { return d->displayname; }
Expand All @@ -623,8 +623,7 @@ QStringList Room::pinnedEventIds() const {
QVector<const Quotient::RoomEvent*> Quotient::Room::pinnedEvents() const
{
QVector<const RoomEvent*> pinnedEvents;
const auto eventIds = pinnedEventIds();
for (const auto& evtId : eventIds)
for (const auto eventIds = pinnedEventIds(); const auto& evtId : eventIds)
if (const auto& it = findInTimeline(evtId); it != historyEdge())
pinnedEvents.append(it->event());

Expand All @@ -640,7 +639,7 @@ void Room::refreshDisplayName() { d->updateDisplayname(); }

QString Room::topic() const
{
return currentState().queryOr(&RoomTopicEvent::topic, QString());
return currentState().content<RoomTopicEvent>().value;
}

QString Room::avatarMediaId() const { return d->avatar.mediaId(); }
Expand Down Expand Up @@ -1398,7 +1397,7 @@ QUrl Room::makeMediaUrl(const QString& eventId, const QUrl& mxcUrl) const

QString safeFileName(QString rawName)
{
static auto safeFileNameRegex = QRegularExpression("[/\\<>|\"*?:]"_ls);
static auto safeFileNameRegex = QRegularExpression(R"([/\<>|"*?:])"_ls);
return rawName.replace(safeFileNameRegex, "_"_ls);
}

Expand Down Expand Up @@ -2735,7 +2734,7 @@ bool Room::Private::processRedaction(const RedactionEvent& redaction)
<< ti->id() << "already done, skipping";
return true;
}
if (const auto* messageEvent = ti.viewAs<RoomMessageEvent>())
if (ti->is<RoomMessageEvent>())
FileMetadataMap::remove(id, ti->id());

// Make a new event from the redacted JSON and put it in the timeline
Expand Down
17 changes: 8 additions & 9 deletions Quotient/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,19 @@ QString Quotient::cacheLocation(const QString& dirName)
const QString cachePath =
QStandardPaths::writableLocation(QStandardPaths::CacheLocation) % u'/'
% dirName % u'/';
QDir dir;
if (!dir.exists(cachePath))
dir.mkpath(cachePath);
if (const QDir dir(cachePath); !dir.exists())
dir.mkpath("."_ls);
return cachePath;
}

qreal Quotient::stringToHueF(const QString& s)
{
Q_ASSERT(!s.isEmpty());
QByteArray hash = QCryptographicHash::hash(s.toUtf8(),
QCryptographicHash::Sha1);
const auto hash =
QCryptographicHash::hash(s.toUtf8(), QCryptographicHash::Sha1);
QDataStream dataStream(hash.left(2));
dataStream.setByteOrder(QDataStream::LittleEndian);
quint16 hashValue;
quint16 hashValue = 0;
dataStream >> hashValue;
const auto hueF = qreal(hashValue) / std::numeric_limits<quint16>::max();
Q_ASSERT((0 <= hueF) && (hueF <= 1));
Expand All @@ -107,9 +106,9 @@ static const auto ServerPartRegEx = QStringLiteral(

QString Quotient::serverPart(const QString& mxId)
{
static QString re = "^[@!#$+].*?:("_ls // Localpart and colon
% ServerPartRegEx % ")$"_ls;
static QRegularExpression parser(
static const QString re("^[@!#$+].*?:("_ls // Localpart and colon
% ServerPartRegEx % ")$"_ls);
static const QRegularExpression parser(
re,
QRegularExpression::UseUnicodePropertiesOption); // Because Asian digits
Q_ASSERT(parser.isValid());
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ if you want to switch on all debug logs except `jobs` you can set
QT_LOGGING_RULES="quotient.*.debug=true;quotient.jobs.debug=false"
```

(Thanks to [@eang:matrix.org](https://matrix.to/#/@eang:matrix.org]) for
contributing the original libQuotient code for logging categories.)

You may also want to set `QT_MESSAGE_PATTERN` to make logs slightly more
informative (see https://doc.qt.io/qt-6/qtlogging.html#qSetMessagePattern
for the format description). To give an example, here's what one of the library
developers uses for `QT_MESSAGE_PATTERN`:
```
`%{time h:mm:ss.zzz}|%{category}|%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}|%{message}`
```
(the scary `%{if}`s are just encoding the logging level into its initial letter).

#### Cache format
In case of troubles with room state and caching it may be useful to switch
cache format from binary CBOR to plaintext JSON. To do that, set
Expand Down