Skip to main content
SDKsAndroid

User and profile

setUser, getUser, reset, updateUser, and logout on MotiSig.getInstance().

All APIs below are on MotiSig.getInstance() after MotiSig.initialize(...).

setUser(id, register?, completion?)

Registers the user with the MotiSig API (POST /users) with timezone (TimeZone.getDefault().id) and locale (Locale.getDefault().toLanguageTag()). Optional RegisterUserExtras can supply firstName, lastName, email, tags, and customAttributes on the same request (iOS / Expo parity).

  • If the server returns 409 Conflict, the SDK treats the user as already registered and continues.
  • On success (including the 409 path), the user id is persisted locally.
  • After the user id is set, the SDK upserts a push subscription (FCM token plus permission and customer-enabled flag) when an FCM token is available. See Push notifications.

setUser runs on the SDK's FIFOMutationQueue relative to other mutations; see Getting started. Optional completion receives Result<Unit> on the main thread.

getUser { result -> … }

Loads the current profile from GET /users/{id} (callback on the main thread). result is a failure if the SDK is not initialized or no user is set; on success getOrNull() is null only when the server responds 404.

reset()

Clears local configuration and storage without server logout. Use before initialize with new credentials. See Configuration.

updateUser(firstName?, lastName?, email?)

Sends PATCH /users/{id} with only the fields allowed by the client API (name, email, timezone, locale). Only non-null parameters are included; timezone and locale are refreshed from the current device values.

If no user is set, the method returns immediately without enqueueing any work.

logout()

  • If both a persisted user id and FCM token exist, the SDK enqueues remove push subscription (DELETE …/push-subscriptions) for that pair (captured before clearing storage).
  • Removes all notification listeners and clears the in-memory event buffer.
  • Clears local SDK storage (user id, FCM token).
  • Customer push preference (isNotificationEnabled) is persisted across logout.

Important: Other mutations already queued may still run afterward using user ids captured at enqueue time. The design intentionally avoids dropping in-flight work when logging out.

Mutation queue semantics

Every user-scoped HTTP call on the SDK goes through FIFOMutationQueue.enqueue { ... }. Each closure:

  1. Captures the current userId (and fcmToken where applicable) at the moment of enqueue.
  2. Looks up the HTTP client lazily; if MotiSig was reinitialized between enqueue and run, the closure uses the latest client.
  3. Logs and discards exceptions per call site (it never throws into the queue, so one failed request does not block subsequent ones).

This guarantees that the observable order of writes matches the order of method calls, even if the underlying HTTP requests complete out of order.