aboutsummaryrefslogtreecommitdiff
path: root/connection.h
diff options
context:
space:
mode:
Diffstat (limited to 'connection.h')
-rw-r--r--connection.h156
1 files changed, 123 insertions, 33 deletions
diff --git a/connection.h b/connection.h
index 2a107b43..256dbd5f 100644
--- a/connection.h
+++ b/connection.h
@@ -27,6 +27,8 @@
#include <functional>
+class QDnsLookup;
+
namespace QMatrixClient
{
class Room;
@@ -61,27 +63,6 @@ namespace QMatrixClient
QHash<QPair<QString, bool>, Room*> roomMap() const;
- // Old API that will be abolished any time soon. DO NOT USE.
-
- /** @deprecated Use callApi<PostMessageJob>() or Room::postMessage() instead */
- Q_INVOKABLE virtual void postMessage(Room* room, const QString& type,
- const QString& message) const;
- /** @deprecated Use callApi<PostReceiptJob>() or Room::postReceipt() instead */
- Q_INVOKABLE virtual PostReceiptJob* postReceipt(Room* room,
- RoomEvent* event) const;
- /** @deprecated Use callApi<JoinRoomJob>() instead */
- Q_INVOKABLE virtual JoinRoomJob* joinRoom(const QString& roomAlias);
- /** @deprecated Use callApi<LeaveRoomJob>() or Room::leaveRoom() instead */
- Q_INVOKABLE virtual void leaveRoom( Room* room );
- /** @deprecated User callApi<RoomMessagesJob>() or Room::getPreviousContent() instead */
- Q_INVOKABLE virtual RoomMessagesJob* getMessages(Room* room,
- const QString& from) const;
- /** @deprecated Use callApi<MediaThumbnailJob>() instead */
- virtual MediaThumbnailJob* getThumbnail(const QUrl& url,
- QSize requestedSize) const;
- /** @deprecated Use callApi<MediaThumbnailJob>() instead */
- MediaThumbnailJob* getThumbnail(const QUrl& url, int requestedWidth,
- int requestedHeight) const;
/** Sends /forget to the server and also deletes room locally.
* This method is in Connection, not in Room, since it's a
* room lifecycle operation, and Connection is an acting room manager.
@@ -96,11 +77,13 @@ namespace QMatrixClient
*/
ForgetRoomJob* forgetRoom(const QString& id);
+ // FIXME: Convert Q_INVOKABLEs to Q_PROPERTIES
+ // (breaks back-compatibility)
Q_INVOKABLE QUrl homeserver() const;
Q_INVOKABLE User* user(const QString& userId);
Q_INVOKABLE User* user();
Q_INVOKABLE QString userId() const;
- Q_INVOKABLE const QString& deviceId() const;
+ Q_INVOKABLE QString deviceId() const;
/** @deprecated Use accessToken() instead. */
Q_INVOKABLE QString token() const;
Q_INVOKABLE QString accessToken() const;
@@ -174,12 +157,17 @@ namespace QMatrixClient
}
public slots:
- void resolveServer(const QString& domain);
+ /** Set the homeserver base URL */
+ void setHomeserver(const QUrl& baseUrl);
+
+ /** Determine and set the homeserver from domain or MXID */
+ void resolveServer(const QString& mxidOrDomain);
+
void connectToServer(const QString& user, const QString& password,
- const QString& initialDeviceName,
- const QString& deviceId = {});
+ const QString& initialDeviceName,
+ const QString& deviceId = {});
void connectWithToken(const QString& userId, const QString& accessToken,
- const QString& deviceId);
+ const QString& deviceId);
/** @deprecated Use stopSync() instead */
void disconnectFromServer() { stopSync(); }
@@ -188,24 +176,109 @@ namespace QMatrixClient
void sync(int timeout = -1);
void stopSync();
+ virtual MediaThumbnailJob* getThumbnail(const QUrl& url,
+ QSize requestedSize) const;
+ MediaThumbnailJob* getThumbnail(const QUrl& url,
+ int requestedWidth,
+ int requestedHeight) const;
+
+ // Old API that will be abolished any time soon. DO NOT USE.
+
+ /** @deprecated Use callApi<PostMessageJob>() or Room::postMessage() instead */
+ virtual void postMessage(Room* room, const QString& type,
+ const QString& message) const;
+ /** @deprecated Use callApi<PostReceiptJob>() or Room::postReceipt() instead */
+ virtual PostReceiptJob* postReceipt(Room* room,
+ RoomEvent* event) const;
+ /** @deprecated Use callApi<JoinRoomJob>() instead */
+ virtual JoinRoomJob* joinRoom(const QString& roomAlias);
+ /** @deprecated Use callApi<LeaveRoomJob>() or Room::leaveRoom() instead */
+ virtual void leaveRoom( Room* room );
+ /** @deprecated User callApi<RoomMessagesJob>() or Room::getPreviousContent() instead */
+ virtual RoomMessagesJob* getMessages(Room* room,
+ const QString& from) const;
signals:
+ /**
+ * @deprecated
+ * This was a signal resulting from a successful resolveServer().
+ * Since Connection now provides setHomeserver(), the HS URL
+ * may change even without resolveServer() invocation. Use
+ * homeserverChanged() instead of resolved(). You can also use
+ * connectToServer and connectWithToken without the HS URL set in
+ * advance (i.e. without calling resolveServer), as they now trigger
+ * server name resolution from MXID if the server URL is not valid.
+ */
void resolved();
+ void resolveError(QString error);
+
+ void homeserverChanged(QUrl baseUrl);
+
void connected();
- void reconnected();
+ void reconnected(); //< Unused; use connected() instead
void loggedOut();
+ void loginError(QString error);
+ void networkError(size_t nextAttempt, int inMilliseconds);
void syncDone();
+ void syncError(QString error);
+
+ /**
+ * \group Signals emitted on room transitions
+ *
+ * Note: Rooms in Invite state are always stored separately from
+ * rooms in Join/Leave state, because of special treatment of
+ * invite_state in Matrix CS API (see The Spec on /sync for details).
+ * Therefore, objects below are: r - room in Join/Leave state;
+ * i - room in Invite state
+ *
+ * 1. none -> Invite: newRoom(r), invitedRoom(r,nullptr)
+ * 2. none -> Join: newRoom(r), joinedRoom(r,nullptr)
+ * 3. none -> Leave: newRoom(r), leftRoom(r,nullptr)
+ * 4. Invite -> Join:
+ * newRoom(r), joinedRoom(r,i), aboutToDeleteRoom(i)
+ * 4a. Leave and Invite -> Join:
+ * joinedRoom(r,i), aboutToDeleteRoom(i)
+ * 5. Invite -> Leave:
+ * newRoom(r), leftRoom(r,i), aboutToDeleteRoom(i)
+ * 5a. Leave and Invite -> Leave:
+ * leftRoom(r,i), aboutToDeleteRoom(i)
+ * 6. Join -> Leave: leftRoom(r)
+ * 7. Leave -> Invite: newRoom(i), invitedRoom(i,r)
+ * 8. Leave -> Join: joinedRoom(r)
+ * The following transitions are only possible via forgetRoom()
+ * so far; if a room gets forgotten externally, sync won't tell
+ * about it:
+ * 9. any -> none: as any -> Leave, then aboutToDeleteRoom(r)
+ */
+
+ /** A new room object has been created */
void newRoom(Room* room);
+
+ /** Invitation to a room received
+ *
+ * If the same room is in Left state, it's passed in prev.
+ */
void invitedRoom(Room* room, Room* prev);
+
+ /** A room has just been joined
+ *
+ * It's not the same as receiving a room in "join" section of sync
+ * response (rooms will be there even after joining). If this room
+ * was in Invite state before, the respective object is passed in
+ * prev (and it will be deleted shortly afterwards).
+ */
void joinedRoom(Room* room, Room* prev);
+
+ /** A room has just been left
+ *
+ * If this room has been in Invite state (as in case of rejecting
+ * an invitation), the respective object will be passed in prev
+ * (and will be deleted shortly afterwards).
+ */
void leftRoom(Room* room, Room* prev);
- void aboutToDeleteRoom(Room* room);
- void loginError(QString error);
- void networkError(size_t nextAttempt, int inMilliseconds);
- void resolveError(QString error);
- void syncError(QString error);
- //void jobError(BaseJob* job);
+ /** The room object is about to be deleted */
+ void aboutToDeleteRoom(Room* room);
void cacheStateChanged();
@@ -236,6 +309,23 @@ namespace QMatrixClient
class Private;
Private* d;
+ /**
+ * A single entry for functions that need to check whether the
+ * homeserver is valid before running. May either execute connectFn
+ * synchronously or asynchronously (if tryResolve is true and
+ * a DNS lookup is initiated); in case of errors, emits resolveError
+ * if the homeserver URL is not valid and cannot be resolved from
+ * userId.
+ *
+ * @param userId - fully-qualified MXID to resolve HS from
+ * @param connectFn - a function to execute once the HS URL is good
+ */
+ void checkAndConnect(const QString& userId,
+ std::function<void()> connectFn);
+ void doConnectToServer(const QString& user, const QString& password,
+ const QString& initialDeviceName,
+ const QString& deviceId = {});
+
static room_factory_t createRoom;
static user_factory_t createUser;
};