|
| 1 | +import 'package:matrix/matrix.dart'; |
| 2 | + |
| 3 | +class RoomResult { |
| 4 | + /// An integer that can be used to sort rooms based on the last "proper" activity in the room. Greater means more recent. |
| 5 | + /// |
| 6 | + /// "Proper" activity is defined as an event being received is one of the following types: m.room.create, m.room.message, m.room.encrypted, m.sticker, m.call.invite, m.poll.start, m.beacon_info. |
| 7 | + /// |
| 8 | + /// For rooms that the user is not currently joined to, this instead represents when the relevant membership happened, e.g. when the user left the room. |
| 9 | + /// |
| 10 | + /// The exact value of bump_stamp is opaque to the client, a server may use e.g. an auto-incrementing integer, a timestamp, etc. |
| 11 | + /// |
| 12 | + /// The bump_stamp may decrease in subsequent responses, if e.g. an event was redacted/removed (or purged in cases of retention policies). |
| 13 | + final int bumpStamp; |
| 14 | + |
| 15 | + /// The current membership of the user, or omitted if user not in room (for peeking). |
| 16 | + // TODO: migrate to enum |
| 17 | + final String? membership; |
| 18 | + |
| 19 | + /// The name of the lists that match this room. The field is omitted if it doesn't match any list and is included only due to a subscription. |
| 20 | + final List<String>? lists; |
| 21 | + |
| 22 | + // Currently or previously joined rooms |
| 23 | +// When a user is or has been in the room, the following field are also returned: |
| 24 | + |
| 25 | + /// Room name or calculated room name. |
| 26 | + final String? name; |
| 27 | + |
| 28 | + /// Room avatar |
| 29 | +// TODO: migrate to Uri |
| 30 | + final String? avatar; |
| 31 | + |
| 32 | + /// A truncated list of users in the room that can be used to calculate the room name. Will first include joined users, then invited users, and then finally left users. The same as the m.heroes section in the /v3/sync specification |
| 33 | + final List<StrippedHero>? heroes; |
| 34 | + |
| 35 | + /// Flag to specify whether the room is a direct-message room (according to account data). If absent the room is not a DM room. |
| 36 | + final bool? isDm; |
| 37 | + |
| 38 | + /// Flag which is set when this is the first time the server is sending this data on this connection, or if the client should replace all room data with what is returned. Clients can use this flag to replace or update their local state. The absence of this flag means false. |
| 39 | + final bool? initial; |
| 40 | + |
| 41 | + /// Flag which is set if we're returning more historic events due to the timeline limit having increased. See "Changing room configs" section. |
| 42 | + final bool? expandedTimeline; |
| 43 | + |
| 44 | + /// Changes in the current state of the room. |
| 45 | + /// |
| 46 | + /// To handle state being deleted, the list may include a StateStub type (c.f. schema below) that only has type and state_key fields. The presence or absence of content field can be used to differentiate between the two cases. |
| 47 | + final List<BasicEvent>? requiredState; |
| 48 | + |
| 49 | + /// The latest events in the room. May not include all events if e.g. there were more events than the configured timeline_limit, c.f. the limited field. |
| 50 | + /// |
| 51 | + /// If limited is true then we include bundle aggregations for the event, as per /v3/sync. |
| 52 | + /// |
| 53 | + /// The last event in the list is the most recent. |
| 54 | + final List<MatrixEvent>? timelineEvents; |
| 55 | + |
| 56 | + /// A token that can be passed as a start parameter to the /rooms/<room_id>/messages API to retrieve earlier messages. |
| 57 | + final String? prevBatch; |
| 58 | + |
| 59 | + /// True if there are more events since the previous sync than were included in the timeline_events field, or that the client should paginate to fetch more events. |
| 60 | + /// |
| 61 | + /// Note that server may return fewer than the requested number of events and still set limited to true, e.g. because there is a gap in the history the server has for the room. |
| 62 | + /// |
| 63 | + /// Absence means false |
| 64 | + final bool limited; |
| 65 | + |
| 66 | + /// The number of timeline events which have "just occurred" and are not historical, i.e. that have happened since the previous sync request. The last N events are 'live' and should be treated as such. |
| 67 | + /// |
| 68 | + /// This is mostly useful to e.g. determine whether a given @mention event should make a noise or not. Clients cannot rely solely on the absence of initial: true to determine live events because if a room not in the sliding window bumps into the window because of an @mention it will have initial: true yet contain a single live event (with potentially other old events in the timeline). |
| 69 | + final int? numLive; |
| 70 | + |
| 71 | + /// The number of users with membership of join, including the client's own user ID. (same as /v3/sync m.joined_member_count) |
| 72 | + final int? joinedCount; |
| 73 | + |
| 74 | + /// The number of users with membership of invite. (same as /v3/sync m.invited_member_count) |
| 75 | + final int? invitedCount; |
| 76 | + |
| 77 | + /// The total number of unread notifications for this room. (same as /v3/sync). |
| 78 | + /// |
| 79 | + /// Does not included threaded notifications, which are returned in an extension. |
| 80 | + final int? notificationCount; |
| 81 | + |
| 82 | + /// The number of unread notifications for this room with the highlight flag set. (same as /v3/sync) |
| 83 | + /// |
| 84 | + /// Does not included threaded notifications, which are returned in an extension. |
| 85 | + final int? highlightCount; |
| 86 | + |
| 87 | + // Invite/knock/rejections |
| 88 | +// For rooms the user has not been joined to the client also gets the stripped state events. This is commonly the case for invites or knocks, but can also be for when the user has rejected an invite. |
| 89 | + |
| 90 | + /// Stripped state events (for rooms where the user is invited). Same as rooms.invite.$room_id.invite_state for invites in /v3/sync. |
| 91 | + final StrippedStateEvent? stripped_state; |
| 92 | + |
| 93 | + const RoomResult({ |
| 94 | + required this.bumpStamp, |
| 95 | + this.membership, |
| 96 | + this.lists, |
| 97 | + this.name, |
| 98 | + this.avatar, |
| 99 | + this.heroes, |
| 100 | + this.isDm, |
| 101 | + this.initial, |
| 102 | + this.expandedTimeline, |
| 103 | + this.requiredState, |
| 104 | + this.timelineEvents, |
| 105 | + this.prevBatch, |
| 106 | + this.limited = false, |
| 107 | + this.numLive, |
| 108 | + this.joinedCount, |
| 109 | + this.invitedCount, |
| 110 | + this.notificationCount, |
| 111 | + this.highlightCount, |
| 112 | + this.stripped_state, |
| 113 | + }); |
| 114 | + |
| 115 | + factory RoomResult.fromJson(Map<String, Object?> json) => RoomResult( |
| 116 | + bumpStamp: json['bump_stamp'] as int, |
| 117 | + membership: json['membership'] as String?, |
| 118 | + lists: (json['lists'] as List?)?.cast<String>(), |
| 119 | + name: json['name'] as String?, |
| 120 | + avatar: json['avatar'] as String?, |
| 121 | + heroes: json.containsKey('heroes') |
| 122 | + ? (json['heroes'] as List) |
| 123 | + .map((v) => StrippedHero.fromJson(v)) |
| 124 | + .toList() |
| 125 | + : null, |
| 126 | + isDm: json['is_dm'] as bool?, |
| 127 | + initial: json['initial'] as bool?, |
| 128 | + expandedTimeline: json['expanded_timeline'] as bool?, |
| 129 | + requiredState: json.containsKey('required_state') |
| 130 | + ? (json['required_state'] as List) |
| 131 | + .map((v) => BasicEvent.fromJson(v)) |
| 132 | + .toList() |
| 133 | + : null, |
| 134 | + timelineEvents: json.containsKey('timeline_events') |
| 135 | + ? (json['timeline_events'] as List) |
| 136 | + .map((v) => MatrixEvent.fromJson(v)) |
| 137 | + .toList() |
| 138 | + : null, |
| 139 | + prevBatch: json['prev_batch'] as String?, |
| 140 | + limited: json['limited'] as bool? ?? false, |
| 141 | + numLive: json['num_live'] as int?, |
| 142 | + joinedCount: json['joined_count'] as int?, |
| 143 | + invitedCount: json['invited_count'] as int?, |
| 144 | + notificationCount: json['notification_count'] as int?, |
| 145 | + highlightCount: json['highlight_count'] as int?, |
| 146 | + stripped_state: json.containsKey('stripped_state') |
| 147 | + ? StrippedStateEvent.fromJson( |
| 148 | + (json['stripped_state'] as Map).cast<String, Object?>(), |
| 149 | + ) |
| 150 | + : null, |
| 151 | + ); |
| 152 | +} |
0 commit comments