Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "events/encryptionevent.h"
#include "jobs/downloadfilejob.h"
#include "jobs/mediathumbnailjob.h"
#include "events/presenceevent.h"

// moc needs fully defined deps, see https://www.qt.io/blog/whats-new-in-qmetatype-qvariant
#include "moc_connection.cpp" // NOLINT(bugprone-suspicious-include)
Expand Down Expand Up @@ -637,7 +638,26 @@ void Connection::Private::consumeAccountData(Events&& accountDataEvents)

void Connection::Private::consumePresenceData(Events&& presenceData)
{
// To be implemented
for (const auto &event : presenceData) {
auto presenceEvent = eventCast<const PresenceEvent>(event);
auto sender = presenceEvent->fullJson()[u"sender"_s].toString(); // TODO ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto sender = presenceEvent->fullJson()[u"sender"_s].toString(); // TODO ?
auto sender = presenceEvent->senderId();

Calling it senderId() to align with RoomEvent.

if (presenceEvent->currentlyActive()) {
forcePresentUsers += sender;
} else {
forcePresentUsers.removeAll(sender);
}
if (presenceEvent->presence() == u"online") {
presentUsers += sender;
} else {
presentUsers.removeAll(sender);
}
}
Q_EMIT q->presenceChanged();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Q_EMIT q->presenceChanged();
emit q->presenceChanged();

}

bool Connection::isUserPresent(const QString &userId) const
{
return d->forcePresentUsers.contains(userId) || d->presentUsers.contains(userId);
}

void Connection::Private::consumeToDeviceEvents(Events&& toDeviceEvents)
Expand Down
4 changes: 4 additions & 0 deletions Quotient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ public Q_SLOTS:
static Connection* makeMockConnection(const QString& mxId,
bool enableEncryption = true);

Q_INVOKABLE bool isUserPresent(const QString &userId) const;

Q_SIGNALS:
//! \brief Initial server resolution has failed
//!
Expand Down Expand Up @@ -983,6 +985,8 @@ public Q_SLOTS:
//! This does not mean that the server was reached, a sync was performed, or the state cache was loaded.
void ready();

void presenceChanged();

friend class ::TestCrossSigning;
protected:
//! Access the underlying ConnectionData class
Expand Down
2 changes: 2 additions & 0 deletions Quotient/connection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Q_DECL_HIDDEN Quotient::Connection::Private {
std::unordered_map<QString, EventPtr> accountData;
QMetaObject::Connection syncLoopConnection {};
int syncTimeout = -1;
QStringList forcePresentUsers;
QStringList presentUsers;

GetCapabilitiesJob::Capabilities capabilities{};

Expand Down
25 changes: 25 additions & 0 deletions Quotient/events/presenceevent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2025 Tobias Fella <[email protected]>

#pragma once

#include "event.h"

namespace Quotient
{

class QUOTIENT_API PresenceEvent : public Quotient::Event {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class QUOTIENT_API PresenceEvent : public Quotient::Event {
class QUOTIENT_API PresenceEvent : public Event {

public:
QUO_EVENT(PresenceEvent, "m.presence")

using Event::Event;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QString senderId() const { return fullJson()[SenderKey].toString(); }

QUO_CONTENT_GETTER(QString, avatarUrl)
QUO_CONTENT_GETTER(bool, currentlyActive)
QUO_CONTENT_GETTER(QString, displayName)
QUO_CONTENT_GETTER(qint64, lastActiveTime)
QUO_CONTENT_GETTER(QString, presence)
QUO_CONTENT_GETTER(QString, statusMsg)
};

}