Client constructor
- String clientName, {
- required DatabaseApi database,
- FutureOr<
DatabaseApi> legacyDatabaseBuilder()?, - Set<
KeyVerificationMethod> ? verificationMethods, - Client? httpClient,
- Set<
String> ? importantStateEvents, - Set<
String> ? roomPreviewLastEvents, - bool pinUnreadRooms = false,
- bool pinInvitedRooms = true,
- @Deprecated('Use [sendTimelineEventTimeout] instead.') int? sendMessageTimeoutSeconds,
- bool requestHistoryOnLimitedTimeline = false,
- Set<
String> ? supportedLoginTypes, - bool mxidLocalPartFallback = true,
- bool formatLocalpart = true,
- NativeImplementations nativeImplementations = NativeImplementations.dummy,
- Level? logLevel,
- Filter? syncFilter,
- Duration defaultNetworkRequestTimeout = const Duration(seconds: 35),
- Duration sendTimelineEventTimeout = const Duration(minutes: 1),
- Future<
MatrixImageFileResizedResponse?> customImageResizer()?, - Future<
MatrixVideoThumbnailResponse?> customVideoThumbnailGenerator()?, - bool enableDehydratedDevices = false,
- bool receiptsPublicByDefault = true,
- Future<
void> onSoftLogout(- Client client
- @Deprecated('Use `customRefreshTokenLifetime` in `Client.refreshAccessToken() directly.') Duration? customRefreshTokenLifetime,
- Duration typingIndicatorTimeout = const Duration(seconds: 30),
- bool convertLinebreaksInFormatting = true,
- bool enableLatexMarkdown = true,
- String dehydratedDeviceDisplayName = 'Dehydrated Device',
- RoomSorter? customRoomSorter,
- MatrixContentScannerConfig? contentScannerConfig,
- bool autoRequestProfileForMissingUsers = true,
- bool getDisplayNameAndAvatarFromPrevContent = 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 and customVideoThumbnailGenerator to your own
implementations for a more advanced and faster image resizing experience
and for generating video thumbnails, which the SDK can not do itself.
Set enableDehydratedDevices to enable experimental support for enabling MSC3814 dehydrated devices.
Implementation
Client(
this.clientName, {
required DatabaseApi database,
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,
this.nativeImplementations = NativeImplementations.dummy,
Level? logLevel,
Filter? syncFilter,
Duration defaultNetworkRequestTimeout = const Duration(seconds: 35),
this.sendTimelineEventTimeout = const Duration(minutes: 1),
this.customImageResizer,
this.customVideoThumbnailGenerator,
this.shareKeysWith = ShareKeysWith.crossVerifiedIfEnabled,
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,
@Deprecated(
'Use `customRefreshTokenLifetime` in `Client.refreshAccessToken() directly.',
)
this.customRefreshTokenLifetime,
this.typingIndicatorTimeout = const Duration(seconds: 30),
/// When sending a formatted message, converting linebreaks in markdown to
/// <br/> tags:
this.convertLinebreaksInFormatting = true,
this.enableLatexMarkdown = true,
this.dehydratedDeviceDisplayName = 'Dehydrated Device',
RoomSorter? customRoomSorter,
this.contentScannerConfig,
/// Whether the app automatically requests the profile for users which have
/// no filled out member state in a room. This is e.g. the case for left
/// or banned users.
this.autoRequestProfileForMissingUsers = true,
/// Whether the app should get DisplayName and Avatar also from the
/// previous content of a member state event.
this.getDisplayNameAndAvatarFromPrevContent = true,
}) : _database = database,
syncFilter =
syncFilter ??
Filter(room: RoomFilter(state: StateFilter(lazyLoadMembers: true))),
importantStateEvents = importantStateEvents ??= {},
roomPreviewLastEvents = roomPreviewLastEvents ??= {},
supportedLoginTypes =
supportedLoginTypes ?? {AuthenticationTypes.password},
verificationMethods = verificationMethods ?? <KeyVerificationMethod>{},
_customRoomSorter = customRoomSorter,
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();
}