Skip to content

Commit

Permalink
Merge pull request #115 from matrix-org/kegan/default-persistence
Browse files Browse the repository at this point in the history
rust: always use persistence in clients
  • Loading branch information
kegsay committed Jul 9, 2024
2 parents 3aabfa8 + ead3a38 commit d48d6ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 4 additions & 2 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ type ClientCreationOpts struct {
// Required. The password for this account.
Password string

// Optional. If true, persistent storage will be used for the same user|device ID.
PersistentStorage bool
// Required for rust clients. The URL of the sliding sync proxy.
SlidingSyncURL string
// Optional. Set this to login with this device ID.
DeviceID string

// A hint to the client implementation that persistent storage is required. Clients may ignore
// this flag and always use persistence.
PersistentStorage bool

// Rust only. If set, enables the cross process refresh lock on the FFI client with the process name provided.
EnableCrossProcessRefreshLockProcessName string
// Rust only. If set with EnableCrossProcessRefreshLockProcessName=ProcessNameNSE, the client will be seeded
Expand Down
25 changes: 10 additions & 15 deletions internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,21 @@ func NewRustClient(t ct.TestLike, opts api.ClientCreationOpts) (api.Client, erro
clientSessionDelegate = NewMemoryClientSessionDelegate()
ab = ab.EnableCrossProcessRefreshLock(opts.EnableCrossProcessRefreshLockProcessName, clientSessionDelegate)
}
var username string
if opts.PersistentStorage {
// @alice:hs1, FOOBAR => alice_hs1_FOOBAR
username = strings.Replace(opts.UserID[1:], ":", "_", -1) + "_" + opts.DeviceID
ab = ab.SessionPath("rust_storage/" + username).Username(username)
}
// @alice:hs1, FOOBAR => alice_hs1_FOOBAR
username := strings.Replace(opts.UserID[1:], ":", "_", -1) + "_" + opts.DeviceID
ab = ab.SessionPath("rust_storage/" + username).Username(username)
client, err := ab.Build()
if err != nil {
return nil, fmt.Errorf("ClientBuilder.Build failed: %s", err)
}
c := &RustClient{
userID: opts.UserID,
FFIClient: client,
roomsListener: NewRoomsListener(),
rooms: make(map[string]*RustRoomInfo),
roomsMu: &sync.RWMutex{},
opts: opts,
}
if opts.PersistentStorage {
c.persistentStoragePath = "./rust_storage/" + username
userID: opts.UserID,
FFIClient: client,
roomsListener: NewRoomsListener(),
rooms: make(map[string]*RustRoomInfo),
roomsMu: &sync.RWMutex{},
opts: opts,
persistentStoragePath: "./rust_storage/" + username,
}
if opts.AccessToken != "" { // restore the session
session := matrix_sdk_ffi.Session{
Expand Down

0 comments on commit d48d6ba

Please sign in to comment.