aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 3ed71bb4..c4587f30 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -133,6 +133,11 @@ public:
!= "json";
bool lazyLoading = false;
+ /// \brief Stop resolving and login flows jobs, and clear login flows
+ ///
+ /// Prepares the class to set or resolve a new homeserver
+ void clearResolvingContext();
+
/** \brief Check the homeserver and resolve it if needed, before connecting
*
* A single entry for functions that need to check whether the homeserver
@@ -270,8 +275,7 @@ Connection::~Connection()
void Connection::resolveServer(const QString& mxid)
{
- if (isJobRunning(d->resolverJob))
- d->resolverJob->abandon();
+ d->clearResolvingContext();
auto maybeBaseUrl = QUrl::fromUserInput(serverPart(mxid));
maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http"
@@ -687,7 +691,7 @@ void Connection::Private::consumeAccountData(Events&& accountDataEvents)
DirectChatsMap remoteAdditions;
for (auto it = usersToDCs.begin(); it != usersToDCs.end(); ++it) {
- if (auto* u = q->user(it.key())) {
+ if (auto* const u = q->user(it.key())) {
if (!directChats.contains(u, it.value())
&& !dcLocalRemovals.contains(u, it.value())) {
Q_ASSERT(!directChatUsers.contains(it.value(), u));
@@ -920,6 +924,12 @@ Connection::createRoom(RoomVisibility visibility, const QString& alias,
const QJsonObject& creationContent)
{
invites.removeOne(userId()); // The creator is by definition in the room
+ for (const auto& i : invites)
+ if (!user(i)) {
+ qCWarning(MAIN) << "Won't create a room with malformed invitee ids";
+ return nullptr;
+ }
+
auto job = callApi<CreateRoomJob>(visibility == PublishRoom
? QStringLiteral("public")
: QStringLiteral("private"),
@@ -954,7 +964,7 @@ void Connection::requestDirectChat(User* u)
void Connection::doInDirectChat(const QString& userId,
const std::function<void(Room*)>& operation)
{
- if (auto* u = user(userId))
+ if (auto* const u = user(userId))
doInDirectChat(u, operation);
else
qCCritical(MAIN)
@@ -1530,13 +1540,19 @@ QByteArray Connection::generateTxnId() const
return d->data->generateTxnId();
}
+void Connection::Private::clearResolvingContext()
+{
+ if (isJobRunning(resolverJob))
+ resolverJob->abandon();
+ if (isJobRunning(loginFlowsJob))
+ loginFlowsJob->abandon();
+ loginFlows.clear();
+
+}
+
void Connection::setHomeserver(const QUrl& url)
{
- if (isJobRunning(d->resolverJob))
- d->resolverJob->abandon();
- if (isJobRunning(d->loginFlowsJob))
- d->loginFlowsJob->abandon();
- d->loginFlows.clear();
+ d->clearResolvingContext();
if (homeserver() != url) {
d->data->setBaseUrl(url);