mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-01-31 09:49:10 +01:00
FIX - filtered duplicate reactions in reactions viewer
This commit is contained in:
parent
c110e64341
commit
2cbe0000a8
2 changed files with 49 additions and 11 deletions
|
@ -40,7 +40,25 @@ export const Reactions = as<'div', ReactionsProps>(
|
||||||
const reactions = useRelations(
|
const reactions = useRelations(
|
||||||
relations,
|
relations,
|
||||||
useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
|
useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
|
||||||
);
|
).map((reaction) => {
|
||||||
|
const events = Array.from(reaction[1]);
|
||||||
|
|
||||||
|
// Track unique userIds using a Set to filter efficiently
|
||||||
|
const existingUserIds = new Set();
|
||||||
|
const uniqueEvents = events.filter((event) => {
|
||||||
|
const userId = event.sender?.userId;
|
||||||
|
if (!userId || existingUserIds.has(userId)) {
|
||||||
|
return false; // If already exist, filter out the event
|
||||||
|
}
|
||||||
|
existingUserIds.add(userId); // Mark this userId as exis
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
reaction[1] = new Set(uniqueEvents);
|
||||||
|
|
||||||
|
return reaction;
|
||||||
|
});
|
||||||
|
|
||||||
const handleViewReaction: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
const handleViewReaction: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
|
|
@ -40,7 +40,25 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
|
||||||
const reactions = useRelations(
|
const reactions = useRelations(
|
||||||
relations,
|
relations,
|
||||||
useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
|
useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
|
||||||
);
|
).map((reaction) => {
|
||||||
|
const events = Array.from(reaction[1]);
|
||||||
|
|
||||||
|
// Track unique userIds using a Set to filter efficiently
|
||||||
|
const existingUserIds = new Set();
|
||||||
|
const uniqueEvents = events.filter((event) => {
|
||||||
|
const userId = event.sender?.userId;
|
||||||
|
if (!userId || existingUserIds.has(userId)) {
|
||||||
|
return false; // If already exist, filter out the event
|
||||||
|
}
|
||||||
|
existingUserIds.add(userId); // Mark this userId as exis
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
reaction[1] = new Set(uniqueEvents);
|
||||||
|
|
||||||
|
return reaction;
|
||||||
|
});
|
||||||
|
|
||||||
const [selectedKey, setSelectedKey] = useState<string>(() => {
|
const [selectedKey, setSelectedKey] = useState<string>(() => {
|
||||||
if (initialKey) return initialKey;
|
if (initialKey) return initialKey;
|
||||||
|
@ -111,7 +129,8 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
|
||||||
const name = (member ? getName(member) : getMxIdLocalPart(senderId)) ?? senderId;
|
const name = (member ? getName(member) : getMxIdLocalPart(senderId)) ?? senderId;
|
||||||
|
|
||||||
const avatarMxcUrl = member?.getMxcAvatarUrl();
|
const avatarMxcUrl = member?.getMxcAvatarUrl();
|
||||||
const avatarUrl = avatarMxcUrl ? mx.mxcUrlToHttp(
|
const avatarUrl = avatarMxcUrl
|
||||||
|
? mx.mxcUrlToHttp(
|
||||||
avatarMxcUrl,
|
avatarMxcUrl,
|
||||||
100,
|
100,
|
||||||
100,
|
100,
|
||||||
|
@ -119,7 +138,8 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
|
||||||
undefined,
|
undefined,
|
||||||
false,
|
false,
|
||||||
useAuthentication
|
useAuthentication
|
||||||
) : undefined;
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|
Loading…
Reference in a new issue