Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active private receipt support #1109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/app/organisms/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import settings from '../../../client/state/settings';
import navigation from '../../../client/state/navigation';
import {
toggleSystemTheme, toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents,
toggleNotifications, toggleNotificationSounds,
toggleNotifications, toggleNotificationSounds, toggleReadReceipts,
} from '../../../client/action/settings';
import { usePermission } from '../../hooks/usePermission';

Expand Down Expand Up @@ -44,6 +44,10 @@ import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
import CinnySVG from '../../../../public/res/svg/cinny.svg';
import { confirmDialog } from '../../molecules/confirm-dialog/ConfirmDialog';

let capabilities = {
privateReadReceipts: false,
};

function AppearanceSection() {
const [, updateState] = useState({});

Expand Down Expand Up @@ -188,6 +192,7 @@ function EmojiSection() {
}

function SecuritySection() {
const [, updateState] = useState({});
return (
<div className="settings-security">
<div className="settings-security__card">
Expand Down Expand Up @@ -217,6 +222,33 @@ function SecuritySection() {
)}
/>
</div>
<div className="settings-security__card">
<MenuHeader>Presence</MenuHeader>
<SettingTile
title="Send read receipts"
options={(
<Toggle
/** Always allow to switch receipts on. */
disabled={!capabilities.privateReadReceipts && settings.sendReadReceipts}
isActive={settings.sendReadReceipts}
onToggle={() => { toggleReadReceipts(); updateState({}); }}
/>
)}
content={(
<>
<Text variant="b3">
Let other people know what messages you read.
</Text>
{!capabilities.privateReadReceipts
&& (
<Text variant="b3">
Making your read receipts private requires a compatible homeserver.
</Text>
)}
</>
)}
/>
</div>
</div>
);
}
Expand Down Expand Up @@ -320,9 +352,20 @@ function useWindowToggle(setSelectedTab) {
return [isOpen, requestClose];
}

async function getCapabilities() {
const mx = initMatrix.matrixClient;
capabilities = {
privateReadReceipts: (await (Promise.all([
mx.doesServerSupportUnstableFeature('org.matrix.msc2285.stable'),
mx.isVersionSupported('v1.4')])
)).some((res) => res === true),
};
}

function Settings() {
const [selectedTab, setSelectedTab] = useState(tabItems[0]);
const [isOpen, requestClose] = useWindowToggle(setSelectedTab);
useEffect(getCapabilities, []);

const handleTabChange = (tabItem) => setSelectedTab(tabItem);
const handleLogout = async () => {
Expand Down
9 changes: 8 additions & 1 deletion src/client/action/notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import initMatrix from '../initMatrix';
import settings from '../state/settings';

const ReceiptType = {
Read: 'm.read',
ReadPrivate: 'm.read.private',
};
Comment on lines +4 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type exists in matrix-js-sdk/lib/@types/read_receipts, why not just use that?


// eslint-disable-next-line import/prefer-default-export
export async function markAsRead(roomId) {
Expand All @@ -22,5 +28,6 @@ export async function markAsRead(roomId) {
const latestEvent = getLatestValidEvent();
if (latestEvent === null) return;

await mx.sendReadReceipt(latestEvent);
const receiptType = settings.sendReadReceipts ? ReceiptType.Read : ReceiptType.ReadPrivate;
await mx.sendReadReceipt(latestEvent, receiptType);
}
6 changes: 6 additions & 0 deletions src/client/action/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ export function toggleNotificationSounds() {
type: cons.actions.settings.TOGGLE_NOTIFICATION_SOUNDS,
});
}

export function toggleReadReceipts() {
appDispatcher.dispatch({
type: cons.actions.settings.TOGGLE_READ_RECEIPTS,
});
}
2 changes: 2 additions & 0 deletions src/client/state/cons.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const cons = {
TOGGLE_NICKAVATAR_EVENT: 'TOGGLE_NICKAVATAR_EVENT',
TOGGLE_NOTIFICATIONS: 'TOGGLE_NOTIFICATIONS',
TOGGLE_NOTIFICATION_SOUNDS: 'TOGGLE_NOTIFICATION_SOUNDS',
TOGGLE_READ_RECEIPTS: 'TOGGLE_READ_RECEIPTS',
},
},
events: {
Expand Down Expand Up @@ -150,6 +151,7 @@ const cons = {
NICKAVATAR_EVENTS_TOGGLED: 'NICKAVATAR_EVENTS_TOGGLED',
NOTIFICATIONS_TOGGLED: 'NOTIFICATIONS_TOGGLED',
NOTIFICATION_SOUNDS_TOGGLED: 'NOTIFICATION_SOUNDS_TOGGLED',
READ_RECEIPTS_TOGGLED: 'READ_RECEIPTS_TOGGLED',
},
},
};
Expand Down
15 changes: 15 additions & 0 deletions src/client/state/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Settings extends EventEmitter {
this.hideNickAvatarEvents = this.getHideNickAvatarEvents();
this._showNotifications = this.getShowNotifications();
this.isNotificationSounds = this.getIsNotificationSounds();
this.sendReadReceipts = this.getSendReadReceipts();

this.darkModeQueryList = window.matchMedia('(prefers-color-scheme: dark)');

Expand Down Expand Up @@ -153,6 +154,15 @@ class Settings extends EventEmitter {
return settings.isNotificationSounds;
}

getSendReadReceipts() {
if (typeof this.sendReadReceipts === 'boolean') return this.sendReadReceipts;

const settings = getSettings();
if (settings === null) return true;
if (typeof settings.sendReadReceipts === 'undefined') return true;
return settings.sendReadReceipts;
}

setter(action) {
const actions = {
[cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => {
Expand Down Expand Up @@ -192,6 +202,11 @@ class Settings extends EventEmitter {
setSettings('isNotificationSounds', this.isNotificationSounds);
this.emit(cons.events.settings.NOTIFICATION_SOUNDS_TOGGLED, this.isNotificationSounds);
},
[cons.actions.settings.TOGGLE_READ_RECEIPTS]: () => {
this.sendReadReceipts = !this.sendReadReceipts;
setSettings('sendReadReceipts', this.sendReadReceipts);
this.emit(cons.events.settings.READ_RECEIPTS_TOGGLED, this.sendReadReceipts);
},
};

actions[action.type]?.();
Expand Down
Loading