You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Merge pull request #981 from matrix-org/jryans/reactions-send-marks-unread
Block read marker and read receipt from advancing into pending events
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2018-2019 New Vector Ltd
|
Copyright 2018-2019 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -2190,7 +2191,12 @@ MatrixClient.prototype.sendReceipt = function(event, receiptType, callback) {
|
|||||||
* @return {module:client.Promise} Resolves: TODO
|
* @return {module:client.Promise} Resolves: TODO
|
||||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
*/
|
*/
|
||||||
MatrixClient.prototype.sendReadReceipt = function(event, callback) {
|
MatrixClient.prototype.sendReadReceipt = async function(event, callback) {
|
||||||
|
const eventId = event.getId();
|
||||||
|
const room = this.getRoom(event.getRoomId());
|
||||||
|
if (room && room.hasPendingEvent(eventId)) {
|
||||||
|
throw new Error(`Cannot set read receipt to a pending event (${eventId})`);
|
||||||
|
}
|
||||||
return this.sendReceipt(event, "m.read", callback);
|
return this.sendReceipt(event, "m.read", callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2200,20 +2206,25 @@ MatrixClient.prototype.sendReadReceipt = function(event, callback) {
|
|||||||
* and displayed as a horizontal line in the timeline that is visually distinct to the
|
* and displayed as a horizontal line in the timeline that is visually distinct to the
|
||||||
* position of the user's own read receipt.
|
* position of the user's own read receipt.
|
||||||
* @param {string} roomId ID of the room that has been read
|
* @param {string} roomId ID of the room that has been read
|
||||||
* @param {string} eventId ID of the event that has been read
|
* @param {string} rmEventId ID of the event that has been read
|
||||||
* @param {string} rrEvent the event tracked by the read receipt. This is here for
|
* @param {string} rrEvent the event tracked by the read receipt. This is here for
|
||||||
* convenience because the RR and the RM are commonly updated at the same time as each
|
* convenience because the RR and the RM are commonly updated at the same time as each
|
||||||
* other. The local echo of this receipt will be done if set. Optional.
|
* other. The local echo of this receipt will be done if set. Optional.
|
||||||
* @return {module:client.Promise} Resolves: the empty object, {}.
|
* @return {module:client.Promise} Resolves: the empty object, {}.
|
||||||
*/
|
*/
|
||||||
MatrixClient.prototype.setRoomReadMarkers = function(roomId, eventId, rrEvent) {
|
MatrixClient.prototype.setRoomReadMarkers = async function(roomId, rmEventId, rrEvent) {
|
||||||
const rmEventId = eventId;
|
const room = this.getRoom(roomId);
|
||||||
let rrEventId;
|
if (room && room.hasPendingEvent(rmEventId)) {
|
||||||
|
throw new Error(`Cannot set read marker to a pending event (${rmEventId})`);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the optional RR update, do local echo like `sendReceipt`
|
// Add the optional RR update, do local echo like `sendReceipt`
|
||||||
|
let rrEventId;
|
||||||
if (rrEvent) {
|
if (rrEvent) {
|
||||||
rrEventId = rrEvent.getId();
|
rrEventId = rrEvent.getId();
|
||||||
const room = this.getRoom(roomId);
|
if (room && room.hasPendingEvent(rrEventId)) {
|
||||||
|
throw new Error(`Cannot set read receipt to a pending event (${rrEventId})`);
|
||||||
|
}
|
||||||
if (room) {
|
if (room) {
|
||||||
room._addLocalEchoReceipt(this.credentials.userId, rrEvent, "m.read");
|
room._addLocalEchoReceipt(this.credentials.userId, rrEvent, "m.read");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2018, 2019 New Vector Ltd
|
Copyright 2018, 2019 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -346,13 +347,30 @@ Room.prototype.userMayUpgradeRoom = function(userId) {
|
|||||||
Room.prototype.getPendingEvents = function() {
|
Room.prototype.getPendingEvents = function() {
|
||||||
if (this._opts.pendingEventOrdering !== "detached") {
|
if (this._opts.pendingEventOrdering !== "detached") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Cannot call getPendingEventList with pendingEventOrdering == " +
|
"Cannot call getPendingEvents with pendingEventOrdering == " +
|
||||||
this._opts.pendingEventOrdering);
|
this._opts.pendingEventOrdering);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._pendingEventList;
|
return this._pendingEventList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the pending event list contains a given event by ID.
|
||||||
|
*
|
||||||
|
* @param {string} eventId The event ID to check for.
|
||||||
|
* @return {boolean}
|
||||||
|
* @throws If <code>opts.pendingEventOrdering</code> was not 'detached'
|
||||||
|
*/
|
||||||
|
Room.prototype.hasPendingEvent = function(eventId) {
|
||||||
|
if (this._opts.pendingEventOrdering !== "detached") {
|
||||||
|
throw new Error(
|
||||||
|
"Cannot call hasPendingEvent with pendingEventOrdering == " +
|
||||||
|
this._opts.pendingEventOrdering);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._pendingEventList.some(event => event.getId() === eventId);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the live unfiltered timeline for this room.
|
* Get the live unfiltered timeline for this room.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user