Implement changes to MSC2285 (private read receipts) (#7993)

This commit is contained in:
Šimon Brandner 2022-05-06 21:32:47 +02:00 committed by GitHub
parent eca8494c66
commit 99543a7858
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 9 deletions

View file

@ -23,6 +23,7 @@ import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Relations } from "matrix-js-sdk/src/models/relations";
import { logger } from 'matrix-js-sdk/src/logger';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon';
import shouldHideEvent from '../../shouldHideEvent';
@ -847,7 +848,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
}
const receipts: IReadReceiptProps[] = [];
room.getReceiptsForEvent(event).forEach((r) => {
if (!r.userId || r.type !== "m.read" || r.userId === myUserId) {
if (!r.userId || ![ReceiptType.Read, ReceiptType.ReadPrivate].includes(r.type) || r.userId === myUserId) {
return; // ignore non-read receipts and receipts from self.
}
if (MatrixClientPeg.get().isUserIgnored(r.userId)) {

View file

@ -28,6 +28,7 @@ import { debounce } from 'lodash';
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { Thread } from 'matrix-js-sdk/src/models/thread';
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import SettingsStore from "../../settings/SettingsStore";
import { Layout } from "../../settings/enums/Layout";
@ -862,14 +863,14 @@ class TimelinePanel extends React.Component<IProps, IState> {
MatrixClientPeg.get().setRoomReadMarkers(
roomId,
this.state.readMarkerEventId,
lastReadEvent, // Could be null, in which case no RR is sent
{ hidden: hiddenRR },
hiddenRR ? null : lastReadEvent, // Could be null, in which case no RR is sent
lastReadEvent, // Could be null, in which case no private RR is sent
).catch((e) => {
// /read_markers API is not implemented on this HS, fallback to just RR
if (e.errcode === 'M_UNRECOGNIZED' && lastReadEvent) {
return MatrixClientPeg.get().sendReadReceipt(
lastReadEvent,
{},
hiddenRR ? ReceiptType.ReadPrivate : ReceiptType.Read,
).catch((e) => {
logger.error(e);
this.lastRRSentEventId = undefined;

View file

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
/**
@ -29,9 +30,8 @@ export function findReadReceiptFromUserId(receiptEvent: MatrixEvent, userId: str
const receiptKeys = Object.keys(receiptEvent.getContent());
for (let i = 0; i < receiptKeys.length; ++i) {
const rcpt = receiptEvent.getContent()[receiptKeys[i]];
if (rcpt['m.read'] && rcpt['m.read'][userId]) {
return rcpt;
}
if (rcpt[ReceiptType.Read]?.[userId]) return rcpt;
if (rcpt[ReceiptType.ReadPrivate]?.[userId]) return rcpt;
}
return null;

View file

@ -16,6 +16,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
/**
* Determines if a read receipt update event includes the client's own user.
@ -26,8 +27,12 @@ import { MatrixClient } from "matrix-js-sdk/src/client";
export function readReceiptChangeIsFor(event: MatrixEvent, client: MatrixClient): boolean {
const myUserId = client.getUserId();
for (const eventId of Object.keys(event.getContent())) {
const receiptUsers = Object.keys(event.getContent()[eventId]['m.read'] || {});
if (receiptUsers.includes(myUserId)) {
const readReceiptUsers = Object.keys(event.getContent()[eventId][ReceiptType.Read] || {});
if (readReceiptUsers.includes(myUserId)) {
return true;
}
const readPrivateReceiptUsers = Object.keys(event.getContent()[eventId][ReceiptType.ReadPrivate] || {});
if (readPrivateReceiptUsers.includes(myUserId)) {
return true;
}
}