mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix: pass cached profile data and guard failed-send actions in threads
This commit is contained in:
1 parent
30a2c0921d
commit
95a459722d
2 files changed
+45
-30
No files matched your search
@@ -5,6 +5,7 @@ import { Chats, composerIcon, X } from '$components/icons/phosphor';
|
||||
import type { IEvent, Room, CryptoBackend } from '$types/matrix-sdk';
|
||||
import {
|
||||
Direction,
|
||||
EventStatus,
|
||||
MatrixEvent,
|
||||
MatrixEventEvent,
|
||||
ReceiptType,
|
||||
@@ -13,6 +14,8 @@ import {
|
||||
ThreadEvent,
|
||||
EventType,
|
||||
} from '$types/matrix-sdk';
|
||||
import { useSpaceOptionally } from '$hooks/useSpace';
|
||||
import { buildCachedProfilePayload } from '$hooks/timeline/useTimelineActions';
|
||||
import { useAtomValue, useSetAtom, useStore } from 'jotai';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
@@ -253,6 +256,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
|
||||
// User profile popup
|
||||
const openUserRoomProfile = useOpenUserRoomProfile();
|
||||
const optionalSpace = useSpaceOptionally();
|
||||
|
||||
// Thread timeline data for useProcessedTimeline
|
||||
const thread = room.getThread(threadRootId);
|
||||
@@ -592,12 +596,14 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
if (!userId) return;
|
||||
openUserRoomProfile(
|
||||
room.roomId,
|
||||
undefined,
|
||||
optionalSpace?.roomId,
|
||||
userId,
|
||||
evt.currentTarget.getBoundingClientRect()
|
||||
evt.currentTarget.getBoundingClientRect(),
|
||||
undefined,
|
||||
buildCachedProfilePayload(getGlobalProfile(userId))
|
||||
);
|
||||
},
|
||||
[room, openUserRoomProfile]
|
||||
[room, optionalSpace, openUserRoomProfile, getGlobalProfile]
|
||||
);
|
||||
|
||||
const handleUsernameClick: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
@@ -701,13 +707,15 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
|
||||
const handleResend = useCallback(
|
||||
(event: MatrixEvent) => {
|
||||
mx.resendEvent(event, room);
|
||||
if (event.getAssociatedStatus() !== EventStatus.NOT_SENT) return;
|
||||
mx.resendEvent(event, room).catch(() => undefined);
|
||||
},
|
||||
[mx, room]
|
||||
);
|
||||
|
||||
const handleDeleteFailedSend = useCallback(
|
||||
(event: MatrixEvent) => {
|
||||
if (event.getAssociatedStatus() !== EventStatus.NOT_SENT) return;
|
||||
mx.cancelPendingEvent(event);
|
||||
},
|
||||
[mx]
|
||||
|
||||
@@ -11,6 +11,38 @@ import { extractReplyDraftBody, getMemberDisplayName, resolveReplyDraftTarget }
|
||||
import { createMentionElement, moveCursor } from '$components/editor';
|
||||
import * as prefix from '$unstable/prefixes';
|
||||
|
||||
/**
|
||||
* The profile popup reads name, avatar and the identity fields off the room
|
||||
* member, so the cached copies would shadow fresher state event data.
|
||||
*/
|
||||
export const buildCachedProfilePayload = (cachedData: UserProfile | undefined) => {
|
||||
const cleanExtended = cachedData?.extended ? { ...cachedData.extended } : undefined;
|
||||
|
||||
if (cleanExtended) {
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_PRONOUNS_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_BIO_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_TIMEZONE_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_STABLE_PROFILE_TIMEZONE_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_BANNER_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME];
|
||||
delete cleanExtended.avatar_url;
|
||||
delete cleanExtended.displayname;
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_HAS_CAT_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME];
|
||||
}
|
||||
|
||||
return {
|
||||
pronouns: cachedData?.pronouns,
|
||||
bio: cachedData?.bio,
|
||||
timezone: cachedData?.timezone,
|
||||
extended: cleanExtended,
|
||||
};
|
||||
};
|
||||
|
||||
export interface UseTimelineActionsOptions {
|
||||
room: Room;
|
||||
mx: MatrixClient;
|
||||
@@ -65,38 +97,13 @@ export function useTimelineActions({
|
||||
const userId = evt.currentTarget.getAttribute('data-user-id');
|
||||
if (!userId) return;
|
||||
|
||||
const cachedData = getGlobalProfile(userId);
|
||||
const cleanExtended = cachedData?.extended ? { ...cachedData.extended } : undefined;
|
||||
|
||||
if (cleanExtended) {
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_PRONOUNS_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_BIO_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_TIMEZONE_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_STABLE_PROFILE_TIMEZONE_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_BANNER_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME];
|
||||
delete cleanExtended.avatar_url;
|
||||
delete cleanExtended.displayname;
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_HAS_CAT_PROPERTY_NAME];
|
||||
delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME];
|
||||
}
|
||||
|
||||
openUserRoomProfile(
|
||||
room.roomId,
|
||||
spaceId,
|
||||
userId,
|
||||
evt.currentTarget.getBoundingClientRect(),
|
||||
undefined,
|
||||
{
|
||||
pronouns: cachedData?.pronouns,
|
||||
bio: cachedData?.bio,
|
||||
timezone: cachedData?.timezone,
|
||||
extended: cleanExtended,
|
||||
}
|
||||
buildCachedProfilePayload(getGlobalProfile(userId))
|
||||
);
|
||||
},
|
||||
[room.roomId, spaceId, openUserRoomProfile, getGlobalProfile]
|
||||
|
||||
Reference in new issue
Block a user