Skip to content

Commit 3b6fd54

Browse files
authored
Add partial MSC4459 support and refactor related code (#730)
### Description partial implementation of [MSC4459](matrix-org/matrix-spec-proposals#4459) Currently only sending the data and not rendering anything Partially #729 #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: No AI used
2 parents f44835d + 4f5f6e6 commit 3b6fd54

37 files changed

Lines changed: 370 additions & 105 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
# add initial support for sending discoverable emojis and sticker

src/app/components/create-room/AdditionalCreatorInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717
} from 'folds';
1818
import { isKeyHotkey } from 'is-hotkey';
1919
import FocusTrap from 'focus-trap-react';
20+
import { getMxIdServer } from '$utils/mxIdHelper';
2021
import type { ChangeEventHandler, KeyboardEventHandler, MouseEventHandler } from 'react';
2122
import { useMemo, useState } from 'react';
22-
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
23+
import { getMxIdLocalPart, isUserId } from '$utils/matrix';
2324
import { useDirectUsers } from '$hooks/useDirectUsers';
2425
import { useMatrixClient } from '$hooks/useMatrixClient';
2526
import { stopPropagation } from '$utils/keyboard';

src/app/components/create-room/CreateRoomAliasInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { useCallback, useEffect, useRef, useState } from 'react';
33
import { MatrixError } from '$types/matrix-sdk';
44
import { Box, color, Icon, Icons, Input, Spinner, Text, toRem } from 'folds';
55
import { isKeyHotkey } from 'is-hotkey';
6-
import { getMxIdServer } from '$utils/matrix';
76
import { useMatrixClient } from '$hooks/useMatrixClient';
87
import { replaceSpaceWithDash } from '$utils/common';
98
import type { AsyncState } from '$hooks/useAsyncCallback';
109
import { AsyncStatus, useAsync } from '$hooks/useAsyncCallback';
1110
import { useDebounce } from '$hooks/useDebounce';
11+
import { getMxIdServer } from '$utils/mxIdHelper';
1212

1313
export function CreateRoomAliasInput({ disabled }: { disabled?: boolean }) {
1414
const mx = useMatrixClient();

src/app/components/create-room/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { JoinRule, RestrictedAllowType, EventType, RoomType } from '$types/matri
99

1010
import type { StateEvents } from '$types/matrix-sdk';
1111
import { getViaServers } from '$plugins/via-servers';
12-
import { getMxIdServer } from '$utils/matrix';
12+
import { getMxIdServer } from '$utils/mxIdHelper';
1313
import { CreateRoomAccess } from './types';
1414

1515
export const createRoomCreationContent = (

src/app/components/editor/autocomplete/RoomMentionAutocomplete.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { useAtomValue } from 'jotai';
99

1010
import { getDirectRoomAvatarUrl } from '$utils/room';
1111
import { useMatrixClient } from '$hooks/useMatrixClient';
12-
import { getMxIdServer, isRoomAlias } from '$utils/matrix';
13-
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
12+
import { isRoomAlias } from '$utils/matrix';
1413
import { useAsyncSearch } from '$hooks/useAsyncSearch';
14+
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
1515
import { onTabPress } from '$utils/keyboard';
1616
import { useKeyDown } from '$hooks/useKeyDown';
1717
import { mDirectAtom } from '$state/mDirectList';
@@ -20,6 +20,7 @@ import { factoryRoomIdByActivity } from '$utils/sort';
2020
import { RoomAvatar, RoomIcon } from '$components/room-avatar';
2121
import { getViaServers } from '$plugins/via-servers';
2222
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
23+
import { getMxIdServer } from '$utils/mxIdHelper';
2324
import { AutocompleteMenu } from './AutocompleteMenu';
2425
import type { AutocompleteQuery } from './autocompleteQuery';
2526

src/app/components/editor/autocomplete/UserMentionAutocomplete.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import type { SearchItemStrGetter, UseAsyncSearchOptions } from '$hooks/useAsync
1111
import { useAsyncSearch } from '$hooks/useAsyncSearch';
1212
import { onTabPress } from '$utils/keyboard';
1313
import { useKeyDown } from '$hooks/useKeyDown';
14-
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
14+
import { getMxIdLocalPart, isUserId } from '$utils/matrix';
1515
import { getMemberDisplayName, getMemberSearchStr } from '$utils/room';
1616
import { UserAvatar } from '$components/user-avatar';
1717
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
1818

1919
import { useAtomValue } from 'jotai';
2020
import { nicknamesAtom } from '$state/nicknames';
2121
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
22+
import { getMxIdServer } from '$utils/mxIdHelper';
2223
import { AutocompleteMenu } from './AutocompleteMenu';
2324
import type { AutocompleteQuery } from './autocompleteQuery';
2425
import { KnownMembership } from '$types/matrix-sdk';

src/app/components/invite-user-prompt/InviteUserPrompt.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import { isKeyHotkey } from 'is-hotkey';
2727
import FocusTrap from 'focus-trap-react';
2828
import { stopPropagation } from '$utils/keyboard';
2929
import { useDirectUsers } from '$hooks/useDirectUsers';
30-
import { getMxIdLocalPart, getMxIdServer, isUserId } from '$utils/matrix';
31-
30+
import { getMxIdLocalPart, isUserId } from '$utils/matrix';
3231
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
3332
import { useAsyncSearch } from '$hooks/useAsyncSearch';
3433
import { highlightText, makeHighlightRegex } from '$plugins/react-custom-html-parser';
3534
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
3635
import { useMatrixClient } from '$hooks/useMatrixClient';
3736
import { BreakWord } from '$styles/Text.css';
3837
import { useAlive } from '$hooks/useAlive';
38+
import { getMxIdServer } from '$utils/mxIdHelper';
3939
import { KnownMembership } from '$types/matrix-sdk';
4040

4141
const SEARCH_OPTIONS: UseAsyncSearchOptions = {

src/app/components/message/modals/MessageForward.tsx

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ import {
1818
} from 'folds';
1919
import { useAtomValue, useSetAtom } from 'jotai';
2020
import type { MatrixEvent, Room } from '$types/matrix-sdk';
21-
import { JoinRule, EventType } from '$types/matrix-sdk';
2221
import { useEffect, useMemo, useState } from 'react';
2322
import { allRoomsAtom } from '$state/room-list/roomList';
2423
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
2524
import { factoryRoomIdByActivity } from '$utils/sort';
2625
import * as css from '$features/room/message/styles.css';
2726
import { sanitizeCustomHtml, sanitizeText } from '$utils/sanitize';
28-
import { getStateEvents } from '$utils/room';
29-
3027
import { createDebugLogger } from '$utils/debugLogger';
3128
import * as Sentry from '@sentry/react';
29+
import { isRoomPrivate } from '$utils/roomVisibility';
3230

3331
const debugLog = createDebugLogger('MessageForward');
3432

@@ -112,28 +110,6 @@ export function MessageForwardInternal({
112110
const [isForwarding, setIsForwarding] = useState(false);
113111
const [forwardError, setForwardError] = useState<string | null>(null);
114112
const [targetRoomId, setTargetRoomId] = useState<string | null>(null);
115-
116-
// detect if it's a public room or not
117-
const joinRule = room.getJoinRule() ?? JoinRule.Invite;
118-
119-
const parentSpaceIds = getStateEvents(room, EventType.SpaceParent)
120-
.map((e) => e.getStateKey())
121-
.filter((id): id is string => Boolean(id));
122-
123-
const isInPublicSpace = parentSpaceIds.some((spaceId) => {
124-
const space = mx.getRoom(spaceId);
125-
return Boolean(space?.isSpaceRoom()) && space?.getJoinRule() === JoinRule.Public;
126-
});
127-
128-
// A room is private if its join rule is Invite (or other non-public/non-knock/non-restricted),
129-
// or it's Restricted but NOT inside a public space.
130-
const isPrivate =
131-
joinRule === JoinRule.Invite ||
132-
(joinRule === JoinRule.Restricted && !isInPublicSpace) ||
133-
(joinRule !== JoinRule.Public &&
134-
joinRule !== JoinRule.Knock &&
135-
joinRule !== JoinRule.Restricted);
136-
137113
const allRooms = useAtomValue(allRoomsAtom);
138114
const allJoinedRooms = useAllJoinedRoomsSet();
139115
const getRoom = useGetRoom(allJoinedRooms);
@@ -191,7 +167,7 @@ export function MessageForwardInternal({
191167
: undefined;
192168

193169
const bodyModifText = `(Forwarded message from ${
194-
isPrivate ? 'a private room' : (getRoom(room.roomId)?.name ?? 'a room')
170+
isRoomPrivate(mx, room) ? 'a private room' : (getRoom(room.roomId)?.name ?? 'a room')
195171
})`;
196172

197173
let newBodyPlain = '';
@@ -230,7 +206,7 @@ export function MessageForwardInternal({
230206
delete baseContent['com.beeper.per_message_profile']; // remove per-message profile as that could confuse clients in the target room
231207
let content;
232208
// handle privacy stuff
233-
if (isPrivate) {
209+
if (isRoomPrivate(mx, room)) {
234210
// if the message is from a private room, we should strip any media or mentions to avoid leaking information to the target room
235211
// we can still include the original message content in the body of the message, so we'll just use a fallback text/plain content with the original message body
236212
content = {
@@ -271,7 +247,7 @@ export function MessageForwardInternal({
271247
sourceRoomId: room.roomId,
272248
targetRoomId: targetRoom.roomId,
273249
msgtype,
274-
isPrivate,
250+
isPrivate: isRoomPrivate(mx, room),
275251
});
276252
Sentry.metrics.count('sable.message.forward.attempt', 1, { attributes: { msgtype } });
277253
mx.sendEvent(targetRoom.roomId, null, eventType, content as unknown as SendEventContent)

src/app/components/user-profile/UserChips.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
Avatar,
2323
} from 'folds';
2424
import { useMatrixClient } from '$hooks/useMatrixClient';
25-
import { getMxIdServer } from '$utils/matrix';
2625
import { useCloseUserRoomProfile } from '$state/hooks/userRoomProfile';
2726
import { stopPropagation } from '$utils/keyboard';
2827
import { copyToClipboard } from '$utils/dom';
@@ -43,6 +42,7 @@ import { useNickname, useSetNickname } from '$hooks/useNickname';
4342
import { CutoutCard } from '$components/cutout-card';
4443
import { SettingTile } from '$components/setting-tile';
4544
import { RoomAvatar, RoomIcon } from '$components/room-avatar';
45+
import { getMxIdServer } from '$utils/mxIdHelper';
4646

4747
export function ServerChip({ server }: { server: string }) {
4848
const mx = useMatrixClient();

src/app/components/user-profile/UserRoomProfile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom';
55
import { useAtomValue } from 'jotai';
66
import type { Opts as LinkifyOpts } from 'linkifyjs';
77
import type { HTMLReactParserOptions } from 'html-react-parser';
8-
import { getMxIdServer, mxcUrlToHttp } from '$utils/matrix';
8+
import { mxcUrlToHttp } from '$utils/matrix';
99
import { getMemberAvatarMxc, getMemberDisplayName } from '$utils/room';
1010
import { useMatrixClient } from '$hooks/useMatrixClient';
1111
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
@@ -37,6 +37,7 @@ import { getSettings, settingsAtom } from '$state/settings';
3737
import { filterPronounsByLanguage } from '$utils/pronouns';
3838
import { useSetting } from '$state/hooks/settings';
3939
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
40+
import { getMxIdServer } from '$utils/mxIdHelper';
4041
import { TextViewerContent } from '$components/text-viewer';
4142
import { CreatorChip } from './CreatorChip';
4243
import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration';

0 commit comments

Comments
 (0)