mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 09:46:09 +03:00
Implement changes to MSC2285 (private read receipts) (#7993)
This commit is contained in:
parent
eca8494c66
commit
99543a7858
4 changed files with 16 additions and 9 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue