Fix Mark all as read
in settings (#12205)
* Fix `Mark all as read` in settings * Update tests
This commit is contained in:
parent
40ee1bb400
commit
8299abd344
6 changed files with 16 additions and 11 deletions
|
@ -74,6 +74,9 @@ export function doesRoomHaveUnreadMessages(room: Room, includeThreads: boolean):
|
||||||
}
|
}
|
||||||
|
|
||||||
function doesTimelineHaveUnreadMessages(room: Room, timeline: Array<MatrixEvent>): boolean {
|
function doesTimelineHaveUnreadMessages(room: Room, timeline: Array<MatrixEvent>): boolean {
|
||||||
|
// The room is a space, let's ignore it
|
||||||
|
if (room.isSpaceRoom()) return false;
|
||||||
|
|
||||||
const myUserId = room.client.getSafeUserId();
|
const myUserId = room.client.getSafeUserId();
|
||||||
const latestImportantEventId = findLatestImportantEvent(room.client, timeline)?.getId();
|
const latestImportantEventId = findLatestImportantEvent(room.client, timeline)?.getId();
|
||||||
if (latestImportantEventId) {
|
if (latestImportantEventId) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ import {
|
||||||
import { Caption } from "../typography/Caption";
|
import { Caption } from "../typography/Caption";
|
||||||
import { SettingsSubsectionHeading } from "./shared/SettingsSubsectionHeading";
|
import { SettingsSubsectionHeading } from "./shared/SettingsSubsectionHeading";
|
||||||
import SettingsSubsection from "./shared/SettingsSubsection";
|
import SettingsSubsection from "./shared/SettingsSubsection";
|
||||||
|
import { doesRoomHaveUnreadMessages } from "../../../Unread";
|
||||||
|
|
||||||
// TODO: this "view" component still has far too much application logic in it,
|
// TODO: this "view" component still has far too much application logic in it,
|
||||||
// which should be factored out to other files.
|
// which should be factored out to other files.
|
||||||
|
@ -739,7 +740,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
||||||
category === RuleClass.VectorOther &&
|
category === RuleClass.VectorOther &&
|
||||||
MatrixClientPeg.safeGet()
|
MatrixClientPeg.safeGet()
|
||||||
.getRooms()
|
.getRooms()
|
||||||
.some((r) => r.getUnreadNotificationCount() > 0)
|
.some((r) => doesRoomHaveUnreadMessages(r, true))
|
||||||
) {
|
) {
|
||||||
clearNotifsButton = (
|
clearNotifsButton = (
|
||||||
<AccessibleButton
|
<AccessibleButton
|
||||||
|
|
|
@ -34,7 +34,8 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
|
||||||
public async start(): Promise<void> {
|
public async start(): Promise<void> {
|
||||||
this.dispatcherRef = this.dispatcher.register(this.onAction);
|
this.dispatcherRef = this.dispatcher.register(this.onAction);
|
||||||
|
|
||||||
const matrixClient = MatrixClientPeg.get();
|
// MatrixClientPeg can be undefined in tests because of circular dependencies with other stores
|
||||||
|
const matrixClient = MatrixClientPeg?.get();
|
||||||
if (matrixClient) {
|
if (matrixClient) {
|
||||||
this.matrixClient = matrixClient;
|
this.matrixClient = matrixClient;
|
||||||
await this.onReady();
|
await this.onReady();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import { IndicatorIcon } from "@vector-im/compound-web";
|
||||||
|
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
import { NotificationLevel } from "../stores/notifications/NotificationLevel";
|
import { NotificationLevel } from "../stores/notifications/NotificationLevel";
|
||||||
|
import { doesRoomHaveUnreadMessages } from "../Unread";
|
||||||
|
|
||||||
export const deviceNotificationSettingsKeys = [
|
export const deviceNotificationSettingsKeys = [
|
||||||
"notificationsEnabled",
|
"notificationsEnabled",
|
||||||
|
@ -105,7 +106,7 @@ export async function clearRoomNotification(room: Room, client: MatrixClient): P
|
||||||
*/
|
*/
|
||||||
export function clearAllNotifications(client: MatrixClient): Promise<Array<{} | undefined>> {
|
export function clearAllNotifications(client: MatrixClient): Promise<Array<{} | undefined>> {
|
||||||
const receiptPromises = client.getRooms().reduce((promises: Array<Promise<{} | undefined>>, room: Room) => {
|
const receiptPromises = client.getRooms().reduce((promises: Array<Promise<{} | undefined>>, room: Room) => {
|
||||||
if (room.getUnreadNotificationCount() > 0) {
|
if (doesRoomHaveUnreadMessages(room, true)) {
|
||||||
const promise = clearRoomNotification(room, client);
|
const promise = clearRoomNotification(room, client);
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,6 +421,11 @@ describe("Unread", () => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns false for space", () => {
|
||||||
|
jest.spyOn(room, "isSpaceRoom").mockReturnValue(true);
|
||||||
|
expect(doesRoomHaveUnreadMessages(room, false)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("doesRoomOrThreadHaveUnreadMessages()", () => {
|
describe("doesRoomOrThreadHaveUnreadMessages()", () => {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {
|
||||||
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
Room,
|
Room,
|
||||||
NotificationCountType,
|
|
||||||
PushRuleActionName,
|
PushRuleActionName,
|
||||||
TweakName,
|
TweakName,
|
||||||
ConditionKind,
|
ConditionKind,
|
||||||
|
@ -31,7 +30,7 @@ import {
|
||||||
ThreepidMedium,
|
ThreepidMedium,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||||
import { act, fireEvent, getByTestId, render, screen, waitFor, within } from "@testing-library/react";
|
import { act, fireEvent, getByTestId, render, screen, within } from "@testing-library/react";
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
|
@ -900,8 +899,7 @@ describe("<Notifications />", () => {
|
||||||
user: "@alice:example.org",
|
user: "@alice:example.org",
|
||||||
ts: 1,
|
ts: 1,
|
||||||
});
|
});
|
||||||
room.addLiveEvents([message]);
|
await room.addLiveEvents([message]);
|
||||||
room.setUnreadNotificationCount(NotificationCountType.Total, 1);
|
|
||||||
|
|
||||||
const { container } = await getComponentAndWait();
|
const { container } = await getComponentAndWait();
|
||||||
const clearNotificationEl = getByTestId(container, "clear-notifications");
|
const clearNotificationEl = getByTestId(container, "clear-notifications");
|
||||||
|
@ -910,10 +908,6 @@ describe("<Notifications />", () => {
|
||||||
|
|
||||||
expect(clearNotificationEl.className).toContain("mx_AccessibleButton_disabled");
|
expect(clearNotificationEl.className).toContain("mx_AccessibleButton_disabled");
|
||||||
expect(mockClient.sendReadReceipt).toHaveBeenCalled();
|
expect(mockClient.sendReadReceipt).toHaveBeenCalled();
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(clearNotificationEl).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue