Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/expo/src/app/friends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ export default function FriendsScreen() {
whispLogo={whispLogo}
colorScheme={colorScheme}
onPressGroupRow={(group) => {
navigation.navigate("Group", { groupId: group.id });
navigation.navigate("Group", {
groupId: group.id,
autoOpenUnread: group.unreadCount > 0,
});
}}
onLongPressGroupRow={(group) => {
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
Expand Down
15 changes: 13 additions & 2 deletions apps/expo/src/app/group.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RouteProp } from "@react-navigation/native";
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";

import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
FlatList,
Pressable,
Expand Down Expand Up @@ -32,7 +32,7 @@ export default function GroupScreen() {
const navigation =
useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const route = useRoute<RouteProp<RootStackParamList, "Group">>();
const { groupId } = route.params;
const { groupId, autoOpenUnread = false } = route.params;
const insets = useSafeAreaInsets();
const colorScheme = useColorScheme();
const iconColor = colorScheme === "dark" ? "#fff" : "#000";
Expand All @@ -58,9 +58,20 @@ export default function GroupScreen() {

const { viewer, openViewer, closeViewer, onViewerTap } =
useGroupMessageViewer(groupId);
const hasAutoOpenedRef = useRef(false);

const isLoading = groupLoading || inboxLoading;

useEffect(() => {
if (!autoOpenUnread) return;
if (hasAutoOpenedRef.current) return;
if (isLoading) return;
if (inboxRaw.length === 0) return;

hasAutoOpenedRef.current = true;
openViewer(inboxRaw, 0);
}, [autoOpenUnread, inboxRaw, isLoading, openViewer]);

const onSendWhisp = useCallback(() => {
navigation.navigate("Main", {
screen: "Camera",
Expand Down
1 change: 1 addition & 0 deletions apps/expo/src/hooks/useFriendRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function useFriendRows({
const senderToLatestMime = new Map<string, string | undefined>();
for (const m of inbox) {
if (!m) continue;
if (m.groupId) continue;
const count = senderToMessages.get(m.senderId) ?? 0;
senderToMessages.set(m.senderId, count + 1);

Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface RootStackParamList extends ParamListBase {
color: string;
}[];
};
Group: { groupId: string };
Group: { groupId: string; autoOpenUnread?: boolean };
GroupSettings: { groupId: string };
GroupAddMembers: { groupId: string };
CreateGroup: undefined;
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/services/message-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function getPendingSentDeliveries(
.where(
and(
inArray(MessageDelivery.recipientId, friendIds),
isNull(MessageDelivery.groupId),
isNull(MessageDelivery.readAt),
),
);
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function getLastSentMimeTypes(
.where(
and(
inArray(MessageDelivery.recipientId, friendIds),
isNull(MessageDelivery.groupId),
eq(Message.senderId, me),
),
)
Expand Down Expand Up @@ -126,6 +128,7 @@ export async function getLastReceivedMimeTypes(
.where(
and(
eq(MessageDelivery.recipientId, me),
isNull(MessageDelivery.groupId),
inArray(Message.senderId, friendIds),
),
)
Expand Down