Client constructor

Client(
  1. String clientName, {
  2. FutureOr<DatabaseApi> databaseBuilder(
    1. Client
    )?,
  3. FutureOr<DatabaseApi> legacyDatabaseBuilder(
    1. Client
    )?,
  4. Set<KeyVerificationMethod>? verificationMethods,
  5. Client? httpClient,
  6. Set<String>? importantStateEvents,
  7. Set<String>? roomPreviewLastEvents,
  8. bool pinUnreadRooms = false,
  9. bool pinInvitedRooms = true,
  10. @Deprecated('Use [sendTimelineEventTimeout] instead.') int? sendMessageTimeoutSeconds,
  11. bool requestHistoryOnLimitedTimeline = false,
  12. Set<String>? supportedLoginTypes,
  13. bool mxidLocalPartFallback = true,
  14. bool formatLocalpart = true,
  15. @Deprecated('Use [nativeImplementations] instead') ComputeCallback? compute,
  16. NativeImplementations nativeImplementations = NativeImplementations.dummy,
  17. Level? logLevel,
  18. Filter? syncFilter,
  19. Duration defaultNetworkRequestTimeout = const Duration(seconds: 35),
  20. Duration sendTimelineEventTimeout = const Duration(minutes: 1),
  21. Future<MatrixImageFileResizedResponse?> customImageResizer(
    1. MatrixImageFileResizeArguments
    )?,
  22. bool shareKeysWithUnverifiedDevices = true,
  23. bool enableDehydratedDevices = false,
  24. bool receiptsPublicByDefault = true,
  25. Future<void> onSoftLogout(
    1. Client client
    )?,
  26. Duration? customRefreshTokenLifetime,
})

Create a client clientName = unique identifier of this client databaseBuilder: A function that creates the database instance, that will be used. legacyDatabaseBuilder: Use this for your old database implementation to perform an automatic migration databaseDestroyer: A function that can be used to destroy a database instance, for example by deleting files from disk. verificationMethods: A set of all the verification methods this client can handle. Includes: KeyVerificationMethod.numbers: Compare numbers. Most basic, should be supported KeyVerificationMethod.emoji: Compare emojis importantStateEvents: A set of all the important state events to load when the client connects. To speed up performance only a set of state events is loaded on startup, those that are needed to display a room list. All the remaining state events are automatically post-loaded when opening the timeline of a room or manually by calling room.postLoad(). This set will always include the following state events: - m.room.name - m.room.avatar - m.room.message - m.room.encrypted - m.room.encryption - m.room.canonical_alias - m.room.tombstone - some m.room.member events, where needed roomPreviewLastEvents: The event types that should be used to calculate the last event in a room for the room list. Set requestHistoryOnLimitedTimeline to controll the automatic behaviour if the client receives a limited timeline flag for a room. If mxidLocalPartFallback is true, then the local part of the mxid will be shown if there is no other displayname available. If not then this will return "Unknown user". If formatLocalpart is true, then the localpart of an mxid will be formatted in the way, that all "_" characters are becomming white spaces and the first character of each word becomes uppercase. If your client supports more login types like login with token or SSO, then add this to supportedLoginTypes. Set a custom syncFilter if you like. By default the app will use lazy_load_members. Set nativeImplementations to NativeImplementationsIsolate in order to enable the SDK to compute some code in background. Set timelineEventTimeout to the preferred time the Client should retry sending events on connection problems or to Duration.zero to disable it. Set customImageResizer to your own implementation for a more advanced and faster image resizing experience. Set enableDehydratedDevices to enable experimental support for enabling MSC3814 dehydrated devices.

Implementation

Client(
  this.clientName, {
  this.databaseBuilder,
  this.legacyDatabaseBuilder,
  Set<KeyVerificationMethod>? verificationMethods,
  http.Client? httpClient,
  Set<String>? importantStateEvents,

  /// You probably don't want to add state events which are also
  /// in important state events to this list, or get ready to face
  /// only having one event of that particular type in preLoad because
  /// previewEvents are stored with stateKey '' not the actual state key
  /// of your state event
  Set<String>? roomPreviewLastEvents,
  this.pinUnreadRooms = false,
  this.pinInvitedRooms = true,
  @Deprecated('Use [sendTimelineEventTimeout] instead.')
  int? sendMessageTimeoutSeconds,
  this.requestHistoryOnLimitedTimeline = false,
  Set<String>? supportedLoginTypes,
  this.mxidLocalPartFallback = true,
  this.formatLocalpart = true,
  @Deprecated('Use [nativeImplementations] instead') this.compute,
  NativeImplementations nativeImplementations = NativeImplementations.dummy,
  Level? logLevel,
  Filter? syncFilter,
  Duration defaultNetworkRequestTimeout = const Duration(seconds: 35),
  this.sendTimelineEventTimeout = const Duration(minutes: 1),
  this.customImageResizer,
  this.shareKeysWithUnverifiedDevices = true,
  this.enableDehydratedDevices = false,
  this.receiptsPublicByDefault = true,

  /// Implement your https://spec.matrix.org/v1.9/client-server-api/#soft-logout
  /// logic here.
  /// Set this to `refreshAccessToken()` for the easiest way to handle the
  /// most common reason for soft logouts.
  /// You can also perform a new login here by passing the existing deviceId.
  this.onSoftLogout,

  /// Experimental feature which allows to send a custom refresh token
  /// lifetime to the server which overrides the default one. Needs server
  /// support.
  this.customRefreshTokenLifetime,
})  : syncFilter = syncFilter ??
          Filter(
            room: RoomFilter(
              state: StateFilter(lazyLoadMembers: true),
            ),
          ),
      importantStateEvents = importantStateEvents ??= {},
      roomPreviewLastEvents = roomPreviewLastEvents ??= {},
      supportedLoginTypes =
          supportedLoginTypes ?? {AuthenticationTypes.password},
      verificationMethods = verificationMethods ?? <KeyVerificationMethod>{},
      nativeImplementations = compute != null
          ? NativeImplementationsIsolate(compute)
          : nativeImplementations,
      super(
          httpClient: FixedTimeoutHttpClient(
              httpClient ?? http.Client(), defaultNetworkRequestTimeout)) {
  if (logLevel != null) Logs().level = logLevel;
  importantStateEvents.addAll([
    EventTypes.RoomName,
    EventTypes.RoomAvatar,
    EventTypes.Encryption,
    EventTypes.RoomCanonicalAlias,
    EventTypes.RoomTombstone,
    EventTypes.SpaceChild,
    EventTypes.SpaceParent,
    EventTypes.RoomCreate,
  ]);
  roomPreviewLastEvents.addAll([
    EventTypes.Message,
    EventTypes.Encrypted,
    EventTypes.Sticker,
    EventTypes.CallInvite,
    EventTypes.CallAnswer,
    EventTypes.CallReject,
    EventTypes.CallHangup,
    EventTypes.GroupCallMember,
  ]);

  // register all the default commands
  registerDefaultCommands();
}