forked from mystiq/hydrogen-web
only set unread for incremental syncs
This commit is contained in:
parent
eae5bc4230
commit
4fb3010676
3 changed files with 16 additions and 10 deletions
|
@ -142,7 +142,7 @@ export class Sync {
|
||||||
room = this._session.createRoom(roomId);
|
room = this._session.createRoom(roomId);
|
||||||
}
|
}
|
||||||
console.log(` * applying sync response to room ${roomId} ...`);
|
console.log(` * applying sync response to room ${roomId} ...`);
|
||||||
const changes = await room.writeSync(roomResponse, membership, syncTxn);
|
const changes = await room.writeSync(roomResponse, membership, isInitialSync, syncTxn);
|
||||||
roomChanges.push({room, changes});
|
roomChanges.push({room, changes});
|
||||||
});
|
});
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
|
@ -42,8 +42,8 @@ export class Room extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @package */
|
/** @package */
|
||||||
async writeSync(roomResponse, membership, txn) {
|
async writeSync(roomResponse, membership, isInitialSync, txn) {
|
||||||
const summaryChanges = this._summary.writeSync(roomResponse, membership, txn);
|
const summaryChanges = this._summary.writeSync(roomResponse, membership, isInitialSync, txn);
|
||||||
const {entries, newLiveKey, changedMembers} = await this._syncWriter.writeSync(roomResponse, txn);
|
const {entries, newLiveKey, changedMembers} = await this._syncWriter.writeSync(roomResponse, txn);
|
||||||
let removedPendingEvents;
|
let removedPendingEvents;
|
||||||
if (roomResponse.timeline && roomResponse.timeline.events) {
|
if (roomResponse.timeline && roomResponse.timeline.events) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function applySyncResponse(data, roomResponse, membership) {
|
function applySyncResponse(data, roomResponse, membership, isInitialSync) {
|
||||||
if (roomResponse.summary) {
|
if (roomResponse.summary) {
|
||||||
data = updateSummary(data, roomResponse.summary);
|
data = updateSummary(data, roomResponse.summary);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,9 @@ function applySyncResponse(data, roomResponse, membership) {
|
||||||
}
|
}
|
||||||
// state comes before timeline
|
// state comes before timeline
|
||||||
if (roomResponse.state) {
|
if (roomResponse.state) {
|
||||||
data = roomResponse.state.events.reduce(processEvent, data);
|
data = roomResponse.state.events.reduce((data, event) => {
|
||||||
|
return processEvent(data, event, isInitialSync);
|
||||||
|
}, data);
|
||||||
}
|
}
|
||||||
if (roomResponse.timeline) {
|
if (roomResponse.timeline) {
|
||||||
const {timeline} = roomResponse;
|
const {timeline} = roomResponse;
|
||||||
|
@ -32,7 +34,9 @@ function applySyncResponse(data, roomResponse, membership) {
|
||||||
data = data.cloneIfNeeded();
|
data = data.cloneIfNeeded();
|
||||||
data.lastPaginationToken = timeline.prev_batch;
|
data.lastPaginationToken = timeline.prev_batch;
|
||||||
}
|
}
|
||||||
data = timeline.events.reduce(processEvent, data);
|
data = timeline.events.reduce((data, event) => {
|
||||||
|
return processEvent(data, event, isInitialSync);
|
||||||
|
}, data);
|
||||||
}
|
}
|
||||||
const unreadNotifications = roomResponse.unread_notifications;
|
const unreadNotifications = roomResponse.unread_notifications;
|
||||||
if (unreadNotifications) {
|
if (unreadNotifications) {
|
||||||
|
@ -44,7 +48,7 @@ function applySyncResponse(data, roomResponse, membership) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processEvent(data, event) {
|
function processEvent(data, event, isInitialSync) {
|
||||||
if (event.type === "m.room.encryption") {
|
if (event.type === "m.room.encryption") {
|
||||||
if (!data.isEncrypted) {
|
if (!data.isEncrypted) {
|
||||||
data = data.cloneIfNeeded();
|
data = data.cloneIfNeeded();
|
||||||
|
@ -65,7 +69,9 @@ function processEvent(data, event) {
|
||||||
} else if (event.type === "m.room.message") {
|
} else if (event.type === "m.room.message") {
|
||||||
data = data.cloneIfNeeded();
|
data = data.cloneIfNeeded();
|
||||||
data.lastMessageTimestamp = event.origin_server_ts;
|
data.lastMessageTimestamp = event.origin_server_ts;
|
||||||
data.isUnread = true;
|
if (!isInitialSync) {
|
||||||
|
data.isUnread = true;
|
||||||
|
}
|
||||||
const {content} = event;
|
const {content} = event;
|
||||||
const body = content?.body;
|
const body = content?.body;
|
||||||
const msgtype = content?.msgtype;
|
const msgtype = content?.msgtype;
|
||||||
|
@ -207,11 +213,11 @@ export class RoomSummary {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeSync(roomResponse, membership, txn) {
|
writeSync(roomResponse, membership, isInitialSync, txn) {
|
||||||
// clear cloned flag, so cloneIfNeeded makes a copy and
|
// clear cloned flag, so cloneIfNeeded makes a copy and
|
||||||
// this._data is not modified if any field is changed.
|
// this._data is not modified if any field is changed.
|
||||||
this._data.cloned = false;
|
this._data.cloned = false;
|
||||||
const data = applySyncResponse(this._data, roomResponse, membership);
|
const data = applySyncResponse(this._data, roomResponse, membership, isInitialSync);
|
||||||
if (data !== this._data) {
|
if (data !== this._data) {
|
||||||
// need to think here how we want to persist
|
// need to think here how we want to persist
|
||||||
// things like unread status (as read marker, or unread count)?
|
// things like unread status (as read marker, or unread count)?
|
||||||
|
|
Loading…
Reference in a new issue