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. int sendMessageTimeoutSeconds = 60,
  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 sendTimelineEventTimeout = const Duration(minutes: 1),
  20. Future<SDNImageFileResizedResponse?> customImageResizer(
    1. SDNImageFileResizeArguments
    )?,
  21. bool shareKeysWithUnverifiedDevices = true,
  22. bool enableDehydratedDevices = false,
  23. bool receiptsPublicByDefault = true,
})

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,
  Set<String>? roomPreviewLastEvents,
  this.pinUnreadRooms = false,
  this.pinInvitedRooms = true,
  this.sendMessageTimeoutSeconds = 60,
  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,
  this.sendTimelineEventTimeout = const Duration(minutes: 1),
  this.customImageResizer,
  this.shareKeysWithUnverifiedDevices = true,
  this.enableDehydratedDevices = false,
  this.receiptsPublicByDefault = true,
})  : 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(), Duration(seconds: 35))) {
  if (logLevel != null) Logs().level = logLevel;
  importantStateEvents.addAll([
    EventTypes.RoomName,
    EventTypes.RoomAvatar,
    EventTypes.Message,
    EventTypes.Encrypted,
    EventTypes.Encryption,
    EventTypes.RoomCanonicalAlias,
    EventTypes.RoomTombstone,
    EventTypes.spaceChild,
    EventTypes.spaceParent,
    EventTypes.RoomCreate,
  ]);
  roomPreviewLastEvents.addAll([
    EventTypes.Message,
    EventTypes.Encrypted,
    EventTypes.Sticker,
  ]);

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