diff --git a/src/models/room-state.js b/src/models/room-state.js index 2ed858ab8..69fe27abc 100644 --- a/src/models/room-state.js +++ b/src/models/room-state.js @@ -79,6 +79,8 @@ function RoomState(roomId, oobMemberFlags = undefined) { this._userIdsToDisplayNames = {}; this._tokenToInvite = {}; // 3pid invite state_key to m.room.member invite this._joinedMemberCount = null; // cache of the number of joined members + this._invitedMemberCount = null; + if (!oobMemberFlags) { oobMemberFlags = { status: OOB_STATUS_NOTSTARTED, @@ -102,9 +104,33 @@ RoomState.prototype.getJoinedMemberCount = function() { return this._joinedMemberCount; }; +/** + * Set the joined member count explicitly (like from summary part of the sync response) + * @param {number} count the amount of joined members + */ RoomState.prototype.setJoinedMemberCount = function(count) { this._joinedMemberCount = count; } +/** + * Returns the number of invited members in this room + * @return {integer} The number of members in this room whose membership is 'invite' + */ +RoomState.prototype.getInvitedMemberCount = function() { + if (this._invitedMemberCount === null) { + this._invitedMemberCount = this.getMembers().filter((m) => { + return m.membership === 'invite'; + }).length; + } + return this._invitedMemberCount; +}; + +/** + * Set the amount of invited members in this room + * @param {number} count the amount of invited members + */ +RoomState.prototype.setInvitedMemberCount = function(count) { + this._invitedMemberCount = count; +} /** * Get all RoomMembers in this room. @@ -193,6 +219,9 @@ RoomState.prototype.clone = function() { // Ugly hack: see above this._oobMemberFlags.status = status; + copy.setJoinedMemberCount(this.getJoinedMemberCount()); + copy.setInvitedMemberCount(this.getInvitedMemberCount()); + // copy out of band flags if needed if (this._oobMemberFlags.status == OOB_STATUS_FINISHED) { // copy markOutOfBand flags diff --git a/src/models/room.js b/src/models/room.js index fd4627768..ff5dcb1f3 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -379,12 +379,18 @@ Room.prototype.setUnreadNotificationCount = function(type, count) { }; Room.prototype.setSummary = function(summary) { - const heros = summary["m.heroes"]; - const count = summary["m.joined_member_count"]; - if (Number.isInteger(count)) { - this.currentState.setJoinedMemberCount(count); + const heroes = summary["m.heroes"]; + const joinedCount = summary["m.joined_member_count"]; + const invitedCount = summary["m.invited_member_count"]; + if (Number.isInteger(joinedCount)) { + this.currentState.setJoinedMemberCount(joinedCount); + } + if (Number.isInteger(invitedCount)) { + this.currentState.setInvitedMemberCount(invitedCount); + } + if (heroes) { + this._summaryHeroes = heroes; } - this._summaryHeroes = heros; } /** diff --git a/src/sync-accumulator.js b/src/sync-accumulator.js index 3ff71af77..1a617d0ab 100644 --- a/src/sync-accumulator.js +++ b/src/sync-accumulator.js @@ -63,7 +63,11 @@ class SyncAccumulator { // { event: $event, token: null|token }, // ... // ], - // _summary: { m.heroes: [ $user_id ], m.joined_member_count: $count } + // _summary: { + // m.heroes: [ $user_id ], + // m.joined_member_count: $count, + // m.invited_member_count: $count + // }, // _accountData: { $event_type: json }, // _unreadNotifications: { ... unread_notifications JSON ... }, // _readReceipts: { $user_id: { data: $json, eventId: $event_id }} @@ -261,7 +265,15 @@ class SyncAccumulator { currentData._unreadNotifications = data.unread_notifications; } if (data.summary) { - currentData._summary = data.summary; + const HEROES_KEY = "m.heroes"; + const INVITED_COUNT_KEY = "m.invited_member_count"; + const JOINED_COUNT_KEY = "m.joined_member_count"; + + const acc = currentData._summary; + const sum = data.summary; + acc[HEROES_KEY] = sum[HEROES_KEY] || acc[HEROES_KEY]; + acc[JOINED_COUNT_KEY] = sum[JOINED_COUNT_KEY] || acc[JOINED_COUNT_KEY]; + acc[INVITED_COUNT_KEY] = sum[INVITED_COUNT_KEY] || acc[INVITED_COUNT_KEY]; } if (data.ephemeral && data.ephemeral.events) { diff --git a/src/sync.js b/src/sync.js index c3c8970e8..c912d62d0 100644 --- a/src/sync.js +++ b/src/sync.js @@ -823,7 +823,11 @@ SyncApi.prototype._processSyncResponse = async function( // state: { events: [] }, // timeline: { events: [], prev_batch: $token, limited: true }, // ephemeral: { events: [] }, - // summary: { m.heroes: [ $userId ], m.joined_member_count: $count } + // summary: { + // m.heroes: [ $user_id ], + // m.joined_member_count: $count, + // m.invited_member_count: $count + // }, // account_data: { events: [] }, // unread_notifications: { // highlight_count: 0,