Skip to content

Commit a7c92b5

Browse files
committed
fix: answer and results list anonymity fixes
1 parent 9bb3cab commit a7c92b5

File tree

16 files changed

+55
-10
lines changed

16 files changed

+55
-10
lines changed

package/src/components/Poll/components/PollAnswersList.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { FlatList, type FlatListProps, StyleSheet, Text, View } from 'react-native';
33

4-
import { PollAnswer } from 'stream-chat';
4+
import { PollAnswer, VotingVisibility } from 'stream-chat';
55

66
import { AnswerListAddCommentButton } from './Button';
77

@@ -15,6 +15,7 @@ import { DefaultStreamChatGenerics } from '../../../types/types';
1515
import { getDateString } from '../../../utils/i18n/getDateString';
1616
import { Avatar } from '../../Avatar/Avatar';
1717
import { usePollAnswersPagination } from '../hooks/usePollAnswersPagination';
18+
import { usePollState } from '../hooks/usePollState';
1819

1920
export type PollAnswersListProps<
2021
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -25,6 +26,8 @@ export type PollAnswersListProps<
2526

2627
export const PollAnswerListItem = ({ answer }: { answer: PollAnswer }) => {
2728
const { t, tDateTimeParser } = useTranslationContext();
29+
const { voting_visibility } = usePollState();
30+
2831
const {
2932
theme: {
3033
colors: { bg_user, black },
@@ -37,12 +40,17 @@ export const PollAnswerListItem = ({ answer }: { answer: PollAnswer }) => {
3740
const dateString = useMemo(
3841
() =>
3942
getDateString({
40-
date: answer.created_at,
43+
date: answer.updated_at,
4144
t,
4245
tDateTimeParser,
4346
timestampTranslationKey: 'timestamp/PollVote',
4447
}),
45-
[answer.created_at, t, tDateTimeParser],
48+
[answer.updated_at, t, tDateTimeParser],
49+
);
50+
51+
const isAnonymous = useMemo(
52+
() => voting_visibility === VotingVisibility.anonymous,
53+
[voting_visibility],
4654
);
4755

4856
return (
@@ -52,8 +60,12 @@ export const PollAnswerListItem = ({ answer }: { answer: PollAnswer }) => {
5260
</Text>
5361
<View style={[styles.listItemInfoContainer, itemStyle.infoContainer]}>
5462
<View style={[styles.listItemUserInfoContainer, itemStyle.userInfoContainer]}>
55-
<Avatar image={answer.user?.image as string} size={20} />
56-
<Text style={{ color: black, fontSize: 14, marginLeft: 2 }}>{answer.user?.name}</Text>
63+
{!isAnonymous && answer.user?.image ? (
64+
<Avatar image={answer.user?.image as string} size={20} />
65+
) : null}
66+
<Text style={{ color: black, fontSize: 14, marginLeft: 2 }}>
67+
{isAnonymous ? t<string>('Anonymous') : answer.user?.name}
68+
</Text>
5769
</View>
5870
<Text style={{ color: black }}>{dateString}</Text>
5971
</View>

package/src/components/Poll/components/PollResults/PollResultItem.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
33

4-
import { PollOption, PollVote as PollVoteClass } from 'stream-chat';
4+
import { PollOption, PollVote as PollVoteClass, VotingVisibility } from 'stream-chat';
55

66
import { useTheme, useTranslationContext } from '../../../../contexts';
77
import type { DefaultStreamChatGenerics } from '../../../../types/types';
@@ -18,6 +18,7 @@ export type PollResultItemProps<
1818

1919
export const PollVote = (vote: PollVoteClass) => {
2020
const { t, tDateTimeParser } = useTranslationContext();
21+
const { voting_visibility } = usePollState();
2122
const {
2223
theme: {
2324
colors: { black, text_low_emphasis },
@@ -40,11 +41,20 @@ export const PollVote = (vote: PollVoteClass) => {
4041
[vote.created_at, t, tDateTimeParser],
4142
);
4243

44+
const isAnonymous = useMemo(
45+
() => voting_visibility === VotingVisibility.anonymous,
46+
[voting_visibility],
47+
);
48+
4349
return (
4450
<View key={`results_vote_${vote.id}`} style={[styles.voteContainer, container]}>
4551
<View style={{ flexDirection: 'row' }}>
46-
<Avatar image={vote.user?.image as string} key={vote.id} size={20} />
47-
<Text style={[styles.voteUserName, { color: black }, userName]}>{vote.user?.name}</Text>
52+
{!isAnonymous && vote.user?.image ? (
53+
<Avatar image={vote.user.image as string} key={vote.id} size={20} />
54+
) : null}
55+
<Text style={[styles.voteUserName, { color: black }, userName]}>
56+
{isAnonymous ? t<string>('Anonymous') : vote.user?.name}
57+
</Text>
4858
</View>
4959
<Text style={[styles.voteDate, { color: text_low_emphasis }, dateText]}>{dateString}</Text>
5060
</View>

package/src/components/Poll/hooks/usePollAnswersPagination.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const usePollAnswersPagination = ({
3434
const { next: newNext, votes: answers } = await poll.queryAnswers({
3535
filter: paginationParams?.filter,
3636
options: !next ? paginationParams?.options : { ...paginationParams?.options, next },
37-
sort: { created_at: -1, ...paginationParams?.sort },
37+
sort: { updated_at: -1, ...paginationParams?.sort },
3838
});
3939
cursorRef.current = newNext || null;
4040
setPollAnswers((prev) => uniqBy([...prev, ...answers], 'id'));

package/src/components/Poll/hooks/usePollState.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { useCallback } from 'react';
22

3-
import type { PollAnswer, PollOption, PollState, PollVote, UserResponse } from 'stream-chat';
3+
import {
4+
PollAnswer,
5+
PollOption,
6+
PollState,
7+
PollVote,
8+
UserResponse,
9+
VotingVisibility,
10+
} from 'stream-chat';
411

512
import { usePollStateStore } from './usePollStateStore';
613

@@ -22,6 +29,7 @@ export type UsePollStateSelectorReturnType = [
2229
boolean | undefined,
2330
boolean | undefined,
2431
UserResponse | null,
32+
VotingVisibility | undefined,
2533
];
2634

2735
const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
@@ -40,6 +48,7 @@ const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
4048
nextValue.allow_answers,
4149
nextValue.allow_user_suggested_options,
4250
nextValue.created_by,
51+
nextValue.voting_visibility,
4352
];
4453

4554
export const usePollState = () => {
@@ -58,6 +67,7 @@ export const usePollState = () => {
5867
allow_answers,
5968
allow_user_suggested_options,
6069
created_by,
70+
voting_visibility,
6171
] = usePollStateStore(selector);
6272

6373
const addOption = useCallback(
@@ -90,5 +100,6 @@ export const usePollState = () => {
90100
ownAnswer,
91101
ownVotesByOptionId,
92102
vote_counts_by_option,
103+
voting_visibility,
93104
};
94105
};

package/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "Allow access to your Gallery",
77
"Allow camera access in device settings": "Allow camera access in device settings",
88
"Also send to channel": "Also send to channel",
9+
"Anonymous": "Anonymous",
910
"Anonymous poll": "Anonymous poll",
1011
"Are you sure you want to permanently delete this message?": "Are you sure you want to permanently delete this message?",
1112
"Are you sure?": "Are you sure?",

package/src/i18n/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "Permitir acceso a tu galería",
77
"Allow camera access in device settings": "Permitir el acceso a la cámara en la configuración del dispositivo",
88
"Also send to channel": "También enviar al canal",
9+
"Anonymous": "Anónimo",
910
"Anonymous poll": "Encuesta anónima",
1011
"Are you sure you want to permanently delete this message?": "¿Estás seguro de que deseas eliminar permanentemente este mensaje?",
1112
"Are you sure?": "¿Estás seguro?",

package/src/i18n/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "Autoriser l'accès à votre galerie",
77
"Allow camera access in device settings": "Autoriser l'accès à la caméra dans les paramètres de l'appareil",
88
"Also send to channel": "Envoyer également à la chaîne",
9+
"Anonymous": "Anonyme",
910
"Anonymous poll": "Sondage anonyme",
1011
"Are you sure you want to permanently delete this message?": "Êtes-vous sûr de vouloir supprimer définitivement ce message?",
1112
"Are you sure?": "Es-tu sûr ?",

package/src/i18n/he.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "אפשר גישה לגלריה שלך",
77
"Allow camera access in device settings": "אפשר גישה למצלמה בהגדרות המכשיר",
88
"Also send to channel": "שלח/י הודעה לשיחה",
9+
"Anonymous": "אנונימי",
910
"Anonymous poll": "סקר אנונימי",
1011
"Are you sure you want to permanently delete this message?": "האם את/ה בטוח/ה שאת/ה רוצה למחוק את ההודעה הזו לצמיתות?",
1112
"Are you sure?": "האם אתה בטוח?",

package/src/i18n/hi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "अपनी गैलरी तक पहुँचने की अनुमति दें",
77
"Allow camera access in device settings": "डिवाइस सेटिंग्स में कैमरा एक्सेस की अनुमति दें",
88
"Also send to channel": "चैनल को भी भेजें",
9+
"Anonymous": "गुमनाम",
910
"Anonymous poll": "अनाम सर्वेक्षण",
1011
"Are you sure you want to permanently delete this message?": "क्या आप वाकई इस संदेश को स्थायी रूप से हटाना चाहते हैं?",
1112
"Are you sure?": "क्या आप सुनिश्चित हैं?",

package/src/i18n/it.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Allow access to your Gallery": "Consenti l'accesso alla tua galleria",
77
"Allow camera access in device settings": "Consenti l'accesso alla fotocamera nelle impostazioni del dispositivo",
88
"Also send to channel": "Invia anche al canale",
9+
"Anonymous": "Anonimo",
910
"Anonymous poll": "Sondaggio anonimo",
1011
"Are you sure you want to permanently delete this message?": "Sei sicuro di voler eliminare definitivamente questo messaggio?",
1112
"Are you sure?": "Sei sicuro?",

0 commit comments

Comments
 (0)