You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
add invited count, only copy summary fields if present in summary
only copy any member from summary as they are only in the response when they change. Also accumulate them in the sync accumulator
This commit is contained in:
@@ -79,6 +79,8 @@ function RoomState(roomId, oobMemberFlags = undefined) {
|
|||||||
this._userIdsToDisplayNames = {};
|
this._userIdsToDisplayNames = {};
|
||||||
this._tokenToInvite = {}; // 3pid invite state_key to m.room.member invite
|
this._tokenToInvite = {}; // 3pid invite state_key to m.room.member invite
|
||||||
this._joinedMemberCount = null; // cache of the number of joined members
|
this._joinedMemberCount = null; // cache of the number of joined members
|
||||||
|
this._invitedMemberCount = null;
|
||||||
|
|
||||||
if (!oobMemberFlags) {
|
if (!oobMemberFlags) {
|
||||||
oobMemberFlags = {
|
oobMemberFlags = {
|
||||||
status: OOB_STATUS_NOTSTARTED,
|
status: OOB_STATUS_NOTSTARTED,
|
||||||
@@ -102,9 +104,33 @@ RoomState.prototype.getJoinedMemberCount = function() {
|
|||||||
return this._joinedMemberCount;
|
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) {
|
RoomState.prototype.setJoinedMemberCount = function(count) {
|
||||||
this._joinedMemberCount = 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.
|
* Get all RoomMembers in this room.
|
||||||
@@ -193,6 +219,9 @@ RoomState.prototype.clone = function() {
|
|||||||
// Ugly hack: see above
|
// Ugly hack: see above
|
||||||
this._oobMemberFlags.status = status;
|
this._oobMemberFlags.status = status;
|
||||||
|
|
||||||
|
copy.setJoinedMemberCount(this.getJoinedMemberCount());
|
||||||
|
copy.setInvitedMemberCount(this.getInvitedMemberCount());
|
||||||
|
|
||||||
// copy out of band flags if needed
|
// copy out of band flags if needed
|
||||||
if (this._oobMemberFlags.status == OOB_STATUS_FINISHED) {
|
if (this._oobMemberFlags.status == OOB_STATUS_FINISHED) {
|
||||||
// copy markOutOfBand flags
|
// copy markOutOfBand flags
|
||||||
|
|||||||
@@ -379,12 +379,18 @@ Room.prototype.setUnreadNotificationCount = function(type, count) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Room.prototype.setSummary = function(summary) {
|
Room.prototype.setSummary = function(summary) {
|
||||||
const heros = summary["m.heroes"];
|
const heroes = summary["m.heroes"];
|
||||||
const count = summary["m.joined_member_count"];
|
const joinedCount = summary["m.joined_member_count"];
|
||||||
if (Number.isInteger(count)) {
|
const invitedCount = summary["m.invited_member_count"];
|
||||||
this.currentState.setJoinedMemberCount(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,7 +63,11 @@ class SyncAccumulator {
|
|||||||
// { event: $event, token: null|token },
|
// { 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 },
|
// _accountData: { $event_type: json },
|
||||||
// _unreadNotifications: { ... unread_notifications JSON ... },
|
// _unreadNotifications: { ... unread_notifications JSON ... },
|
||||||
// _readReceipts: { $user_id: { data: $json, eventId: $event_id }}
|
// _readReceipts: { $user_id: { data: $json, eventId: $event_id }}
|
||||||
@@ -261,7 +265,15 @@ class SyncAccumulator {
|
|||||||
currentData._unreadNotifications = data.unread_notifications;
|
currentData._unreadNotifications = data.unread_notifications;
|
||||||
}
|
}
|
||||||
if (data.summary) {
|
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) {
|
if (data.ephemeral && data.ephemeral.events) {
|
||||||
|
|||||||
@@ -823,7 +823,11 @@ SyncApi.prototype._processSyncResponse = async function(
|
|||||||
// state: { events: [] },
|
// state: { events: [] },
|
||||||
// timeline: { events: [], prev_batch: $token, limited: true },
|
// timeline: { events: [], prev_batch: $token, limited: true },
|
||||||
// ephemeral: { events: [] },
|
// 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: [] },
|
// account_data: { events: [] },
|
||||||
// unread_notifications: {
|
// unread_notifications: {
|
||||||
// highlight_count: 0,
|
// highlight_count: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user