diff --git a/metro.config.js b/metro.config.js index 062090c731..4448e81d4b 100644 --- a/metro.config.js +++ b/metro.config.js @@ -21,9 +21,12 @@ module.exports = (() => { config.resolver.resolveRequest = (context, moduleName, platform) => { if ( platform !== "web" && - ["redux-persist-electron-storage", "electron", "electron-store"].includes( - moduleName, - ) + [ + "redux-persist-electron-storage", + "electron", + "electron-store", + "react-native-vision-camera", + ].includes(moduleName) ) { return { type: "empty", diff --git a/packages/screens/Mini/Notifications/MessengerNotificationCard.tsx b/packages/screens/Mini/Notifications/MessengerNotificationCard.tsx index b2aee9afa6..355bfe4cad 100644 --- a/packages/screens/Mini/Notifications/MessengerNotificationCard.tsx +++ b/packages/screens/Mini/Notifications/MessengerNotificationCard.tsx @@ -1,4 +1,5 @@ -import React from "react"; +import moment from "moment"; +import React, { useMemo } from "react"; import { View } from "react-native"; import { randomGradients } from "./notificationData"; @@ -27,8 +28,8 @@ export default function MessengerNotificationCard({ }: { item: TypeNotification; }) { - const randomIndex = Math.floor(Math.random() * 4); const navigation = useAppNavigation(); + const randomIndex = useMemo(() => Math.floor(Math.random() * 4), []); return ( { store.dispatch(readNotification({ id: item.id })); - // TODO: Change to appropriate routes - if (item.type === "message") { - navigation.navigate("Conversation", { - conversationId: item?.id, - }); - } - if (item.type === "contact-request") { navigation.navigate("MiniFriend"); } + if (item.type === "group-invite") { + navigation.navigate("Conversation", { conversationId: item?.id }); + } + if (item.type === "group-join") { - navigation.navigate("MiniChats", {}); + navigation.navigate("Conversation", { conversationId: item?.id }); } }} > - {/* */} {item.avatar ? ( - {item.type === "message" && ( + {item.type === "contact-request" && ( )} - {item.type === "contact-request" && ( + {item.type === "group-invite" && ( )} @@ -112,9 +107,8 @@ export default function MessengerNotificationCard({ {item.type === "group-join" && ( )} @@ -127,19 +121,12 @@ interface NotiCardContentProps { isRead: boolean; title: string; date?: string; - desc: string; - link?: string; - user?: { userAvatar?: string; username: string; id: string }; } function NotificationCardInnerContent({ - id, title, date, - desc, - link, isRead, - user, }: NotiCardContentProps) { return ( - - {/* */} - {/* - - {desc} - - - {user && ( - <> - {user?.userAvatar ? ( - <> - - - - {user.username} - - - ) : ( - <> - - - - - {user?.username} - - - )} - - )} - - {link && ( - <> - - {link} - - )} - */} - {date} + {moment(date).fromNow()} {!isRead ? ( diff --git a/packages/store/slices/notification.ts b/packages/store/slices/notification.ts index 47c0042deb..bfa59515e2 100644 --- a/packages/store/slices/notification.ts +++ b/packages/store/slices/notification.ts @@ -8,7 +8,11 @@ import { z } from "zod"; import { RootState } from "../store"; -const NotificationType = z.enum(["message", "group-join", "contact-request"]); +const NotificationType = z.enum([ + "group-invite", + "contact-request", + "group-join", +]); export const Notification = z.object({ id: z.string(), @@ -57,6 +61,18 @@ const notificationSlice = createSlice({ }); } }, + removeNotification: (state, action: PayloadAction<{ id: string }>) => { + if (action.payload.id) { + const notification = notificationSelectors.selectById( + state, + action.payload.id, + ); + + if (!notification) return; + + notificationEntityAdapter.removeOne(state, notification.id); + } + }, setNotificationList: (state, action: PayloadAction) => { notificationEntityAdapter.setAll(state, action.payload); }, diff --git a/packages/weshnet/message/processEvent.ts b/packages/weshnet/message/processEvent.ts index 49c5e8ccf6..51cd0cdc03 100644 --- a/packages/weshnet/message/processEvent.ts +++ b/packages/weshnet/message/processEvent.ts @@ -79,15 +79,19 @@ export const processMessage = async ( data: message, }), ); - } - store.dispatch( - setNotificationRequest({ - id: groupPk, - type: "group-join", - isRead: false, - }), - ); + if (!isSender) { + store.dispatch( + setNotificationRequest({ + id: groupPk, + name: message?.payload?.metadata?.groupName, + type: "group-invite", + timestamp: message?.timestamp, + isRead: false, + }), + ); + } + } break; } @@ -136,6 +140,7 @@ export const processMessage = async ( ...data, }), ); + break; } default: { diff --git a/packages/weshnet/metadata/processEvent.ts b/packages/weshnet/metadata/processEvent.ts index c711e0946b..0547371933 100644 --- a/packages/weshnet/metadata/processEvent.ts +++ b/packages/weshnet/metadata/processEvent.ts @@ -8,6 +8,7 @@ import { } from "../../api/weshnet/protocoltypes"; import { selectContactRequestList, + selectConversationList, setContactRequest, setContactRequestList, setConversationList, @@ -17,10 +18,7 @@ import { weshClient } from "../client"; import { subscribeMessages } from "../message/subscriber"; import { bytesFromString, decodeJSON, stringFromBytes } from "../utils"; -import { - setNotificationList, - setNotificationRequest, -} from "@/store/slices/notification"; +import { setNotificationRequest } from "@/store/slices/notification"; const processedMetadataIds: string[] = []; @@ -126,23 +124,6 @@ export const processMetadata = async (data: GroupMetadataEvent) => { ), ), ); - - store.dispatch( - setNotificationList( - contactRequests - .filter( - (item) => - item.contactId !== - stringFromBytes(parsedData.payload.contactPk), - ) - .map((notification) => ({ - id: notification.id, - type: "contact-request", - isRead: false, - })), - ), - ); - break; } case EventType.EventTypeAccountContactRequestIncomingAccepted: { @@ -170,21 +151,7 @@ export const processMetadata = async (data: GroupMetadataEvent) => { ), ), ); - store.dispatch( - setNotificationList( - contactRequests - .filter( - (item) => - item.contactId !== - stringFromBytes(parsedData.payload.contactPk), - ) - .map((notification) => ({ - id: notification.id, - type: "contact-request", - isRead: false, - })), - ), - ); + const group = await weshClient.client.GroupInfo({ contactPk: bytesFromString(contactRequest.contactId), }); @@ -217,17 +184,38 @@ export const processMetadata = async (data: GroupMetadataEvent) => { } case EventType.EventTypeAccountGroupJoined: { const parsedData: any = GroupMetadataEvent.toJSON(data); - + const conversationList = selectConversationList(store.getState()); parsedData.payload = AccountGroupJoined.decode(data.metadata.payload); + + const groupPk = stringFromBytes(parsedData.payload.group.publicKey); + console.log("group-join"); + const selectedGroup = conversationList.filter( + (singleConv) => singleConv.id === groupPk, + )[0]; + store.dispatch( setConversationList({ id: stringFromBytes(parsedData.payload.group.publicKey), type: "group", - members: [], + members: [parsedData.payload.contactPk], name: "Group", status: "active", }), ); + + if ( + selectedGroup && + !selectedGroup?.members.includes(parsedData.payload.contackPk) + ) { + store.dispatch( + setNotificationRequest({ + id: stringFromBytes(parsedData.payload.group.publicKey), + type: "group-join", + isRead: false, + }), + ); + } + subscribeMessages(stringFromBytes(parsedData.payload.group.publicKey)); break;