-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.d.ts
268 lines (231 loc) · 8.48 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
declare interface MXCredentials {
user_id: string;
home_server: string;
access_token: string;
refresh_token: string | undefined;
device_id: string;
}
declare interface MXSessionAttributes {
user_id: string;
display_name: string;
avatar: string;
last_active: number;
status: string;
}
declare interface MXRoomMember {
membership: 'join' | 'invite' | 'leave' | 'ban' | 'kick';
userId: string;
name: string;
avatarUrl: string;
}
declare interface MXMessageEvent<ContentType = any, EventLiteral = string> {
event_type: EventLiteral;
event_id: string;
room_id: string;
sender_id: string;
/**
* The timestamp in ms since Epoch generated by the origin homeserver when it receives the event
* from the client.
*/
ts: number;
content: ContentType;
/**
* The message's transaction id. Will only be set for messages send on the user's device.
* See https://matrix.org/docs/spec/client_server/latest#id413
*/
txnId?: string;
}
declare interface MXRoomAttributes {
room_id: string;
name: string;
notification_count: number;
highlight_count: number;
is_direct: boolean;
last_message: MXMessageEvent;
isLeft: boolean;
members: MXRoomMember[];
}
declare interface PublicRoom {
id: string;
aliases: string;
name: string;
guestCanJoin: boolean;
numJoinedMembers: number;
}
declare interface MessagesFromRoom {
start: string;
end: string;
results: [string];
}
declare interface SuccessResponse {
success: string;
}
/**
* The key is the upload it, the value is the mxc uri.
*/
declare interface SuccessUploadResponse {
[key: string]: string
}
declare module 'react-native-matrix-sdk' {
import { EventSubscriptionVendor } from "react-native";
export interface MatrixSDKStatic extends EventSubscriptionVendor {
/**
* Call this to add additional custom event types that your client
* needs to support. This is for iOS only, android will emit the custom events
* with out the need for calling this.
* @param types
*/
setAdditionalEventTypes(types: string[]): void;
configure(host: string): void;
/**
* When you already obtained the credentials using {@see login}, instead of logging in on e.g. every app start,
* you can pass the credentials here. This will save you one login request.
*/
setCredentials(accessToken: string, deviceId: string, userId: string, homeServer: string, refreshToken?: string): void;
/**
* Logging the user in by username and password.
* @param username
* @param password
*/
login(username: string, password: string): Promise<MXCredentials>;
startSession(): Promise<MXSessionAttributes>;
/**
* Creates a new room with userIds
* @param userIds doesn't need to include the user's own ID
* @param isDirect shall be used when a room with only two participants is a 1-1 conversation
* @param isTrustedPrivateChat join_rules is set to invite. history_visibility is set to shared. All invitees are given the same power level as the room creator.
* @param name an optional name for the room
*/
createRoom(userIds: Array<string>, isDirect: boolean, isTrustedPrivateChat: boolean, name: string): Promise<MXRoomAttributes>;
/**
* Updates the name of a room
* @param roomId
* @param newName
*/
updateRoomName(roomId: string, newName: string);
joinRoom(roomId: string): Promise<MXRoomAttributes>;
/**
* roomId to leave
* @param roomId
*/
leaveRoom(roomId: string): Promise<void>;
/**
* Remove a certain user from a room
* @param roomId
* @param userId
*/
removeUserFromRoom(roomId: string, userId: string): Promise<void>;
/**
* Set a user of a room to admin (kick, ban, invite)
* @param roomId
* @param userId
* @param setAdmin
*/
changeUserPermission(roomId: string, userId: string, setAdmin: boolean): Promise<void>;
/**
* Invited a new user to a room
* @param roomId
* @param userId
*/
inviteUserToRoom(roomId: string, userId: string): Promise<void>;
/**
* Gets a single room (left rooms included).
* Will reject if room does not exist.
*/
getRoom(roomId: string): Promise<MXRoomAttributes>;
getInvitedRooms(): Promise<MXRoomAttributes[]>;
getPublicRooms(url: string): Promise<PublicRoom[]>;
getUnreadEventTypes(): Promise<string[]>;
getLastEventsForAllRooms(): Promise<MXMessageEvent[]>;
getJoinedRooms(): Promise<MXRoomAttributes[]>;
getLeftRooms(): Promise<MXRoomAttributes[]>;
listenToRoom(roomId: string): Promise<void>;
unlistenToRoom(roomId: string): Promise<void>;
listenToRoom(roomId: string): Promise<void>;
listen(): Promise<SuccessResponse>;
unlisten(): void;
/**
* This requests messages in direction backwards (past). You need to have a backwards listener in order
* to receive the messages.
* @param roomId
* @param perPage number of entries to return max
* @param initHistory Reset the back state so that future history requests start over from live.
* Must be called when opening a room if interested in history.
*/
backPaginate(roomId: string, perPage: number, initHistory: boolean): Promise<MXMessageEvent[]>;
/**
* Requests room history from server.
* @param roomId
* @param perPage
* @param initialLoad set to true on first request (initial request, newest messages), any additional calls with false to get further room history
*/
loadMessagesInRoom(roomId: string, perPage: number, initialLoad: boolean): Promise<MXMessageEvent[]>;
/**
* Returns true when back pagination is (still) possible.
* @param roomId
*/
canBackPaginate(roomId: string): Promise<boolean>;
searchMessagesInRoom(roomId: string, searchTerm: string, nextBatch: string, beforeLimit: string, afterLimit: string);
getMessages(roomId: string, from: string, direction: string, limit: number): Promise<MessagesFromRoom>;
/**
* Sends an m.room.message event to a room
* @param roomId
* @param messageType the message type (text, image, video, etc - see specifications)
* @param data
* @param txnId transaction id
*/
sendMessageToRoom(roomId: string, messageType: string, data: any, txnId?: string): Promise<SuccessResponse>;
/**
* Sends an event to a room
* @param roomId
* @param eventType
* @param data
* @param txnId transaction id
*/
sendEventToRoom(roomId: string, eventType: string, data: any, txnId?: string): Promise<SuccessResponse>;
sendReadReceipt(roomId: string, eventId: string): Promise<SuccessResponse>;
/**
* Marks the whole room as read.
* @param roomId
*/
markRoomAsRead(roomId: string): Promise<void>;
/**
* Adds a new pusher (service) to the user at the matrix homeserver. The matrix homeserver will
* use this pusher service to broadcast (push) notifications to the user's device (using FCM, APNS).
* @param appDisplayName
* @param appId
* @param pushServiceUrl
* @param token (FCM ID, or APNS device token)
*/
registerPushNotifications(appDisplayName: string, appId: string, pushServiceUrl: string, token: string): Promise<void>;
/**
* Updates the user's display name
* @param displayName new display name
*/
setUserDisplayName(displayName: string): Promise<void>;
/**
* Returns for a matrix content uri (mxc://...) the downloadable
* server url of the content. Currently doesn't support encryption.
* @param matrixContentUrl The matrix content url to resolve
*/
contentGetDownloadableUrl(matrixContentUrl: String): Promise<string>
/**
* Uploads content to the matrix content repository of the connected homeserver.
* @return {@see #SuccessUploadResponse}
* @param fileUri the absolute file path to the file to be uploaded
* @param fileName the file name of the file
* @param mimeType like "audio/aac", "image/jpeg"
* @param uploadId an upload id for reference.
*/
uploadContent(fileUri: string, fileName: string, mimeType: string, uploadId: string): Promise<SuccessUploadResponse>
/**
* Sends m.typing event into the specified room that the user is typing.
* @param roomId
* @param isTyping whether the user is typing or not
* @param timeout in ms
*/
sendTyping(roomId: string, isTyping: boolean, timeout: number): Promise<void>;
}
const MatrixSDK: MatrixSDKStatic;
export default MatrixSDK;
}