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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
import { RoomMember } from "./room-member";
import { EventType } from "../@types/event";
import { MatrixEvent } from "./event";
import { MatrixClient } from "../client";
import { GuestAccess, HistoryVisibility, JoinRule } from "../@types/partials";
import { TypedEventEmitter } from "./typed-event-emitter";
import { Beacon, BeaconEvent, BeaconEventHandlerMap, BeaconIdentifier } from "./beacon";
import { TypedReEmitter } from "../ReEmitter";
export interface IMarkerFoundOptions {
/** Whether the timeline was empty before the marker event arrived in the
* room. This could be happen in a variety of cases:
* 1. From the initial sync
* 2. It's the first state we're seeing after joining the room
* 3. Or whether it's coming from `syncFromCache`
*
* A marker event refers to `UNSTABLE_MSC2716_MARKER` and indicates that
* history was imported somewhere back in time. It specifically points to an
* MSC2716 insertion event where the history was imported at. Marker events
* are sent as state events so they are easily discoverable by clients and
* homeservers and don't get lost in timeline gaps.
*/
timelineWasEmpty?: boolean;
}
declare enum OobStatus {
NotStarted = 0,
InProgress = 1,
Finished = 2
}
export interface IPowerLevelsContent {
users?: Record<string, number>;
events?: Record<string, number>;
users_default?: number;
events_default?: number;
state_default?: number;
ban?: number;
kick?: number;
redact?: number;
}
export declare enum RoomStateEvent {
Events = "RoomState.events",
Members = "RoomState.members",
NewMember = "RoomState.newMember",
Update = "RoomState.update",
BeaconLiveness = "RoomState.BeaconLiveness",
Marker = "RoomState.Marker"
}
export type RoomStateEventHandlerMap = {
/**
* Fires whenever the event dictionary in room state is updated.
* @param event - The matrix event which caused this event to fire.
* @param state - The room state whose RoomState.events dictionary
* was updated.
* @param prevEvent - The event being replaced by the new state, if
* known. Note that this can differ from `getPrevContent()` on the new state event
* as this is the store's view of the last state, not the previous state provided
* by the server.
* @example
* ```
* matrixClient.on("RoomState.events", function(event, state, prevEvent){
* var newStateEvent = event;
* });
* ```
*/
[RoomStateEvent.Events]: (event: MatrixEvent, state: RoomState, lastStateEvent: MatrixEvent | null) => void;
/**
* Fires whenever a member in the members dictionary is updated in any way.
* @param event - The matrix event which caused this event to fire.
* @param state - The room state whose RoomState.members dictionary
* was updated.
* @param member - The room member that was updated.
* @example
* ```
* matrixClient.on("RoomState.members", function(event, state, member){
* var newMembershipState = member.membership;
* });
* ```
*/
[RoomStateEvent.Members]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void;
/**
* Fires whenever a member is added to the members dictionary. The RoomMember
* will not be fully populated yet (e.g. no membership state) but will already
* be available in the members dictionary.
* @param event - The matrix event which caused this event to fire.
* @param state - The room state whose RoomState.members dictionary
* was updated with a new entry.
* @param member - The room member that was added.
* @example
* ```
* matrixClient.on("RoomState.newMember", function(event, state, member){
* // add event listeners on 'member'
* });
* ```
*/
[RoomStateEvent.NewMember]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void;
[RoomStateEvent.Update]: (state: RoomState) => void;
[RoomStateEvent.BeaconLiveness]: (state: RoomState, hasLiveBeacons: boolean) => void;
[RoomStateEvent.Marker]: (event: MatrixEvent, setStateOptions?: IMarkerFoundOptions) => void;
[BeaconEvent.New]: (event: MatrixEvent, beacon: Beacon) => void;
};
type EmittedEvents = RoomStateEvent | BeaconEvent;
type EventHandlerMap = RoomStateEventHandlerMap & BeaconEventHandlerMap;
export declare class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
readonly roomId: string;
private oobMemberFlags;
readonly reEmitter: TypedReEmitter<EmittedEvents, EventHandlerMap>;
private sentinels;
private displayNameToUserIds;
private userIdsToDisplayNames;
private tokenToInvite;
private joinedMemberCount;
private summaryJoinedMemberCount;
private invitedMemberCount;
private summaryInvitedMemberCount;
private modified;
members: Record<string, RoomMember>;
events: Map<string, Map<string, MatrixEvent>>;
paginationToken: string | null;
readonly beacons: Map<string, Beacon>;
private _liveBeaconIds;
/**
* Construct room state.
*
* Room State represents the state of the room at a given point.
* It can be mutated by adding state events to it.
* There are two types of room member associated with a state event:
* normal member objects (accessed via getMember/getMembers) which mutate
* with the state to represent the current state of that room/user, e.g.
* the object returned by `getMember('@bob:example.com')` will mutate to
* get a different display name if Bob later changes his display name
* in the room.
* There are also 'sentinel' members (accessed via getSentinelMember).
* These also represent the state of room members at the point in time
* represented by the RoomState object, but unlike objects from getMember,
* sentinel objects will always represent the room state as at the time
* getSentinelMember was called, so if Bob subsequently changes his display
* name, a room member object previously acquired with getSentinelMember
* will still have his old display name. Calling getSentinelMember again
* after the display name change will return a new RoomMember object
* with Bob's new display name.
*
* @param roomId - Optional. The ID of the room which has this state.
* If none is specified it just tracks paginationTokens, useful for notifTimelineSet
* @param oobMemberFlags - Optional. The state of loading out of bound members.
* As the timeline might get reset while they are loading, this state needs to be inherited
* and shared when the room state is cloned for the new timeline.
* This should only be passed from clone.
*/
constructor(roomId: string, oobMemberFlags?: {
status: OobStatus;
});
/**
* Returns the number of joined members in this room
* This method caches the result.
* @returns The number of members in this room whose membership is 'join'
*/
getJoinedMemberCount(): number;
/**
* Set the joined member count explicitly (like from summary part of the sync response)
* @param count - the amount of joined members
*/
setJoinedMemberCount(count: number): void;
/**
* Returns the number of invited members in this room
* @returns The number of members in this room whose membership is 'invite'
*/
getInvitedMemberCount(): number;
/**
* Set the amount of invited members in this room
* @param count - the amount of invited members
*/
setInvitedMemberCount(count: number): void;
/**
* Get all RoomMembers in this room.
* @returns A list of RoomMembers.
*/
getMembers(): RoomMember[];
/**
* Get all RoomMembers in this room, excluding the user IDs provided.
* @param excludedIds - The user IDs to exclude.
* @returns A list of RoomMembers.
*/
getMembersExcept(excludedIds: string[]): RoomMember[];
/**
* Get a room member by their user ID.
* @param userId - The room member's user ID.
* @returns The member or null if they do not exist.
*/
getMember(userId: string): RoomMember | null;
/**
* Get a room member whose properties will not change with this room state. You
* typically want this if you want to attach a RoomMember to a MatrixEvent which
* may no longer be represented correctly by Room.currentState or Room.oldState.
* The term 'sentinel' refers to the fact that this RoomMember is an unchanging
* guardian for state at this particular point in time.
* @param userId - The room member's user ID.
* @returns The member or null if they do not exist.
*/
getSentinelMember(userId: string): RoomMember | null;
/**
* Get state events from the state of the room.
* @param eventType - The event type of the state event.
* @param stateKey - Optional. The state_key of the state event. If
* this is `undefined` then all matching state events will be
* returned.
* @returns A list of events if state_key was
* `undefined`, else a single event (or null if no match found).
*/
getStateEvents(eventType: EventType | string): MatrixEvent[];
getStateEvents(eventType: EventType | string, stateKey: string): MatrixEvent | null;
get hasLiveBeacons(): boolean;
get liveBeaconIds(): BeaconIdentifier[];
/**
* Creates a copy of this room state so that mutations to either won't affect the other.
* @returns the copy of the room state
*/
clone(): RoomState;
/**
* Add previously unknown state events.
* When lazy loading members while back-paginating,
* the relevant room state for the timeline chunk at the end
* of the chunk can be set with this method.
* @param events - state events to prepend
*/
setUnknownStateEvents(events: MatrixEvent[]): void;
/**
* Add an array of one or more state MatrixEvents, overwriting any existing
* state with the same `{type, stateKey}` tuple. Will fire "RoomState.events"
* for every event added. May fire "RoomState.members" if there are
* `m.room.member` events. May fire "RoomStateEvent.Marker" if there are
* `UNSTABLE_MSC2716_MARKER` events.
* @param stateEvents - a list of state events for this room.
*
* @remarks
* Fires {@link RoomStateEvent.Members}
* Fires {@link RoomStateEvent.NewMember}
* Fires {@link RoomStateEvent.Events}
* Fires {@link RoomStateEvent.Marker}
*/
setStateEvents(stateEvents: MatrixEvent[], markerFoundOptions?: IMarkerFoundOptions): void;
processBeaconEvents(events: MatrixEvent[], matrixClient: MatrixClient): Promise<void>;
/**
* Looks up a member by the given userId, and if it doesn't exist,
* create it and emit the `RoomState.newMember` event.
* This method makes sure the member is added to the members dictionary
* before emitting, as this is done from setStateEvents and setOutOfBandMember.
* @param userId - the id of the user to look up
* @param event - the membership event for the (new) member. Used to emit.
* @returns the member, existing or newly created.
*
* @remarks
* Fires {@link RoomStateEvent.NewMember}
*/
private getOrCreateMember;
private setStateEvent;
/**
* @experimental
*/
private setBeacon;
/**
* @experimental
* Check liveness of room beacons
* emit RoomStateEvent.BeaconLiveness event
*/
private onBeaconLivenessChange;
private getStateEventMatching;
private updateMember;
/**
* Get the out-of-band members loading state, whether loading is needed or not.
* Note that loading might be in progress and hence isn't needed.
* @returns whether or not the members of this room need to be loaded
*/
needsOutOfBandMembers(): boolean;
/**
* Check if loading of out-of-band-members has completed
*
* @returns true if the full membership list of this room has been loaded. False if it is not started or is in
* progress.
*/
outOfBandMembersReady(): boolean;
/**
* Mark this room state as waiting for out-of-band members,
* ensuring it doesn't ask for them to be requested again
* through needsOutOfBandMembers
*/
markOutOfBandMembersStarted(): void;
/**
* Mark this room state as having failed to fetch out-of-band members
*/
markOutOfBandMembersFailed(): void;
/**
* Clears the loaded out-of-band members
*/
clearOutOfBandMembers(): void;
/**
* Sets the loaded out-of-band members.
* @param stateEvents - array of membership state events
*/
setOutOfBandMembers(stateEvents: MatrixEvent[]): void;
/**
* Sets a single out of band member, used by both setOutOfBandMembers and clone
* @param stateEvent - membership state event
*/
private setOutOfBandMember;
/**
* Set the current typing event for this room.
* @param event - The typing event
*/
setTypingEvent(event: MatrixEvent): void;
/**
* Get the m.room.member event which has the given third party invite token.
*
* @param token - The token
* @returns The m.room.member event or null
*/
getInviteForThreePidToken(token: string): MatrixEvent | null;
/**
* Update the last modified time to the current time.
*/
private updateModifiedTime;
/**
* Get the timestamp when this room state was last updated. This timestamp is
* updated when this object has received new state events.
* @returns The timestamp
*/
getLastModifiedTime(): number;
/**
* Get user IDs with the specified or similar display names.
* @param displayName - The display name to get user IDs from.
* @returns An array of user IDs or an empty array.
*/
getUserIdsWithDisplayName(displayName: string): string[];
/**
* Returns true if userId is in room, event is not redacted and either sender of
* mxEvent or has power level sufficient to redact events other than their own.
* @param mxEvent - The event to test permission for
* @param userId - The user ID of the user to test permission for
* @returns true if the given used ID can redact given event
*/
maySendRedactionForEvent(mxEvent: MatrixEvent, userId: string): boolean;
/**
* Returns true if the given power level is sufficient for action
* @param action - The type of power level to check
* @param powerLevel - The power level of the member
* @returns true if the given power level is sufficient
*/
hasSufficientPowerLevelFor(action: "ban" | "kick" | "redact", powerLevel: number): boolean;
/**
* Short-form for maySendEvent('m.room.message', userId)
* @param userId - The user ID of the user to test permission for
* @returns true if the given user ID should be permitted to send
* message events into the given room.
*/
maySendMessage(userId: string): boolean;
/**
* Returns true if the given user ID has permission to send a normal
* event of type `eventType` into this room.
* @param eventType - The type of event to test
* @param userId - The user ID of the user to test permission for
* @returns true if the given user ID should be permitted to send
* the given type of event into this room,
* according to the room's state.
*/
maySendEvent(eventType: EventType | string, userId: string): boolean;
/**
* Returns true if the given MatrixClient has permission to send a state
* event of type `stateEventType` into this room.
* @param stateEventType - The type of state events to test
* @param cli - The client to test permission for
* @returns true if the given client should be permitted to send
* the given type of state event into this room,
* according to the room's state.
*/
mayClientSendStateEvent(stateEventType: EventType | string, cli: MatrixClient): boolean;
/**
* Returns true if the given user ID has permission to send a state
* event of type `stateEventType` into this room.
* @param stateEventType - The type of state events to test
* @param userId - The user ID of the user to test permission for
* @returns true if the given user ID should be permitted to send
* the given type of state event into this room,
* according to the room's state.
*/
maySendStateEvent(stateEventType: EventType | string, userId: string): boolean;
/**
* Returns true if the given user ID has permission to send a normal or state
* event of type `eventType` into this room.
* @param eventType - The type of event to test
* @param userId - The user ID of the user to test permission for
* @param state - If true, tests if the user may send a state
event of this type. Otherwise tests whether
they may send a regular event.
* @returns true if the given user ID should be permitted to send
* the given type of event into this room,
* according to the room's state.
*/
private maySendEventOfType;
/**
* Returns true if the given user ID has permission to trigger notification
* of type `notifLevelKey`
* @param notifLevelKey - The level of notification to test (eg. 'room')
* @param userId - The user ID of the user to test permission for
* @returns true if the given user ID has permission to trigger a
* notification of this type.
*/
mayTriggerNotifOfType(notifLevelKey: string, userId: string): boolean;
/**
* Returns the join rule based on the m.room.join_rule state event, defaulting to `invite`.
* @returns the join_rule applied to this room
*/
getJoinRule(): JoinRule;
/**
* Returns the history visibility based on the m.room.history_visibility state event, defaulting to `shared`.
* @returns the history_visibility applied to this room
*/
getHistoryVisibility(): HistoryVisibility;
/**
* Returns the guest access based on the m.room.guest_access state event, defaulting to `shared`.
* @returns the guest_access applied to this room
*/
getGuestAccess(): GuestAccess;
/**
* Find the predecessor room based on this room state.
*
* @param msc3946ProcessDynamicPredecessor - if true, look for an
* m.room.predecessor state event and use it if found (MSC3946).
* @returns null if this room has no predecessor. Otherwise, returns
* the roomId, last eventId and viaServers of the predecessor room.
*
* If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
* as well as m.room.create events to find predecessors.
*
* Note: if an m.predecessor event is used, eventId may be undefined
* since last_known_event_id is optional.
*
* Note: viaServers may be undefined, and will definitely be undefined if
* this predecessor comes from a RoomCreate event (rather than a
* RoomPredecessor, which has the optional via_servers property).
*/
findPredecessor(msc3946ProcessDynamicPredecessor?: boolean): {
roomId: string;
eventId?: string;
viaServers?: string[];
} | null;
private updateThirdPartyTokenCache;
private updateDisplayNameCache;
}
export {};
//# sourceMappingURL=room-state.d.ts.map
|