Skip to content

Commit 96df140

Browse files
authored
Improve-auth-media (cinnyapp#1933)
* fix set power level broken after sdk update * add media authentication hook * fix service worker types * fix service worker not working in dev mode * fix env mode check when registering sw
1 parent 4dfce32 commit 96df140

38 files changed

+100
-124
lines changed

package-lock.json

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"@types/react-dom": "18.2.17",
9191
"@types/react-google-recaptcha": "2.1.8",
9292
"@types/sanitize-html": "2.9.0",
93-
"@types/serviceworker": "0.0.95",
9493
"@types/ua-parser-js": "0.7.36",
9594
"@typescript-eslint/eslint-plugin": "5.46.1",
9695
"@typescript-eslint/parser": "5.46.1",

src/app/components/editor/Elements.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useMatrixClient } from '../../hooks/useMatrixClient';
1414
import { getBeginCommand } from './utils';
1515
import { BlockType } from './types';
1616
import { mxcUrlToHttp } from '../../utils/matrix';
17-
import { useSpecVersions } from '../../hooks/useSpecVersions';
17+
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
1818

1919
// Put this at the start and end of an inline component to work around this Chromium bug:
2020
// https://bugs.chromium.org/p/chromium/issues/detail?id=1249405
@@ -78,8 +78,7 @@ function RenderEmoticonElement({
7878
children,
7979
}: { element: EmoticonElement } & RenderElementProps) {
8080
const mx = useMatrixClient();
81-
const { versions } = useSpecVersions();
82-
const useAuthentication = versions.includes('v1.11');
81+
const useAuthentication = useMediaAuthentication();
8382
const selected = useSelected();
8483
const focused = useFocused();
8584

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { IEmoji, emojis } from '../../../plugins/emoji';
1919
import { ExtendedPackImage, PackUsage } from '../../../plugins/custom-emoji';
2020
import { useKeyDown } from '../../../hooks/useKeyDown';
2121
import { mxcUrlToHttp } from '../../../utils/matrix';
22-
import { useSpecVersions } from '../../../hooks/useSpecVersions';
22+
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
2323

2424
type EmoticonCompleteHandler = (key: string, shortcode: string) => void;
2525

@@ -50,8 +50,7 @@ export function EmoticonAutocomplete({
5050
requestClose,
5151
}: EmoticonAutocompleteProps) {
5252
const mx = useMatrixClient();
53-
const { versions } = useSpecVersions();
54-
const useAuthentication = versions.includes('v1.11');
53+
const useAuthentication = useMediaAuthentication();
5554

5655
const imagePacks = useRelevantImagePacks(mx, PackUsage.Emoticon, imagePackRooms);
5756
const recentEmoji = useRecentEmoji(mx, 20);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useKeyDown } from '../../../hooks/useKeyDown';
1818
import { getMxIdLocalPart, getMxIdServer, validMxId } from '../../../utils/matrix';
1919
import { getMemberDisplayName, getMemberSearchStr } from '../../../utils/room';
2020
import { UserAvatar } from '../../user-avatar';
21-
import { useSpecVersions } from '../../../hooks/useSpecVersions';
21+
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
2222

2323
type MentionAutoCompleteHandler = (userId: string, name: string) => void;
2424

@@ -85,8 +85,7 @@ export function UserMentionAutocomplete({
8585
requestClose,
8686
}: UserMentionAutocompleteProps) {
8787
const mx = useMatrixClient();
88-
const { versions } = useSpecVersions();
89-
const useAuthentication = versions.includes('v1.11');
88+
const useAuthentication = useMediaAuthentication();
9089
const roomId: string = room.roomId!;
9190
const roomAliasOrId = room.getCanonicalAlias() || roomId;
9291
const members = useRoomMembers(mx, roomId);
@@ -147,7 +146,9 @@ export function UserMentionAutocomplete({
147146
) : (
148147
autoCompleteMembers.map((roomMember) => {
149148
const avatarMxcUrl = roomMember.getMxcAvatarUrl();
150-
const avatarUrl = avatarMxcUrl ? mx.mxcUrlToHttp(avatarMxcUrl, 32, 32, 'crop', undefined, false, useAuthentication) : undefined;
149+
const avatarUrl = avatarMxcUrl
150+
? mx.mxcUrlToHttp(avatarMxcUrl, 32, 32, 'crop', undefined, false, useAuthentication)
151+
: undefined;
151152
return (
152153
<MenuItem
153154
key={roomMember.userId}

src/app/components/emoji-board/EmojiBoard.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { useDebounce } from '../../hooks/useDebounce';
4949
import { useThrottle } from '../../hooks/useThrottle';
5050
import { addRecentEmoji } from '../../plugins/recent-emoji';
5151
import { mobileOrTablet } from '../../utils/user-agent';
52-
import { useSpecVersions } from '../../hooks/useSpecVersions';
52+
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
5353

5454
const RECENT_GROUP_ID = 'recent_group';
5555
const SEARCH_GROUP_ID = 'search_group';
@@ -650,8 +650,7 @@ export function EmojiBoard({
650650

651651
const setActiveGroupId = useSetAtom(activeGroupIdAtom);
652652
const mx = useMatrixClient();
653-
const { versions } = useSpecVersions();
654-
const useAuthentication = versions.includes('v1.11');
653+
const useAuthentication = useMediaAuthentication();
655654
const emojiGroupLabels = useEmojiGroupLabels();
656655
const emojiGroupIcons = useEmojiGroupIcons();
657656
const imagePacks = useRelevantImagePacks(mx, usage, imagePackRooms);

src/app/components/event-readers/EventReaders.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as css from './EventReaders.css';
2121
import { useMatrixClient } from '../../hooks/useMatrixClient';
2222
import { openProfileViewer } from '../../../client/action/navigation';
2323
import { UserAvatar } from '../user-avatar';
24-
import { useSpecVersions } from '../../hooks/useSpecVersions';
24+
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
2525

2626
export type EventReadersProps = {
2727
room: Room;
@@ -31,8 +31,7 @@ export type EventReadersProps = {
3131
export const EventReaders = as<'div', EventReadersProps>(
3232
({ className, room, eventId, requestClose, ...props }, ref) => {
3333
const mx = useMatrixClient();
34-
const { versions } = useSpecVersions();
35-
const useAuthentication = versions.includes('v1.11');
34+
const useAuthentication = useMediaAuthentication();
3635
const latestEventReaders = useRoomEventReaders(room, eventId);
3736

3837
const getName = (userId: string) =>

src/app/components/message/content/AudioContent.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { useThrottle } from '../../../hooks/useThrottle';
1919
import { secondsToMinutesAndSeconds } from '../../../utils/common';
2020
import { mxcUrlToHttp } from '../../../utils/matrix';
21-
import { useSpecVersions } from '../../../hooks/useSpecVersions';
21+
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
2222

2323
const PLAY_TIME_THROTTLE_OPS = {
2424
wait: 500,
@@ -46,8 +46,7 @@ export function AudioContent({
4646
renderMediaControl,
4747
}: AudioContentProps) {
4848
const mx = useMatrixClient();
49-
const { versions } = useSpecVersions();
50-
const useAuthentication = versions.includes('v1.11');
49+
const useAuthentication = useMediaAuthentication();
5150

5251
const [srcState, loadSrc] = useAsyncCallback(
5352
useCallback(

src/app/components/message/content/FileContent.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import * as css from './style.css';
3232
import { stopPropagation } from '../../../utils/keyboard';
3333
import { mxcUrlToHttp } from '../../../utils/matrix';
34-
import { useSpecVersions } from '../../../hooks/useSpecVersions';
34+
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
3535

3636
const renderErrorButton = (retry: () => void, text: string) => (
3737
<TooltipProvider
@@ -77,8 +77,7 @@ type ReadTextFileProps = {
7777
};
7878
export function ReadTextFile({ body, mimeType, url, encInfo, renderViewer }: ReadTextFileProps) {
7979
const mx = useMatrixClient();
80-
const { versions } = useSpecVersions();
81-
const useAuthentication = versions.includes('v1.11');
80+
const useAuthentication = useMediaAuthentication();
8281
const [textViewer, setTextViewer] = useState(false);
8382

8483
const loadSrc = useCallback(
@@ -170,8 +169,7 @@ export type ReadPdfFileProps = {
170169
};
171170
export function ReadPdfFile({ body, mimeType, url, encInfo, renderViewer }: ReadPdfFileProps) {
172171
const mx = useMatrixClient();
173-
const { versions } = useSpecVersions();
174-
const useAuthentication = versions.includes('v1.11');
172+
const useAuthentication = useMediaAuthentication();
175173
const [pdfViewer, setPdfViewer] = useState(false);
176174

177175
const [pdfState, loadPdf] = useAsyncCallback(
@@ -246,8 +244,7 @@ export type DownloadFileProps = {
246244
};
247245
export function DownloadFile({ body, mimeType, url, info, encInfo }: DownloadFileProps) {
248246
const mx = useMatrixClient();
249-
const { versions } = useSpecVersions();
250-
const useAuthentication = versions.includes('v1.11');
247+
const useAuthentication = useMediaAuthentication();
251248

252249
const [downloadState, download] = useAsyncCallback(
253250
useCallback(async () => {

src/app/components/message/content/ImageContent.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { bytesToSize } from '../../../utils/common';
2828
import { FALLBACK_MIMETYPE } from '../../../utils/mimeTypes';
2929
import { stopPropagation } from '../../../utils/keyboard';
3030
import { mxcUrlToHttp } from '../../../utils/matrix';
31-
import { useSpecVersions } from '../../../hooks/useSpecVersions';
31+
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
3232

3333
type RenderViewerProps = {
3434
src: string;
@@ -71,8 +71,7 @@ export const ImageContent = as<'div', ImageContentProps>(
7171
ref
7272
) => {
7373
const mx = useMatrixClient();
74-
const { versions } = useSpecVersions();
75-
const useAuthentication = versions.includes('v1.11');
74+
const useAuthentication = useMediaAuthentication();
7675
const blurHash = info?.[MATRIX_BLUR_HASH_PROPERTY_NAME];
7776

7877
const [load, setLoad] = useState(false);

0 commit comments

Comments
 (0)