performance improvements that may or may not work
This commit is contained in:
1 parent
48fb8686cd
commit
76a29c41fc
12 files changed
+129
-128
No files matched your search
@@ -1,5 +1,9 @@
|
||||
# Sable Client Changelog
|
||||
|
||||
## Version 1.1.4
|
||||
|
||||
- Various performance improvements
|
||||
|
||||
## Version 1.1.3
|
||||
|
||||
_skipped a number since lots of updates :3_
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "sable",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sable",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@atlaskit/pragmatic-drag-and-drop": "1.1.6",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sable",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"description": "Yet another matrix client fork",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
|
||||
@@ -86,6 +86,8 @@ export const MessageBase = recipe({
|
||||
marginTop: SpacingVar,
|
||||
padding: `${config.space.S100} ${config.space.S200} ${config.space.S100} ${config.space.S400}`,
|
||||
borderRadius: `0 ${config.radii.R400} ${config.radii.R400} 0`,
|
||||
minHeight: toRem(16),
|
||||
contain: 'layout',
|
||||
},
|
||||
],
|
||||
variants: {
|
||||
|
||||
@@ -29,7 +29,7 @@ import classNames from 'classnames';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Editor } from 'slate';
|
||||
import to from 'await-to-js';
|
||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { as, Badge, Box, Chip, color, config, ContainerColor, Icon, Icons, Line, Scroll, Text, toRem, } from 'folds';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
@@ -238,7 +238,7 @@ type RoomTimelineProps = {
|
||||
editor: Editor;
|
||||
};
|
||||
|
||||
const PAGINATION_LIMIT = 40;
|
||||
const PAGINATION_LIMIT = 60;
|
||||
|
||||
type Timeline = {
|
||||
linkedTimelines: EventTimeline[];
|
||||
@@ -471,7 +471,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
const canPinEvent = permissions.stateEvent(StateEvent.RoomPinnedEvents, mx.getSafeUserId());
|
||||
const [editId, setEditId] = useState<string>();
|
||||
|
||||
const [globalProfiles] = useAtom(profilesCacheAtom);
|
||||
const globalProfiles = useAtomValue(profilesCacheAtom);
|
||||
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
const unread = useRoomUnread(room.roomId, roomToUnreadAtom);
|
||||
@@ -559,7 +559,18 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
count: eventsLength,
|
||||
limit: PAGINATION_LIMIT,
|
||||
range: timeline.range,
|
||||
onRangeChange: useCallback((r) => setTimeline((cs) => ({ ...cs, range: r })), []),
|
||||
onRangeChange: useCallback((newRange) => {
|
||||
setTimeline((currentTimeline) => {
|
||||
const deltaStart = Math.abs(currentTimeline.range.start - newRange.start);
|
||||
const deltaEnd = Math.abs(currentTimeline.range.end - newRange.end);
|
||||
|
||||
if (deltaStart < 3 && deltaEnd < 3) {
|
||||
return currentTimeline;
|
||||
}
|
||||
|
||||
return { ...currentTimeline, range: newRange };
|
||||
});
|
||||
}, []),
|
||||
getScrollElement,
|
||||
getItemElement: useCallback(
|
||||
(index: number) =>
|
||||
|
||||
@@ -38,6 +38,7 @@ import { useHover, useFocusWithin } from 'react-aria';
|
||||
import { MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
|
||||
import classNames from 'classnames';
|
||||
import parse from 'html-react-parser';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { RoomPinnedEventsEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import {
|
||||
@@ -92,6 +93,9 @@ import { useBlobCache } from '../../../hooks/useBlobCache';
|
||||
|
||||
export type ReactionHandler = (keyOrMxc: string, shortcode: string) => void;
|
||||
|
||||
const MemoizedBody = React.memo(({ children }: { children: ReactNode }) => {
|
||||
return <>{children}</>;
|
||||
});
|
||||
type MessageQuickReactionsProps = {
|
||||
onReaction: ReactionHandler;
|
||||
};
|
||||
@@ -693,6 +697,7 @@ export type MessageProps = {
|
||||
hour24Clock: boolean;
|
||||
dateFormatString: string;
|
||||
senderId: string;
|
||||
content?: string;
|
||||
};
|
||||
|
||||
function useMobileDoubleTap(callback: () => void, delay = 300) {
|
||||
@@ -910,6 +915,10 @@ function MessageInternal(
|
||||
</AvatarBase>
|
||||
);
|
||||
|
||||
const stableContent = useMemo(() => {
|
||||
return mEvent.getContent().body || '';
|
||||
}, [mEvent]);
|
||||
|
||||
const msgContentJSX = (
|
||||
<Box direction="Column" alignSelf="Start" style={{ maxWidth: '100%' }}>
|
||||
{reply}
|
||||
@@ -926,7 +935,9 @@ function MessageInternal(
|
||||
onCancel={() => onEditId()}
|
||||
/>
|
||||
) : (
|
||||
children
|
||||
<MemoizedBody key={stableContent}>
|
||||
{children}
|
||||
</MemoizedBody>
|
||||
)}
|
||||
{reactions}
|
||||
</Box>
|
||||
|
||||
@@ -46,7 +46,7 @@ export function About({ requestClose }: AboutProps) {
|
||||
<Box direction="Column" gap="100">
|
||||
<Box gap="100" alignItems="End">
|
||||
<Text size="H3">Sable</Text>
|
||||
<Text size="T200">v1.1.3</Text>
|
||||
<Text size="T200">v1.1.4</Text>
|
||||
</Box>
|
||||
<Text>Yet another matrix client fork(ed from cinny).</Text>
|
||||
</Box>
|
||||
|
||||
@@ -1,34 +1,19 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { EventTimeline, Room } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { usePowerLevels } from './usePowerLevels';
|
||||
import { useRoomCreators } from './useRoomCreators';
|
||||
import { useAccessiblePowerTagColors, useGetMemberPowerTag } from './useMemberPowerTag'; // Added useMemberPowerTag
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import colorMXID from '../../util/colorMXID';
|
||||
import { useAccessiblePowerTagColors, useGetMemberPowerTag } from './useMemberPowerTag';
|
||||
import { useRoomCreatorsTag } from './useRoomCreatorsTag';
|
||||
import { usePowerLevelTags } from './usePowerLevelTags';
|
||||
import { useTheme } from './useTheme';
|
||||
import { useUserProfile } from './useUserProfile';
|
||||
|
||||
const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c);
|
||||
const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32);
|
||||
|
||||
export function useSableCosmetics(userId: string, room: Room) {
|
||||
const mx = useMatrixClient();
|
||||
const theme = useTheme();
|
||||
|
||||
const profile = useUserProfile(userId);
|
||||
|
||||
const [legacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
|
||||
const [renderGlobalColors] = useSetting(settingsAtom, 'renderGlobalNameColors');
|
||||
const profile = useUserProfile(userId, room);
|
||||
|
||||
const powerLevels = usePowerLevels(room);
|
||||
const creators = useRoomCreators(room);
|
||||
|
||||
const creatorsTag = useRoomCreatorsTag();
|
||||
const powerLevelTags = usePowerLevelTags(room, powerLevels);
|
||||
const getPowerTag = useGetMemberPowerTag(room, creators, powerLevels);
|
||||
@@ -42,70 +27,15 @@ export function useSableCosmetics(userId: string, room: Room) {
|
||||
return useMemo(() => {
|
||||
if (!room || !userId) return { color: undefined, font: undefined };
|
||||
|
||||
// fetch room/space states
|
||||
|
||||
const localColor = room?.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomCosmeticsColor, userId)
|
||||
?.getContent()?.color;
|
||||
|
||||
const localFont = room?.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomCosmeticsFont, userId)
|
||||
?.getContent()?.font;
|
||||
|
||||
const parents = room?.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.SpaceParent);
|
||||
|
||||
let spaceColor;
|
||||
let spaceFont;
|
||||
|
||||
// get space variables if applicable
|
||||
|
||||
if (parents && parents.length > 0) {
|
||||
const parentSpaceId = parents[0].getStateKey();
|
||||
const parentSpace = mx.getRoom(parentSpaceId);
|
||||
|
||||
spaceColor = parentSpace?.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomCosmeticsColor, userId)
|
||||
?.getContent()?.color;
|
||||
|
||||
spaceFont = parentSpace?.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomCosmeticsFont, userId)
|
||||
?.getContent()?.font;
|
||||
let finalColor = profile.resolvedColor;
|
||||
if (!finalColor) {
|
||||
const memberPowerTag = getPowerTag(userId);
|
||||
finalColor = memberPowerTag?.color ? accessibleTagColors?.get(memberPowerTag.color) : undefined;
|
||||
}
|
||||
|
||||
// global name color
|
||||
// show if its on, or the user is you
|
||||
const hasGlobalColor = profile?.nameColor && isValidHex(profile.nameColor);
|
||||
const isMe = userId === mx.getUserId();
|
||||
const validGlobal = (renderGlobalColors || isMe) && hasGlobalColor
|
||||
? profile.nameColor
|
||||
: undefined;
|
||||
|
||||
// resolve traditional fallbacks
|
||||
const memberPowerTag = getPowerTag(userId);
|
||||
const tagColor = memberPowerTag?.color ? accessibleTagColors?.get(memberPowerTag.color) : undefined;
|
||||
|
||||
// final resolutions
|
||||
const validLocal = localColor && isValidHex(localColor) ? localColor : undefined;
|
||||
const validSpace = spaceColor && isValidHex(spaceColor) ? spaceColor : undefined;
|
||||
|
||||
// color decision hierarchy
|
||||
// Room > Space > Global (if enabled) > Random Colors (if enabled) > Tag
|
||||
const resolvedColor = validLocal || validSpace || validGlobal || (legacyUsernameColor ? colorMXID(userId) : tagColor);
|
||||
|
||||
// font decision hierarchy
|
||||
const rawFont = localFont || spaceFont;
|
||||
let resolvedFont;
|
||||
if (rawFont) {
|
||||
const clean = sanitizeFont(rawFont);
|
||||
resolvedFont = clean.includes(' ') ? `"${clean}", var(--font-secondary)` : `${clean}, var(--font-secondary)`;
|
||||
}
|
||||
|
||||
return { color: resolvedColor, font: resolvedFont };
|
||||
}, [room, userId, mx, getPowerTag, accessibleTagColors, legacyUsernameColor, renderGlobalColors, profile.nameColor]);
|
||||
return {
|
||||
color: finalColor,
|
||||
font: profile.resolvedFont
|
||||
};
|
||||
}, [room, userId, profile.resolvedColor, profile.resolvedFont, getPowerTag, accessibleTagColors]);
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { selectAtom } from 'jotai/utils';
|
||||
import { EventTimeline, Room } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { profilesCacheAtom } from '../state/userRoomProfile';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import colorMXID from '../../util/colorMXID';
|
||||
|
||||
export type UserProfile = {
|
||||
avatarUrl?: string;
|
||||
@@ -28,8 +33,17 @@ const normalizeInfo = (info: any): UserProfile => ({
|
||||
_fetched: true,
|
||||
});
|
||||
|
||||
export const useUserProfile = (userId: string, initialProfile?: Partial<UserProfile>): UserProfile => {
|
||||
const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c);
|
||||
const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32);
|
||||
|
||||
export const useUserProfile = (
|
||||
userId: string,
|
||||
room?: Room,
|
||||
initialProfile?: Partial<UserProfile>
|
||||
): UserProfile & { resolvedColor?: string; resolvedFont?: string } => {
|
||||
const mx = useMatrixClient();
|
||||
const [legacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
|
||||
const [renderGlobalColors] = useSetting(settingsAtom, 'renderGlobalNameColors');
|
||||
|
||||
const userSelector = useMemo(
|
||||
() => selectAtom(profilesCacheAtom, (db) => db[userId]),
|
||||
@@ -43,48 +57,74 @@ export const useUserProfile = (userId: string, initialProfile?: Partial<UserProf
|
||||
|
||||
useEffect(() => {
|
||||
if (!needsFetch) return;
|
||||
|
||||
let isMounted = true;
|
||||
|
||||
mx.getProfileInfo(userId).then((info: any) => {
|
||||
if (!isMounted) return;
|
||||
|
||||
const normalized = normalizeInfo(info);
|
||||
|
||||
setGlobalProfiles((prev) => {
|
||||
const existing = prev[userId];
|
||||
|
||||
if (
|
||||
existing?.nameColor === normalized.nameColor &&
|
||||
existing?.displayName === normalized.displayName &&
|
||||
existing?._fetched === true
|
||||
) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
return {
|
||||
...prev,
|
||||
[userId]: { ...existing, ...normalized }
|
||||
};
|
||||
});
|
||||
setGlobalProfiles((prev) => ({
|
||||
...prev,
|
||||
[userId]: { ...prev[userId], ...normalized }
|
||||
}));
|
||||
}).catch(() => {
|
||||
setGlobalProfiles((prev) => ({
|
||||
...prev,
|
||||
[userId]: { ...prev[userId], _fetched: true }
|
||||
}));
|
||||
});
|
||||
|
||||
return () => { isMounted = false; };
|
||||
}, [userId, needsFetch, mx, setGlobalProfiles]);
|
||||
|
||||
return useMemo(() => {
|
||||
if (cached) return cached;
|
||||
|
||||
const user = mx.getUser(userId);
|
||||
return {
|
||||
displayName: initialProfile?.displayName ?? user?.displayName,
|
||||
avatarUrl: initialProfile?.avatarUrl ?? user?.avatarUrl,
|
||||
const data = cached ?? {
|
||||
displayName: initialProfile?.displayName ?? mx.getUser(userId)?.displayName,
|
||||
avatarUrl: initialProfile?.avatarUrl ?? mx.getUser(userId)?.avatarUrl,
|
||||
...initialProfile,
|
||||
};
|
||||
}, [cached, userId, initialProfile, mx]);
|
||||
|
||||
let localColor;
|
||||
let localFont;
|
||||
let spaceColor;
|
||||
let spaceFont;
|
||||
|
||||
if (room) {
|
||||
const state = room.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
|
||||
// Safely get local cosmetics
|
||||
const localEvent = state?.getStateEvents(StateEvent.RoomCosmeticsColor, userId);
|
||||
// If userId is provided, Matrix returns a single event. If it's an array, we take the first.
|
||||
localColor = (Array.isArray(localEvent) ? localEvent[0] : localEvent)?.getContent()?.color;
|
||||
|
||||
const localFontEvent = state?.getStateEvents(StateEvent.RoomCosmeticsFont, userId);
|
||||
localFont = (Array.isArray(localFontEvent) ? localFontEvent[0] : localFontEvent)?.getContent()?.font;
|
||||
|
||||
const parents = state?.getStateEvents(StateEvent.SpaceParent);
|
||||
if (parents && parents.length > 0) {
|
||||
const parentSpace = mx.getRoom(parents[0].getStateKey());
|
||||
const pState = parentSpace?.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
|
||||
const spaceEvent = pState?.getStateEvents(StateEvent.RoomCosmeticsColor, userId);
|
||||
spaceColor = (Array.isArray(spaceEvent) ? spaceEvent[0] : spaceEvent)?.getContent()?.color;
|
||||
|
||||
const spaceFontEvent = pState?.getStateEvents(StateEvent.RoomCosmeticsFont, userId);
|
||||
spaceFont = (Array.isArray(spaceFontEvent) ? spaceFontEvent[0] : spaceFontEvent)?.getContent()?.font;
|
||||
}
|
||||
}
|
||||
|
||||
const hasGlobalColor = data?.nameColor && isValidHex(data.nameColor);
|
||||
const validGlobal = (renderGlobalColors || userId === mx.getUserId()) && hasGlobalColor ? data.nameColor : undefined;
|
||||
const validLocal = localColor && isValidHex(localColor) ? localColor : undefined;
|
||||
const validSpace = spaceColor && isValidHex(spaceColor) ? spaceColor : undefined;
|
||||
|
||||
const resolvedColor = validLocal || validSpace || validGlobal || (legacyUsernameColor ? colorMXID(userId) : undefined);
|
||||
|
||||
const rawFont = localFont || spaceFont;
|
||||
let resolvedFont;
|
||||
if (rawFont) {
|
||||
const clean = sanitizeFont(rawFont);
|
||||
resolvedFont = clean.includes(' ') ? `"${clean}", var(--font-secondary)` : `${clean}, var(--font-secondary)`;
|
||||
}
|
||||
|
||||
return { ...data, resolvedColor, resolvedFont };
|
||||
}, [cached, userId, room, mx, legacyUsernameColor, renderGlobalColors, initialProfile]);
|
||||
};
|
||||
@@ -15,7 +15,7 @@ export function AuthFooter() {
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
v1.1.3
|
||||
v1.1.4
|
||||
</Text>
|
||||
<Text as="a" size="T300" href="https://twitter.com/cinnyapp" target="_blank" rel="noreferrer">
|
||||
Twitter
|
||||
|
||||
@@ -24,7 +24,7 @@ export function WelcomePage() {
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
>
|
||||
v1.1.3
|
||||
v1.1.4
|
||||
</a>
|
||||
</span>
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { UAParser } from 'ua-parser-js';
|
||||
|
||||
export const ua = () => UAParser(window.navigator.userAgent);
|
||||
const result = new UAParser(window.navigator.userAgent).getResult();
|
||||
|
||||
export const isMacOS = () => ua().os.name === 'Mac OS';
|
||||
|
||||
export const mobileOrTablet = (): boolean => {
|
||||
const userAgent = ua();
|
||||
const { os, device } = userAgent;
|
||||
const isMobileOrTablet = (() => {
|
||||
const { os, device } = result;
|
||||
if (device.type === 'mobile' || device.type === 'tablet') return true;
|
||||
if (os.name === 'Android' || os.name === 'iOS') return true;
|
||||
return false;
|
||||
};
|
||||
})();
|
||||
|
||||
const isMac = result.os.name === 'Mac OS';
|
||||
|
||||
export const ua = () => result;
|
||||
export const isMacOS = () => isMac;
|
||||
export const mobileOrTablet = () => isMobileOrTablet;
|
||||
Reference in new issue
Block a user