Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: always use persistence in clients #115

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
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
Loading