Skip to content

Commit 106bc4a

Browse files
pixlwavestefanceriu
authored andcommitted
Update the getting started docs.
1 parent 497a868 commit 106bc4a

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

docs/Getting Started.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ First we need to authenticate the user.
1616
```swift
1717
import MatrixRustSDK
1818

19-
// Create an authentication service to streamline the login process.
20-
let service = AuthenticationService(basePath: URL.applicationSupportDirectory.path(), passphrase: nil)
21-
22-
// Configure the service for a particular homeserver.
19+
// Create a client for a particular homeserver.
2320
// Note that we can pass a server name (the second part of a Matrix user ID) instead of the direct URL.
24-
// This allows the SDK to discover the homeserver's well-known configuration for OIDC and Sliding Sync support.
25-
try service.configureHomeserver(serverName: "matrix.org")
21+
// This allows the SDK to discover the homeserver's well-known configuration for Sliding Sync support.
22+
let client = try await ClientBuilder()
23+
.serverNameOrHomeserverUrl(serverNameOrUrl: "matrix.org")
24+
.sessionPaths(dataPath: URL.applicationSupportDirectory.path(percentEncoded: false),
25+
cachePath: URL.cachesDirectory.path(percentEncoded: false))
26+
.slidingSyncVersionBuilder(versionBuilder: .discoverProxy)
27+
.build()
2628

27-
// Login through the service which creates a client.
28-
let client = try service.login(username: "alice", password: "secret", initialDeviceName: nil, deviceId: nil)
29+
// Login using password authentication.
30+
try await client.login(username: "alice", password: "secret", initialDeviceName: nil, deviceId: nil)
2931

3032
let session = try client.session()
3133
// Store the session in the keychain.
@@ -38,43 +40,46 @@ Or, if the user has previously authenticated we can restore their session instea
3840
let session =
3941

4042
// Build a client for the homeserver.
41-
let client = try ClientBuilder()
42-
.basePath(path: URL.applicationSupportDirectory.path())
43+
let client = try await ClientBuilder()
44+
.sessionPaths(dataPath: URL.applicationSupportDirectory.path(percentEncoded: false),
45+
cachePath: URL.cachesDirectory.path(percentEncoded: false))
4346
.homeserverUrl(url: session.homeserverUrl)
4447
.build()
4548

4649
// Restore the client using the session.
47-
try client.restoreSession(session: session)
50+
try await client.restoreSession(session: session)
4851
```
4952

50-
Next we need to start the client and listen for updates. The following code does so using syncv2.
53+
Next we need to start the sync loop and listen for room updates.
5154

5255
```swift
53-
class ClientListener: ClientDelegate {
56+
class AllRoomsListener: RoomListEntriesListener {
5457
/// The user's list of rooms.
55-
var rooms = [Room]()
56-
57-
func didReceiveSyncUpdate() {
58-
// Update the user's room list on each sync response.
59-
self.rooms = client.rooms()
60-
}
58+
var rooms: [RoomListItem] = []
6159

62-
func didReceiveAuthError(isSoftLogout: Bool) {
63-
// Ask the user to reauthenticate.
64-
}
65-
66-
func didUpdateRestoreToken() {
67-
let session = try? client.session()
68-
// Update the session in the keychain.
60+
func onUpdate(roomEntriesUpdate: [MatrixRustSDK.RoomListEntriesUpdate]) {
61+
// Update the user's room list on each update.
62+
for update in roomEntriesUpdate {
63+
switch update {
64+
case .reset(values: let values):
65+
rooms = values
66+
default:
67+
break // Handle all the other cases accordingly.
68+
}
69+
}
6970
}
7071
}
7172

72-
// Listen to updates from the client.
73-
let listener = ClientListener()
74-
client.setDelegate(delegate: listener)
73+
// Create a sync service which controls the sync loop.
74+
let syncService = try await client.syncService().finish()
75+
76+
// Listen to room list updates.
77+
let listener = AllRoomsListener()
78+
let roomListService = syncService.roomListService()
79+
let handle = try await roomListService.allRooms().entries(listener: listener)
7580

76-
// Start the client using syncv2.
77-
client.startSync(timelineLimit: 20)
81+
// Start the sync loop.
82+
await syncService.start()
7883
```
7984

8085
Finally we can send messages into a room (with built in support for markdown).
@@ -84,6 +89,6 @@ Finally we can send messages into a room (with built in support for markdown).
8489
let message = messageEventContentFromMarkdown(md: "Hello, World!")
8590

8691
// Send the message content to the first room in the list.
87-
try listener.rooms.first?.send(msg: message, txnId: UUID().uuidString)
92+
_ = try await listener.rooms.first?.fullRoom().timeline().send(msg: message)
8893
```
8994

0 commit comments

Comments
 (0)