Skip to content

Commit

Permalink
fix: show user reactions in threads (#2814)
Browse files Browse the repository at this point in the history
* fix: show user reactions in threads

* refactor: add comment for threads not supported
  • Loading branch information
khushal87 authored Nov 27, 2024
1 parent d995ecd commit 837c2d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions package/src/components/MessageOverlay/MessageOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ const MessageOverlayWithContext = <
{!!messageReactionTitle && (
<OverlayReactions
alignment={alignment}
message={message}
messageId={message.id}
OverlayReactionsAvatar={OverlayReactionsAvatar}
showScreen={showScreen}
Expand Down
6 changes: 4 additions & 2 deletions package/src/components/MessageOverlay/OverlayReactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import type { DefaultStreamChatGenerics } from '../../types/types';
import type { ReactionData } from '../../utils/utils';
import { MessageType } from '../MessageList/hooks/useMessageList';

const styles = StyleSheet.create({
avatarContainer: {
Expand Down Expand Up @@ -89,6 +90,7 @@ export type OverlayReactionsProps<
showScreen: Animated.SharedValue<number>;
title: string;
alignment?: Alignment;
message?: MessageType<StreamChatGenerics>;
messageId?: string;
reactions?: Reaction[];
supportedReactions?: ReactionData[];
Expand All @@ -105,7 +107,7 @@ export const OverlayReactions = (props: OverlayReactionsProps) => {
const [itemHeight, setItemHeight] = React.useState(0);
const {
alignment: overlayAlignment,
messageId,
message,
OverlayReactionsAvatar,
reactions: propReactions,
showScreen,
Expand All @@ -119,7 +121,7 @@ export const OverlayReactions = (props: OverlayReactionsProps) => {
loadNextPage,
reactions: fetchedReactions,
} = useFetchReactions({
messageId,
message,
sort,
});

Expand Down
11 changes: 7 additions & 4 deletions package/src/components/MessageOverlay/hooks/useFetchReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';

import { ReactionResponse, ReactionSort } from 'stream-chat';

import { MessageType } from '../../../components/MessageList/hooks/useMessageList';
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
import { getReactionsForFilterSort } from '../../../store/apis/getReactionsforFilterSort';
import { DefaultStreamChatGenerics } from '../../../types/types';
Expand All @@ -10,7 +11,7 @@ export type UseFetchReactionParams<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = {
limit?: number;
messageId?: string;
message?: MessageType<StreamChatGenerics>;
reactionType?: string;
sort?: ReactionSort<StreamChatGenerics>;
};
Expand All @@ -19,13 +20,14 @@ export const useFetchReactions = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>({
limit = 25,
messageId,
message,
reactionType,
sort,
}: UseFetchReactionParams) => {
const [reactions, setReactions] = useState<ReactionResponse<StreamChatGenerics>[]>([]);
const [loading, setLoading] = useState(true);
const [next, setNext] = useState<string | undefined>(undefined);
const messageId = message?.id;

const { client, enableOfflineSupport } = useChatContext();

Expand Down Expand Up @@ -61,8 +63,9 @@ export const useFetchReactions = <
};

try {
if (enableOfflineSupport) {
loadOfflineReactions();
// TODO: Threads are not supported for the offline use case as we don't store the thread messages currently, and this will change in the future.
if (enableOfflineSupport && !message?.parent_id) {
await loadOfflineReactions();
} else {
await loadOnlineReactions();
}
Expand Down

0 comments on commit 837c2d2

Please sign in to comment.