@openpeepshq/rn-components 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./src/index.ts",
@@ -140,8 +140,8 @@
140
140
  "timezones-list": "^3.1.0",
141
141
  "validator": "^13.15.23",
142
142
  "zustand": "^5.0.3",
143
- "@openpeepshq/common": "^0.2.0",
144
- "@openpeepshq/react": "^0.5.0"
143
+ "@openpeepshq/common": "^0.3.0",
144
+ "@openpeepshq/react": "^0.6.0"
145
145
  },
146
146
  "devDependencies": {
147
147
  "@babel/core": "^7.26.7",
@@ -4,7 +4,6 @@ import type { PublicPost } from '@openpeepshq/common/types';
4
4
  import { useCurrentProfile } from '@openpeepshq/react';
5
5
  import { FeedPostContent } from '../post/FeedPostContent';
6
6
  import { UnreadPostIndicator } from '../post/pieces/UnreadPostIndicator';
7
- import { ThemedView } from '../ui/themed-view';
8
7
 
9
8
  export interface ConversationMessageBubbleProps {
10
9
  message: PublicPost;
@@ -20,18 +19,23 @@ export const ConversationMessageBubble = ({
20
19
 
21
20
  return (
22
21
  <View
23
- className={`mt-2 w-full flex-row items-center gap-2 ${
22
+ className={`mt-4 w-full flex-row items-center gap-2 ${
24
23
  mine ? 'justify-end' : 'justify-start'
25
24
  }`}
26
25
  >
27
- <ThemedView
26
+ <View
28
27
  className={`w-[80%] rounded-t-xl p-3 ${
29
- mine ? 'rounded-bl-xl bg-primary/10' : 'rounded-br-xl bg-secondary/20'
28
+ mine ? 'rounded-bl-xl bg-primary/10' : 'rounded-br-xl bg-surface-2'
30
29
  }`}
31
30
  >
32
31
  <FeedPostContent post={message} />
33
- </ThemedView>
34
- {!mine ? <UnreadPostIndicator show={unread} /> : null}
32
+ </View>
33
+ {!mine ? (
34
+ <UnreadPostIndicator
35
+ show={unread}
36
+ className="relative inset-auto shrink-0 translate-y-0"
37
+ />
38
+ ) : null}
35
39
  </View>
36
40
  );
37
41
  };
@@ -2,22 +2,29 @@ import { View, TouchableOpacity } from 'react-native';
2
2
  import React, { useCallback, useRef, useState } from 'react';
3
3
  import { UpdatingDate } from '../custom/date/updating-date';
4
4
  import { OpenpeepsMarkdown } from '../markdown/OpenpeepsMarkdown';
5
- import { formatBadgeCount, PublicPost } from '@openpeepshq/common';
5
+ import {
6
+ formatBadgeCount,
7
+ truncateText,
8
+ type PublicPost,
9
+ } from '@openpeepshq/common';
6
10
  import { Text } from '../ui/text';
7
- import { Button } from '../ui/button';
8
11
  import { BottomSheetModal } from '@gorhom/bottom-sheet';
9
12
  import {
10
13
  DropdownMenu,
11
14
  DropdownMenuContent,
12
15
  DropdownMenuItem,
13
16
  } from '../ui/dropdown-menu';
14
- import { BellOffIcon, FlagIcon, Trash2Icon } from '../icons/index';
17
+ import {
18
+ BellOffIcon,
19
+ FlagIcon,
20
+ Trash2Icon,
21
+ CalendarIcon,
22
+ } from '../icons/index';
15
23
  import { useOpenpeeps } from '@openpeepshq/react';
16
-
17
- import { ProfileImages, ProfileName } from '../profile/ProfilePieces';
18
- import { truncateText } from '../../lib/utils';
19
- import { ProfileSheet } from '../profile/index';
24
+ import { ProfileAvatar } from '../profile/Avatar';
20
25
  import { ConversationParticipantsModal } from './ConversationParticipantsModal';
26
+ import { useTranslation } from 'react-i18next';
27
+
21
28
  interface ConversationPreviewCardProps {
22
29
  conversation: PublicPost[];
23
30
  onPress: () => void;
@@ -31,7 +38,7 @@ export const ConversationPreviewCard = ({
31
38
  onLongPress,
32
39
  unreadCount = 0,
33
40
  }: ConversationPreviewCardProps) => {
34
- const profileSheetRef = useRef<BottomSheetModal>(null);
41
+ const { t } = useTranslation();
35
42
  const deleteMessageModalRef = useRef<BottomSheetModal>(null);
36
43
  const [participantsOpen, setParticipantsOpen] = useState(false);
37
44
  const { currentProfile } = useOpenpeeps();
@@ -43,10 +50,15 @@ export const ConversationPreviewCard = ({
43
50
  (p) => p.id !== currentProfile?.id
44
51
  );
45
52
 
46
- const handleProfilePress = useCallback(() => {
47
- if (participants.length > 2) setParticipantsOpen(true);
48
- else profileSheetRef.current?.present();
49
- }, [participants.length]);
53
+ const otherNames = otherParticipants
54
+ .map((p) => p.displayName || `@${p.handle}`)
55
+ .join(', ');
56
+ const title = otherNames
57
+ ? t('conversations.titleWithYou', {
58
+ defaultValue: '{{names}} and You',
59
+ names: otherNames,
60
+ })
61
+ : t('common.you', { defaultValue: 'You' });
50
62
 
51
63
  const handleDeleteGroupModalPress = useCallback(() => {
52
64
  deleteMessageModalRef.current?.present();
@@ -59,43 +71,60 @@ export const ConversationPreviewCard = ({
59
71
  onLongPress={onLongPress}
60
72
  className="w-full mb-3"
61
73
  >
62
- <View className="flex w-full flex-row items-center justify-between p-4">
63
- <Button
64
- variant={'ghost'}
65
- size={'icon'}
66
- className="rounded-full -mt-4"
67
- onPress={handleProfilePress}
68
- >
69
- <ProfileImages profile={participants} />
70
- </Button>
71
- <View className="flex-1 ml-5">
72
- <View className="flex-row justify-between items-center">
73
- <ProfileName
74
- profile={
75
- participants.length === 2
76
- ? participants.filter((p) => p.id !== currentProfile?.id)
77
- : participants
78
- }
79
- />
74
+ <View className="flex w-full flex-col gap-x-1 border-b p-3 text-left">
75
+ <View className="flex flex-row items-center gap-4">
76
+ <View className="flex -space-x-2">
77
+ {participants.slice(0, 3).map((p) => (
78
+ <ProfileAvatar
79
+ key={p.id}
80
+ profile={p}
81
+ className="size-10 border-0"
82
+ />
83
+ ))}
84
+ </View>
85
+ <View className="flex min-w-0 flex-1 flex-row items-center gap-2">
86
+ <Text className="truncate font-bold">
87
+ {truncateText(title, 20)}
88
+ </Text>
80
89
  {unreadCount > 0 ? (
81
- <View className="bg-destructive size-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1 ml-2">
90
+ <View className="bg-destructive size-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1">
82
91
  <Text className="text-xs font-semibold text-destructive-foreground">
83
92
  {formatBadgeCount(unreadCount)}
84
93
  </Text>
85
94
  </View>
86
95
  ) : null}
87
96
  </View>
88
- <View className="flex-row gap-1">
89
- <Text className="">{lastMessage.profile.handle}</Text>
90
- <UpdatingDate date={lastMessage.createdAt} />
91
- </View>
92
97
  </View>
93
- </View>
94
- <View className="px-4">
95
- <OpenpeepsMarkdown
96
- source={truncateText(lastMessage.data?.content, 70) || ''}
97
- linkPreviewMode="none"
98
+
99
+ <UpdatingDate
100
+ date={lastMessage.createdAt}
101
+ className="text-muted-foreground"
98
102
  />
103
+
104
+ <View className="mt-2 flex flex-row items-start gap-x-2">
105
+ <View className="flex flex-row items-center">
106
+ <Text>~</Text>
107
+ {currentProfile?.id === lastMessage.profile.id ? (
108
+ <Text className="ml-1">Me</Text>
109
+ ) : (
110
+ <Text className="ml-1">
111
+ @{truncateText(lastMessage.profile.handle, 8)}
112
+ </Text>
113
+ )}
114
+ <Text className="mx-1">:</Text>
115
+ </View>
116
+ {lastMessage.data?.type === 'event' ? (
117
+ <View className="flex flex-row items-center gap-1">
118
+ <CalendarIcon size={16} className="text-muted-foreground" />
119
+ <Text>{(lastMessage.data as { name?: string }).name}</Text>
120
+ </View>
121
+ ) : (
122
+ <OpenpeepsMarkdown
123
+ source={lastMessage.data?.content || ''}
124
+ linkPreviewMode="none"
125
+ />
126
+ )}
127
+ </View>
99
128
  </View>
100
129
  </TouchableOpacity>
101
130
  <DropdownMenuContent>
@@ -117,16 +146,6 @@ export const ConversationPreviewCard = ({
117
146
  <Text className="text-destructive">Delete conversation</Text>
118
147
  </DropdownMenuItem>
119
148
  </DropdownMenuContent>
120
- {participants.length === 2 && otherParticipants.length > 0 && (
121
- <ProfileSheet
122
- ref={profileSheetRef}
123
- profile={otherParticipants}
124
- onConnect={() => {
125
- console.log('Connect pressed');
126
- profileSheetRef.current?.dismiss();
127
- }}
128
- />
129
- )}
130
149
  {participants.length > 2 && (
131
150
  <ConversationParticipantsModal
132
151
  open={participantsOpen}
@@ -11,7 +11,6 @@ export const DirectMessagesHeaderActions = () => {
11
11
 
12
12
  return (
13
13
  <Button
14
- size="sm"
15
14
  className="flex-row items-center gap-x-1"
16
15
  accessibilityLabel={t('conversations.newMessage')}
17
16
  onPress={() => openCreateConversation()}
@@ -28,7 +28,7 @@ const audienceDiff = (
28
28
  const AvatarRow = ({ profiles }: { profiles: PublicProfile[] }) => (
29
29
  <View className="flex-row -space-x-2">
30
30
  {profiles.map((p) => (
31
- <ProfileAvatar key={p.id} profile={p} className="size-10" />
31
+ <ProfileAvatar key={p.id} profile={p} className="size-10 border-0" />
32
32
  ))}
33
33
  </View>
34
34
  );
@@ -74,7 +74,10 @@ export const MessageInThread = ({
74
74
  inAudience(previous, message.profile) &&
75
75
  !inAudience(message, message.profile) ? (
76
76
  <View className="flex-row items-center gap-2">
77
- <ProfileAvatar profile={message.profile} className="size-10" />
77
+ <ProfileAvatar
78
+ profile={message.profile}
79
+ className="size-10 border-0"
80
+ />
78
81
  <ThemedText>
79
82
  {t('conversations.messageInThread.left', { name })}
80
83
  </ThemedText>
@@ -102,7 +105,10 @@ export const MessageInThread = ({
102
105
  <View ref={postViewRef} className="flex-row">
103
106
  {!isMe && multipleParticipants ? (
104
107
  <View className="mr-2 mt-6">
105
- <ProfileAvatar profile={message.profile} className="size-10" />
108
+ <ProfileAvatar
109
+ profile={message.profile}
110
+ className="size-10 border-0"
111
+ />
106
112
  </View>
107
113
  ) : null}
108
114
  <View className="min-w-0 flex-1">
@@ -1,15 +1,18 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { dateFormatter } from './formatter';
3
3
  import { ThemedText } from '../../ui/themed-text';
4
+ import { cn } from '../../../lib/utils';
4
5
 
5
6
  interface UpdatingDateProps {
6
7
  date: string | Date | number;
7
8
  formatter?: (date: string | Date | number) => string;
9
+ className?: string;
8
10
  }
9
11
 
10
12
  export const UpdatingDate = ({
11
13
  date,
12
14
  formatter = dateFormatter,
15
+ className,
13
16
  }: UpdatingDateProps) => {
14
17
  const [formattedDate, setFormattedDate] = React.useState(formatter(date));
15
18
 
@@ -20,5 +23,9 @@ export const UpdatingDate = ({
20
23
  return () => clearInterval(interval);
21
24
  }, [date, formatter]);
22
25
 
23
- return <ThemedText className="">{formattedDate}</ThemedText>;
26
+ return (
27
+ <ThemedText className={cn('text-sm', className)}>
28
+ {formattedDate}
29
+ </ThemedText>
30
+ );
24
31
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
- linkProfileMentions,
3
- type MentionProfileRef,
2
+ preprocessMarkdownSource,
3
+ type MarkdownRenderProps,
4
4
  } from '@openpeepshq/common/lib';
5
5
  import { useNavigation } from '@react-navigation/native';
6
6
  import { NativeStackNavigationProp } from '@react-navigation/native-stack';
@@ -19,19 +19,14 @@ import { hashtagPlugin, hashtagRenderer } from './extensions/hashtag';
19
19
  import { mentionPlugin, mentionRenderer } from './extensions/mention';
20
20
  import { codeBlockRenderer, fenceRenderer } from './extensions/codeBlock';
21
21
  import { codeInlineRenderer } from './extensions/codeInline';
22
+ import { htmlBlockRenderer, htmlInlineRenderer } from './extensions/html';
22
23
  import { markdownTheme } from './theme';
23
24
  import { extractLinks, isEmail, isInternalLink, toGotoUrl } from './utils';
24
25
  import { PreviewLink } from '../preview-link';
25
26
  import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
26
27
  import { recordOutboundClick } from '@openpeepshq/react';
27
28
 
28
- export interface OpenpeepsMarkdownProps {
29
- source: string;
30
- mentions?: MentionProfileRef[];
31
- linkPreviewMode?: 'prepend' | 'append' | 'inline' | 'none';
32
- /** When true, same-origin links open in the system browser instead of in-app navigation. */
33
- newTab?: boolean | ((link: string) => boolean);
34
- }
29
+ export interface OpenpeepsMarkdownProps extends MarkdownRenderProps {}
35
30
 
36
31
  export const OpenpeepsMarkdown = ({
37
32
  source,
@@ -46,7 +41,9 @@ export const OpenpeepsMarkdown = ({
46
41
  useNavigation<NativeStackNavigationProp<MainStackParamList>>();
47
42
 
48
43
  const markdownit = useMemo(() => {
49
- const md = MarkdownIt({ linkify: true, typographer: true });
44
+ // html: true so inline HTML (iframes, etc.) is tokenized and passed
45
+ // to custom renderers that apply the same allowlist as the web side.
46
+ const md = MarkdownIt({ linkify: true, typographer: true, html: true });
50
47
  md.use(hashtagPlugin);
51
48
  md.use(mentionPlugin(mentions));
52
49
  return md;
@@ -62,6 +59,12 @@ export const OpenpeepsMarkdown = ({
62
59
  return typeof newTab === 'function' ? newTab(url) : newTab;
63
60
  };
64
61
 
62
+ const handleIframePress = (url: string) => {
63
+ const origin = BASE_URL as string;
64
+ recordOutboundClick(url, origin);
65
+ Linking.openURL(url);
66
+ };
67
+
65
68
  const handleLinkPress = (url: string) => {
66
69
  const origin = BASE_URL as string;
67
70
  if (shouldOpenExternally(url)) {
@@ -73,7 +76,11 @@ export const OpenpeepsMarkdown = ({
73
76
  };
74
77
 
75
78
  const tokens = useMemo(
76
- () => stringToTokens(linkProfileMentions(source, mentions), markdownit),
79
+ () =>
80
+ stringToTokens(
81
+ preprocessMarkdownSource(source ?? '', mentions),
82
+ markdownit
83
+ ),
77
84
  [source, mentions, markdownit]
78
85
  );
79
86
  const links = useMemo(
@@ -104,6 +111,8 @@ export const OpenpeepsMarkdown = ({
104
111
  code_block: codeBlockRenderer(colors),
105
112
  fence: fenceRenderer(colors),
106
113
  code_inline: codeInlineRenderer(colors),
114
+ html_block: htmlBlockRenderer(handleIframePress),
115
+ html_inline: htmlInlineRenderer(handleIframePress),
107
116
  }}
108
117
  >
109
118
  {ast as unknown as ReactNode[]}
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { Linking, StyleSheet, Text, View } from 'react-native';
3
+ import type { RenderFunction } from 'react-native-markdown-display';
4
+ import {
5
+ extractIframeSrcs,
6
+ MARKDOWN_HTML_ALLOWED_TAGS,
7
+ } from '@openpeepshq/common/lib';
8
+
9
+ const TAG_RE = /<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>/g;
10
+
11
+ /**
12
+ * Renderer for markdown-it `html_inline` tokens.
13
+ * Extracts iframes (rendered as tap-to-open links) and strips other HTML.
14
+ */
15
+ export const htmlInlineRenderer =
16
+ (onIframePress: (url: string) => void): RenderFunction =>
17
+ (node) => {
18
+ const raw =
19
+ typeof node.content === 'string' ? node.content : String(node.content);
20
+ return renderHtmlContent(raw, onIframePress);
21
+ };
22
+
23
+ /**
24
+ * Renderer for markdown-it `html_block` tokens.
25
+ */
26
+ export const htmlBlockRenderer =
27
+ (onIframePress: (url: string) => void): RenderFunction =>
28
+ (node) => {
29
+ const raw =
30
+ typeof node.content === 'string' ? node.content : String(node.content);
31
+ return renderHtmlContent(raw, onIframePress);
32
+ };
33
+
34
+ const renderHtmlContent = (
35
+ raw: string,
36
+ onIframePress: (url: string) => void
37
+ ): React.ReactElement | null => {
38
+ // Iframes: extract src URLs and render as tap-to-open buttons.
39
+ const iframes = extractIframeSrcs(raw);
40
+ if (iframes.length > 0) {
41
+ return (
42
+ <View style={styles.iframeContainer} key={raw.slice(0, 40)}>
43
+ {iframes.map((src, i) => (
44
+ <View key={`${i}-${src.slice(0, 20)}`} style={styles.iframeRow}>
45
+ <Text style={styles.iframeLink} onPress={() => onIframePress(src)}>
46
+ Open embedded content
47
+ </Text>
48
+ <Text
49
+ style={styles.iframeUrl}
50
+ onPress={() => void Linking.openURL(src)}
51
+ >
52
+ {src}
53
+ </Text>
54
+ </View>
55
+ ))}
56
+ </View>
57
+ );
58
+ }
59
+
60
+ // Strip all HTML tags — only allowlisted tags are permitted on the web
61
+ // (via DOMPurify). On RN we render safe tags as text and drop the rest.
62
+ const allowed = new Set<string>(MARKDOWN_HTML_ALLOWED_TAGS);
63
+ const tags: string[] = [];
64
+ let match: RegExpExecArray | null;
65
+ TAG_RE.lastIndex = 0;
66
+ while ((match = TAG_RE.exec(raw)) !== null) {
67
+ tags.push(match[1]?.toLowerCase());
68
+ }
69
+
70
+ // If all tags are allowlisted, strip them and render as text.
71
+ const text = raw.replace(TAG_RE, '');
72
+ if (tags.every((tag) => !tag || allowed.has(tag.toLowerCase()))) {
73
+ return <Text style={styles.text}>{text}</Text>;
74
+ }
75
+
76
+ // Disallowed tags present — strip everything to plain text.
77
+ return <Text style={styles.text}>{text}</Text>;
78
+ };
79
+
80
+ const styles = StyleSheet.create({
81
+ iframeContainer: { marginVertical: 8 },
82
+ iframeRow: { flexDirection: 'column', alignItems: 'flex-start' },
83
+ iframeLink: {
84
+ color: '#007AFF',
85
+ textDecorationLine: 'underline',
86
+ fontSize: 14,
87
+ },
88
+ iframeUrl: {
89
+ color: '#666',
90
+ fontSize: 12,
91
+ marginTop: 4,
92
+ },
93
+ text: { fontSize: 16, lineHeight: 24 },
94
+ });
@@ -1 +1,2 @@
1
1
  export * from './OpenpeepsMarkdown';
2
+ export type { MarkdownRenderProps } from '@openpeepshq/common/lib';
@@ -1,7 +1,10 @@
1
1
  import { stringToTokens } from 'react-native-markdown-display';
2
+ import { toGotoUrl } from '@openpeepshq/common/lib';
2
3
 
3
4
  type Token = ReturnType<typeof stringToTokens>[number];
4
5
 
6
+ export { toGotoUrl };
7
+
5
8
  export const isInternalLink = (href: string, origin: string): boolean => {
6
9
  if (!href || href.includes('goto:/')) {
7
10
  return !!href;
@@ -16,24 +19,6 @@ export const isInternalLink = (href: string, origin: string): boolean => {
16
19
  }
17
20
  };
18
21
 
19
- export const toGotoUrl = (url: string, origin: string): string => {
20
- if (url.includes('goto:/')) {
21
- return url;
22
- }
23
- if (url.startsWith('/') && !url.startsWith('//')) {
24
- return `goto:${url}`;
25
- }
26
- try {
27
- const urlObj = new URL(url);
28
- if (urlObj.origin === origin) {
29
- return `goto:${urlObj.pathname}${urlObj.search}${urlObj.hash}`;
30
- }
31
- } catch {
32
- // fall through
33
- }
34
- return url;
35
- };
36
-
37
22
  export const extractLinks = (token: Token): string[] => {
38
23
  if (token.type === 'link') {
39
24
  return [token.href];
@@ -1,11 +1,9 @@
1
1
  import React from 'react';
2
- import type { PublicPost } from '@openpeepshq/common/types';
3
-
4
- import { Attachments } from '../pieces/Attachments';
5
-
6
2
  import { View } from 'react-native';
3
+ import type { PublicPost } from '@openpeepshq/common/types';
7
4
  import { ThemedText } from '../../ui/themed-text';
8
5
  import { OpenpeepsMarkdown } from '../../markdown/index';
6
+ import { Attachments } from '../pieces/Attachments';
9
7
 
10
8
  export interface FeedNoteProps {
11
9
  post: PublicPost;
@@ -14,11 +12,12 @@ export interface FeedNoteProps {
14
12
  export const FeedNote = ({ post }: FeedNoteProps) =>
15
13
  post?.data?.type === 'note' ? (
16
14
  <View>
17
- <Attachments {...{ post }} />
18
15
  <OpenpeepsMarkdown
19
16
  source={post?.data?.content || ''}
17
+ mentions={post.mentions}
20
18
  linkPreviewMode={post?.data?.attachments?.length ? 'none' : 'append'}
21
19
  />
20
+ <Attachments {...{ post }} />
22
21
  </View>
23
22
  ) : (
24
23
  <View>
@@ -4,8 +4,9 @@ import {
4
4
  TouchableOpacity,
5
5
  View,
6
6
  } from 'react-native';
7
- import React, { useEffect, useRef } from 'react';
8
- import { EmptyStateContainer } from '../../components/custom/index';
7
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
8
+ import { MessageCircleOffIcon } from '../../components/icons/index';
9
+ import { ThemedText } from '../../components/ui/themed-text';
9
10
  import {
10
11
  useSetPageHeader,
11
12
  useSetPlusButtonActions,
@@ -23,20 +24,21 @@ import { canCreatePost, PublicPost } from '@openpeepshq/common';
23
24
  import { Input } from '../../components/ui/input';
24
25
  import { profileMatchesQuery } from '../../lib/utils';
25
26
  import { BottomSheetModal } from '@gorhom/bottom-sheet';
26
-
27
27
  import {
28
28
  ConversationPreviewCard,
29
29
  DirectMessagesHeaderActions,
30
30
  useCreateNewConversation,
31
31
  } from '../../components/conversations/index';
32
32
  import { useTranslation } from 'react-i18next';
33
-
34
33
  import { ConversationSettingsSheet } from '../../components/conversations/index';
34
+
35
35
  type MessagesProps = CompositeScreenProps<
36
36
  NativeStackScreenProps<TabStackParamList, 'Messages'>,
37
37
  NativeStackScreenProps<MainStackParamList>
38
38
  >;
39
39
 
40
+ type ConversationsTab = 'active' | 'archived';
41
+
40
42
  export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
41
43
  const { openpeepsApi } = useOpenpeeps();
42
44
  const { t } = useTranslation();
@@ -44,40 +46,42 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
44
46
  const canCreate = canCreatePost(authData, 'note', 'direct');
45
47
  const { openCreateConversation } = useCreateNewConversation();
46
48
  const settingsRef = useRef<BottomSheetModal>(null);
47
- const [refreshing, setRefreshing] = React.useState(false);
48
- const [filteredConversations, setFilteredConversations] = React.useState<
49
+ const [refreshing, setRefreshing] = useState(false);
50
+ const [filteredConversations, setFilteredConversations] = useState<
49
51
  PublicPost[][]
50
52
  >([]);
51
- const [searchQuery, setSearchQuery] = React.useState('');
52
- const [isSearchToggled, setIsSearchToggled] = React.useState(false);
53
+ const [searchQuery, setSearchQuery] = useState('');
54
+ const [isSearchToggled, setIsSearchToggled] = useState(false);
55
+ const [tab, setTab] = useState<ConversationsTab>('active');
53
56
 
54
- const {
55
- data: conversations,
56
- isLoading,
57
- refetch,
58
- } = openpeepsApi.useConversations();
57
+ const query = openpeepsApi.useConversations();
58
+ const archivedQuery = openpeepsApi.useArchivedConversations();
59
59
  const unseenCountsQuery = openpeepsApi.useUnseenPostCounts();
60
60
  const unseenByConversation = unseenCountsQuery.data?.direct ?? {};
61
61
 
62
+ const activeQuery = tab === 'active' ? query : archivedQuery;
63
+ const conversations = useMemo(
64
+ () => activeQuery.data ?? [],
65
+ [activeQuery.data]
66
+ );
67
+
62
68
  const onRefresh = React.useCallback(async () => {
63
69
  setRefreshing(true);
64
- refetch().then(() => {});
70
+ await activeQuery.refetch();
65
71
  setRefreshing(false);
66
- }, [refetch]);
72
+ }, [activeQuery]);
67
73
 
68
74
  useEffect(() => {
69
- if (conversations) {
70
- const filtered = conversations.filter((conversation) =>
71
- conversation.some(
72
- (message) =>
73
- message?.data?.content
74
- ?.toLowerCase()
75
- .includes(searchQuery.toLowerCase()) ||
76
- profileMatchesQuery(message.profile, searchQuery)
77
- )
78
- );
79
- setFilteredConversations(filtered);
80
- }
75
+ const filtered = conversations.filter((conversation) =>
76
+ conversation.some(
77
+ (message) =>
78
+ message?.data?.content
79
+ ?.toLowerCase()
80
+ .includes(searchQuery.toLowerCase()) ||
81
+ profileMatchesQuery(message.profile, searchQuery)
82
+ )
83
+ );
84
+ setFilteredConversations(filtered);
81
85
  }, [conversations, searchQuery]);
82
86
 
83
87
  useSetPageHeader(
@@ -109,6 +113,44 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
109
113
  <DirectMessagesHeaderActions />
110
114
  </View>
111
115
  );
116
+
117
+ const headerTabs = (
118
+ <View className="flex-row border-b border-border">
119
+ <TouchableOpacity
120
+ onPress={() => setTab('active')}
121
+ className={`px-4 py-2 text-sm ${
122
+ tab === 'active'
123
+ ? 'border-primary border-b-2 font-semibold'
124
+ : 'text-muted-foreground'
125
+ }`}
126
+ >
127
+ <ThemedText
128
+ className={
129
+ tab === 'active' ? 'font-semibold' : 'text-muted-foreground'
130
+ }
131
+ >
132
+ {t('conversations.tabs.active', { defaultValue: 'Active' })}
133
+ </ThemedText>
134
+ </TouchableOpacity>
135
+ <TouchableOpacity
136
+ onPress={() => setTab('archived')}
137
+ className={`px-4 py-2 text-sm ${
138
+ tab === 'archived'
139
+ ? 'border-primary border-b-2 font-semibold'
140
+ : 'text-muted-foreground'
141
+ }`}
142
+ >
143
+ <ThemedText
144
+ className={
145
+ tab === 'archived' ? 'font-semibold' : 'text-muted-foreground'
146
+ }
147
+ >
148
+ {t('conversations.tabs.archived', { defaultValue: 'Archived' })}
149
+ </ThemedText>
150
+ </TouchableOpacity>
151
+ </View>
152
+ );
153
+
112
154
  useSetPlusButtonActions(
113
155
  canCreate
114
156
  ? {
@@ -118,8 +160,11 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
118
160
  : undefined
119
161
  );
120
162
 
163
+ const isLoading = activeQuery.isLoading;
164
+
121
165
  return (
122
- <View className="relative flex-1">
166
+ <View className="flex-1">
167
+ {headerTabs}
123
168
  <KeyboardAwareScrollView
124
169
  refreshControl={
125
170
  <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
@@ -129,7 +174,14 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
129
174
  >
130
175
  {isLoading && <ActivityIndicator size={'small'} />}
131
176
  {!isLoading && filteredConversations?.length === 0 && (
132
- <EmptyStateContainer type="messages" copyKey="conversations.empty" />
177
+ <View className="flex h-[80vh] items-center justify-center gap-2">
178
+ <MessageCircleOffIcon size={40} className="text-muted-foreground" />
179
+ <ThemedText className="text-muted-foreground">
180
+ {t('conversations.empty', {
181
+ defaultValue: 'No direct messages here',
182
+ })}
183
+ </ThemedText>
184
+ </View>
133
185
  )}
134
186
  {!isLoading &&
135
187
  filteredConversations?.map((conversation, idx) => (
@@ -16,24 +16,20 @@ import {
16
16
  Platform,
17
17
  ActivityIndicator,
18
18
  } from 'react-native';
19
- import { InfoIcon, SendHorizonalIcon } from '../../components/icons/index';
19
+ import { InfoIcon } from '../../components/icons/index';
20
20
  import { MediaAttachmentData } from '@openpeepshq/common';
21
21
  import { ComposeAttachments } from '../../components/post/post-form/ComposeAttachments';
22
22
  import { OpenpeepsMarkdownInput } from '../../components/post/post-form/OpenpeepsMarkdownInput';
23
23
  import { maxContentLength } from '../../lib/utils';
24
24
  import { DropdownMenu } from '../../components/ui/dropdown-menu';
25
+ import { Button } from '../../components/ui/button';
26
+ import { ThemedText } from '../../components/ui/themed-text';
25
27
  import {
26
28
  ConversationParticipantsModal,
27
29
  ConversationProfileHeader,
28
30
  MessageInThread,
29
31
  } from '../../components/conversations/index';
30
32
 
31
- import {
32
- ProfileBio,
33
- ProfileHandle,
34
- ProfileImages,
35
- ProfileName,
36
- } from '../../components/profile/index';
37
33
  type ConversationProps = MainScreenProps<'Conversation'>;
38
34
 
39
35
  export const ConversationShow = ({ route, navigation }: ConversationProps) => {
@@ -107,17 +103,29 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
107
103
  }, [id, currentProfile, messages, isLoading, markPostsSeen]);
108
104
 
109
105
  useSetPageHeader(
110
- <ConversationProfileHeader
111
- participants={headerParticipants}
112
- onPress={isGroupChat ? () => setParticipantsOpen(true) : undefined}
113
- />,
114
- <TouchableOpacity
115
- onPress={() => navigation.navigate('ConversationInfo', { id })}
116
- >
117
- <InfoIcon size={20} className="text-foreground" />
118
- </TouchableOpacity>
106
+ isLoading ? undefined : (
107
+ <ConversationProfileHeader
108
+ participants={headerParticipants}
109
+ onPress={isGroupChat ? () => setParticipantsOpen(true) : undefined}
110
+ />
111
+ ),
112
+ isLoading ? undefined : (
113
+ <TouchableOpacity
114
+ onPress={() => navigation.navigate('ConversationInfo', { id })}
115
+ >
116
+ <InfoIcon size={18} className="text-foreground" />
117
+ </TouchableOpacity>
118
+ )
119
119
  );
120
120
 
121
+ if (isLoading) {
122
+ return (
123
+ <ThemedView className="flex-1 items-center justify-center">
124
+ <ActivityIndicator size="large" />
125
+ </ThemedView>
126
+ );
127
+ }
128
+
121
129
  return (
122
130
  <ThemedView className="flex-1">
123
131
  <View className="flex-1">
@@ -134,41 +142,6 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
134
142
  scrollViewRef.current?.scrollToEnd({ animated: true })
135
143
  }
136
144
  >
137
- {messages?.[0]?.audience?.length === 2 && (
138
- <View className="bg-background border-b border-border">
139
- <View className="flex items-center justify-center py-6">
140
- <ProfileImages
141
- profile={
142
- messages?.[0].audience.filter(
143
- (p) => p.id !== currentProfile?.id
144
- ) || []
145
- }
146
- />
147
- <ProfileName
148
- profile={
149
- messages?.[0].audience.filter(
150
- (p) => p.id !== currentProfile?.id
151
- ) || []
152
- }
153
- />
154
- <ProfileHandle
155
- profile={
156
- messages?.[0].audience.filter(
157
- (p) => p.id !== currentProfile?.id
158
- ) || []
159
- }
160
- />
161
- <ProfileBio
162
- profile={
163
- messages?.[0].audience.filter(
164
- (p) => p.id !== currentProfile?.id
165
- ) || []
166
- }
167
- />
168
- </View>
169
- </View>
170
- )}
171
-
172
145
  {messages?.map((message, idx) => (
173
146
  <View key={message.id} className="px-2">
174
147
  <MessageInThread
@@ -206,31 +179,28 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
206
179
  })}
207
180
  />
208
181
  <View className="flex-row justify-end">
209
- <TouchableOpacity
182
+ <Button
183
+ variant="default"
210
184
  onPress={handleSendMessage}
211
185
  disabled={
212
186
  isSending ||
213
187
  !content.trim() ||
214
188
  content.length > maxContentLength
215
189
  }
216
- className={`p-2 rounded-full ${
217
- content.trim() && content.length <= maxContentLength
218
- ? 'bg-primary'
219
- : 'bg-surface'
220
- }`}
221
190
  >
222
191
  {isSending ? (
223
- <ActivityIndicator size="small" />
192
+ <View className="flex-row items-center">
193
+ <ActivityIndicator size="small" />
194
+ <ThemedText className="ml-2">
195
+ {t('common.sending', { defaultValue: 'Sending…' })}
196
+ </ThemedText>
197
+ </View>
224
198
  ) : (
225
- <SendHorizonalIcon
226
- className={
227
- content.trim() && content.length <= maxContentLength
228
- ? 'text-primary-foreground'
229
- : 'text-muted-foreground'
230
- }
231
- />
199
+ <ThemedText>
200
+ {t('common.send', { defaultValue: 'Send' })}
201
+ </ThemedText>
232
202
  )}
233
- </TouchableOpacity>
203
+ </Button>
234
204
  </View>
235
205
  </View>
236
206
  </View>
@@ -101,6 +101,11 @@ export const DEFAULT_COLORS: ColorValue[] = [
101
101
  light: '#fafafa',
102
102
  dark: '#18181b',
103
103
  },
104
+ {
105
+ name: 'surface-2',
106
+ light: '#e4e4e7',
107
+ dark: '#3f3f46',
108
+ },
104
109
  ];
105
110
 
106
111
  export const mapColors = (isDark: boolean) =>
@@ -18,7 +18,8 @@ export type ColorName =
18
18
  | 'border'
19
19
  | 'input'
20
20
  | 'ring'
21
- | 'alpha';
21
+ | 'alpha'
22
+ | 'surface-2';
22
23
 
23
24
  export type ColorValue = {
24
25
  name: ColorName;