UNPKG

nativescript-matrix-sdk

Version:

Native Matrix SDK integration for NativeScript

295 lines (259 loc) 7.92 kB
/** * Type declarations for Matrix Android SDK * This covers the main classes from the Matrix Android SDK API * Docs: https://matrix-org.github.io/matrix-android-sdk2/ */ // Declare the global Android namespace declare const android: any; declare namespace org.matrix.android.sdk.api { class Matrix { constructor(context: any); static getInstance(context: any): Matrix; static initialize(context: any): void; authenticateWith(credentials: auth.data.Credentials): session.Session; getAuthenticationService(): auth.AuthenticationService; } namespace auth.data { class Credentials { userId: string; accessToken: string; deviceId: string; homeServer: string; } } namespace auth { class AuthenticationService { getWellKnown(): any; getLoginFlows(homeserverUrl: string, callback: any): void; login(params: LoginParams, callback: any): void; register(params: RegistrationParams, callback: any): void; getLoginWizard(): { getSsoUrl(redirectUrl: string, deviceId: string | null, providerId: string | null): string; }; } class LoginParams { static Builder: { new(): { login(username: string): any; password(password: string): any; deviceDisplayName(name: string): any; build(): LoginParams; } } } class RegistrationParams { static Builder: { new(): { username(username: string): any; password(password: string): any; initialDeviceDisplayName(name: string): any; build(): RegistrationParams; } } } } namespace session { interface Session { open(): void; getMyUserId(): string; getRoomSummaries(params: room.model.RoomSummaryQueryParams): any; getRoom(roomId: string): room.Room; getRoomService(): room.RoomService; getCryptoService(): crypto.CryptoService; getSyncService(): sync.SyncService; getSyncStatusService(): sync.SyncStatusService; signOut(params?: any): Promise<void>; getContentService(): content.ContentService; getContentAttachmentService(): content.ContentAttachmentService; } namespace sync { interface SyncService { addSyncStateListener(listener: SyncStateListener): void; removeSyncStateListener(listener: SyncStateListener): void; } interface SyncStateListener { onSyncStateUpdated(status: any): void; } interface SyncStatusService { addSyncStatusListener(listener: SyncStatusListener): void; removeSyncStatusListener(listener: SyncStatusListener): void; } namespace SyncStatusService { class Status { static INITIAL_SYNC: Status; static RUNNING: Status; static READY: Status; static ERROR: Status; } } interface SyncStatusListener { onSyncStatus(status: SyncStatusService.Status): void; } } namespace crypto { interface CryptoService { enableEncryptionInRoom(roomId: string): Promise<void>; isCryptoEnabled(): boolean; isRoomEncrypted(roomId: string): boolean; } } namespace room { interface Room { roomId: string; getTimelineService(): timeline.TimelineService; getMember(userId: string): any; getReactionService(): reaction.ReactionService; getRoomService(): RoomService; getRoomSummary(): model.RoomSummary; } interface RoomService { joinRoom(roomId: string): Promise<void>; leaveRoom(roomId: string): Promise<void>; addListener(listener: RoomListener): void; removeListener(listener: RoomListener): void; } interface RoomListener { onRoomUpdated(roomId: string): void; } namespace model { class RoomSummaryQueryParams { static Builder: new () => { build(): RoomSummaryQueryParams; }; } interface RoomSummary { roomId: string; displayName: string; topic: string; joinedMembersCount: number; latestPreviewableEvent: any; notificationCount: number; isEncrypted(): boolean; getRoomId(): string; } } namespace timeline { enum Direction { FORWARDS, BACKWARDS } class TimelineParams { static Builder: { new(): { limit(limit: number): any; buildAround(eventId: string | null): TimelineParams; } } } interface TimelineService { getTimelineEvent(eventId: string): TimelineEvent; getTimelineEventsFromId(eventId: string, count: number, direction: Direction): Promise<Array<TimelineEvent>>; getTimelineEvents(params: TimelineParams, direction: Direction, callback: any): void; sendTextMessage(text: string): Promise<string>; getTimelineEvents(): Array<TimelineEvent>; addListener(listener: TimelineListener): void; removeListener(listener: TimelineListener): void; } interface TimelineListener { onTimelineUpdated(snapshot: any): void; } interface TimelineEvent { eventId: string; root: any; isEncrypted(): boolean; getClearContent(): any; getClearType(): string; getSenderInfo(): any; } } namespace reaction { interface ReactionService { sendReaction(eventId: string, reaction: string): Promise<void>; undoReaction(eventId: string, reaction: string): Promise<void>; getAllReactionEvents(eventId: string): Array<any>; } } } namespace content { interface ContentService { downloadFile( contentUrl: string, destFile: java.io.File, mimeType: string, progressListener: any, downloadListener: any ): void; cancelDownload(contentUrl: string): void; cancelAllDownloads(): void; } interface ContentAttachmentService { uploadImageFile( fileUri: android.net.Uri, filename: string, roomId: string, callback: any ): void; uploadVideoFile( fileUri: android.net.Uri, filename: string, roomId: string, callback: any ): void; uploadAudioFile( fileUri: android.net.Uri, filename: string, roomId: string, callback: any ): void; uploadFile( fileUri: android.net.Uri, filename: string, mimeType: string, roomId: string, callback: any ): void; } } } } // Add Java/Android declarations declare namespace java { namespace io { class File { constructor(path: string); exists(): boolean; length(): number; mkdirs(): boolean; static createTempFile(prefix: string, suffix: string, directory: any): File; } class FileOutputStream { constructor(file: File); close(): void; } } } declare namespace android { namespace net { class Uri { static fromFile(file: java.io.File): Uri; } } namespace graphics { class BitmapFactory { static decodeFile(path: string): Bitmap; } class Bitmap { compress(format: any, quality: number, stream: java.io.FileOutputStream): boolean; } namespace Bitmap { class CompressFormat { static JPEG: any; static PNG: any; static WEBP: any; } } } } declare const global: { android: any; };