Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EjembiEmmanuel/afk_monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
EjembiEmmanuel committed Aug 30, 2024
2 parents b50f14d + 86f4e4f commit f645a46
Show file tree
Hide file tree
Showing 27 changed files with 349 additions and 77 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
"contributions": [
"code"
]
},
{
"login": "PoulavBhowmick03",
"name": "Poulav Bhowmick",
"avatar_url": "https://avatars.githubusercontent.com/u/133862694?v=4",
"profile": "https://poulav.vercel.app/",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/manlikeHB"><img src="https://avatars.githubusercontent.com/u/109147010?v=4?s=100" width="100px;" alt="Yusuf Habib"/><br /><sub><b>Yusuf Habib</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=manlikeHB" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://isaaconyemaechi.tech/"><img src="https://avatars.githubusercontent.com/u/116242877?v=4?s=100" width="100px;" alt="Isaac Onyemaechi Ugwu"/><br /><sub><b>Isaac Onyemaechi Ugwu</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=Dprof-in-tech" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/EjembiEmmanuel"><img src="https://avatars.githubusercontent.com/u/83036156?v=4?s=100" width="100px;" alt="Oche"/><br /><sub><b>Oche</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=EjembiEmmanuel" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://poulav.vercel.app/"><img src="https://avatars.githubusercontent.com/u/133862694?v=4?s=100" width="100px;" alt="Poulav Bhowmick"/><br /><sub><b>Poulav Bhowmick</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=PoulavBhowmick03" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
Expand Down
55 changes: 55 additions & 0 deletions apps/indexer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,61 @@ services:
- backend
restart: on-failure

buy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/buy-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure


sell-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/sell-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure

token-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/token-launch.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure

deploy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/deploy-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure



networks:
backend:
driver: bridge
12 changes: 7 additions & 5 deletions apps/mobile/src/components/PrivateKeyImport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export const PrivateKeyImport: React.FC = () => {
showToast({type: 'error', title: 'Password is required'});
return;
}
const passwordRetrieve = await retrievePassword();
if (password != passwordRetrieve) {
showToast({type: 'error', title: 'Invalid password'});
return;
}

/** TODO fix in web */
// const passwordRetrieve = await retrievePassword();
// if (password != passwordRetrieve) {
// showToast({type: 'error', title: 'Invalid password'});
// return;
// }
const privateKey = await retrieveAndDecryptPrivateKey(password);
if (!privateKey || privateKey.length !== 32) {
showToast({type: 'error', title: 'Invalid password'});
Expand Down
17 changes: 10 additions & 7 deletions apps/mobile/src/modules/Group/all/AllGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useNavigation} from '@react-navigation/native';
import {useAuth, useGetAllGroupList, useGetGroupList} from 'afk_nostr_sdk';
import {FlatList, SafeAreaView, Text, TouchableOpacity, View} from 'react-native';
import {ActivityIndicator, FlatList, SafeAreaView, Text, TouchableOpacity, View} from 'react-native';

import {PadlockIcon, SlantedArrowIcon} from '../../../assets/icons';
import {useStyles} from '../../../hooks';
Expand All @@ -11,14 +11,15 @@ export default function AllGroupListComponent() {
const {publicKey: pubKey} = useAuth();

const data = useGetGroupList({
pubKey,
});
const allGroup = useGetAllGroupList({
pubKey,
// pubKey,
});
// const allGroup = useGetAllGroupList({
// pubKey,
// });

console.log(allGroup.data, 'AllGroup');
console.log(data.data, 'AllGroup2');
// console.log("AllGroup", allGroup.data);
console.log("AllGroup", data.data);
// console.log(data.data, 'AllGroup2');

const styles = useStyles(stylesheet);
const navigation = useNavigation<MainStackNavigationProps>();
Expand All @@ -28,6 +29,8 @@ export default function AllGroupListComponent() {
<View style={styles.header}>
<Text style={styles.headerTitle}>My Groups</Text>
</View>

{data?.data?.pages?.length == 0 && <ActivityIndicator></ActivityIndicator>}
<FlatList
data={data.data.pages.flat()}
renderItem={({item}: any) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useQueryClient} from '@tanstack/react-query';
import {useAuth, useDeleteGroup, useGetGroupMemberList, useGetGroupMetadata} from 'afk_nostr_sdk';
import React, {useRef, useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {FlatList, Pressable, SafeAreaView, TouchableOpacity, View} from 'react-native';

import {AddPostIcon, BackIcon, EditIcon, TrashIcon, UserPlusIcon} from '../../../assets/icons';
Expand Down Expand Up @@ -32,6 +32,12 @@ const GroupChatDetail: React.FC<GroupChatDetailScreenProps> = ({navigation, rout
const styles = useStyles(stylesheet);
const [selectedMember, setSelectedMember] = useState();

/** Todo check if user is already added as a member */
useEffect(() => {

},[])


const onOpen = (selected: any) => {
modalizeRef.current?.open();
setSelectedMember(selected);
Expand Down
123 changes: 95 additions & 28 deletions apps/mobile/src/modules/Group/message/GroupMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,75 @@
import {useQueryClient} from '@tanstack/react-query';
import { useQueryClient } from '@tanstack/react-query';
import {
AdminGroupPermission,
useAuth,
useGetGroupMemberList,
useGetGroupMemberListPubkey,
useGetGroupMessages,
useJoinGroupRequest,
useNostrContext,
useProfile,
useSendGroupMessages,
} from 'afk_nostr_sdk';
import React, {useState} from 'react';
import {FlatList, Modal, Pressable, SafeAreaView, Text, TouchableOpacity, View} from 'react-native';

import {BackIcon, MenuIcons} from '../../../assets/icons';
import {IconButton, Input, KeyboardFixedView} from '../../../components';
import {useStyles} from '../../../hooks';
import {useToast} from '../../../hooks/modals';
import {GroupChatScreenProps} from '../../../types';
import React, { useEffect, useState } from 'react';
import { FlatList, Modal, Pressable, SafeAreaView, Text, TouchableOpacity, View } from 'react-native';

import { BackIcon, MenuIcons } from '../../../assets/icons';
import { IconButton, Input, KeyboardFixedView } from '../../../components';
import { useStyles } from '../../../hooks';
import { useToast } from '../../../hooks/modals';
import { GroupChatScreenProps } from '../../../types';
import stylesheet from './styles';
import { checkGroupPermission } from 'afk_nostr_sdk/src/hooks/group/private/useGetPermission';
import { NDKEvent } from '@nostr-dev-kit/ndk';

const GroupChat: React.FC<GroupChatScreenProps> = ({ navigation, route }) => {
const { publicKey } = useAuth();
const ndk = useNostrContext()
const groupdId = route.params.groupId

Check warning on line 28 in apps/mobile/src/modules/Group/message/GroupMessage.tsx

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"groupd" should be "grouped".

const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
const {publicKey} = useAuth();
const memberListData = useGetGroupMemberList({
const memberListData = useGetGroupMemberListPubkey({
groupId: route.params.groupId,
});
const profile = useProfile({publicKey});

const joinRequest = useJoinGroupRequest()
const profile = useProfile({ publicKey });
const [menuVisible, setMenuVisible] = useState(false);
const [isUserMember, setIsUserMember] = useState(false);
const [replyToId, setReplyToId] = useState(null);
const [replyToContent, setReplyToContent] = useState('');
const [selectedMessageId, setSelectedMessageId] = useState(null);
const queryClient = useQueryClient();
const {showToast} = useToast();
const {data: messageData} = useGetGroupMessages({
const { showToast } = useToast();
const { data: messageData } = useGetGroupMessages({
groupId: route.params.groupId,
authors: publicKey,
});
const {mutate} = useSendGroupMessages();
const { mutate } = useSendGroupMessages();
const styles = useStyles(stylesheet);
const [message, setMessage] = useState('');

/** Todo check if user is a member */
useEffect(() => {

const getUserIsMember = () => {
let isMember = memberListData?.data?.pages?.flat().find((e: NDKEvent) => {
console.log("e", e)
const pubkey = e?.tags?.find((tag: string[]) => tag[0] === 'p')?.[1];
console.log("pubKey", pubkey)
if (pubkey == publicKey) {
console.log("pubkey == publicKey", pubkey == publicKey)

return e
}
return undefined;
})
if (isMember) setIsUserMember(true)
}

getUserIsMember()

}, [memberListData])

const handleLongPress = (messageId: any, messageContent: string) => {
setSelectedMessageId(messageId);
setReplyToContent(messageContent);
Expand All @@ -62,8 +96,8 @@ const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
},
{
onSuccess() {
showToast({type: 'success', title: 'Message sent successfully'});
queryClient.invalidateQueries({queryKey: ['getGroupMessages', route.params.groupId]});
showToast({ type: 'success', title: 'Message sent successfully' });
queryClient.invalidateQueries({ queryKey: ['getGroupMessages', route.params.groupId] });
setMessage('');
setReplyToId(null);
setReplyToContent('');
Expand All @@ -78,6 +112,23 @@ const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
);
};

const requestToJoin = () => {

joinRequest.mutateAsync({
groupId: groupdId,

Check warning on line 118 in apps/mobile/src/modules/Group/message/GroupMessage.tsx

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"groupd" should be "grouped".



},
{
onSuccess: () => {

},
},
)

};

return (
<SafeAreaView style={styles.container}>
<View style={styles.header}>
Expand All @@ -103,17 +154,33 @@ const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
<MenuIcons stroke="gray" />
</TouchableOpacity>
</View>
<FlatList
data={messageData.pages.flat()}
renderItem={({item}: any) => <MessageCard handleLongPress={handleLongPress} item={item} />}
keyExtractor={(item: any) => item.id}
contentContainerStyle={styles.messageList}
inverted
/>

{isUserMember &&
<FlatList
data={messageData.pages.flat()}
renderItem={({ item }: any) => <MessageCard handleLongPress={handleLongPress} item={item} />}
keyExtractor={(item: any) => item.id}
contentContainerStyle={styles.messageList}
inverted
/>
}

{!isUserMember &&

<View>

<Text>You are not a member</Text>
<Text>Request to join the group</Text>

<IconButton onPress={() => requestToJoin()} icon="SendIcon" size={24} />

</View>
}


{replyToId && <ReplyIndicator message={replyToContent} onCancel={cancelReply} />}

<KeyboardFixedView containerProps={{style: styles.inputContainer}}>
<KeyboardFixedView containerProps={{ style: styles.inputContainer }}>
<View style={styles.inputContent}>
<Input
multiline
Expand Down Expand Up @@ -171,7 +238,7 @@ const MessageCard = ({
);
};

const ReplyIndicator = ({message, onCancel}: {onCancel: () => void; message: string}) => {
const ReplyIndicator = ({ message, onCancel }: { onCancel: () => void; message: string }) => {
const styles = useStyles(stylesheet);
return (
<View style={styles.replyIndicator}>
Expand Down Expand Up @@ -202,7 +269,7 @@ const LongPressMenu = ({
<Pressable style={styles.modalOverlay} onPress={onClose}>
<View style={styles.menuContainer}>
<Pressable style={styles.menuItem} onPress={onReply}>
<Text style={{color: 'white'}}>Reply Message</Text>
<Text style={{ color: 'white' }}>Reply Message</Text>
</Pressable>
</View>
</Pressable>
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/screens/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Feed: React.FC<FeedScreenProps> = ({ navigation }) => {
]);

const contacts = useContacts()
console.log("contacts", contacts)
// console.log("contacts", contacts)
const notes = useSearch({
// search: search,
kinds,
Expand Down Expand Up @@ -63,10 +63,11 @@ export const Feed: React.FC<FeedScreenProps> = ({ navigation }) => {
setKinds={setKinds}
setSortBy={setSortBy}
sortBy={activeSortBy}
contactList={contacts?.data?.map((item) => item)}
// contactList={contacts?.data?.map((item) => item)}
/>

{notes?.isLoading && <ActivityIndicator></ActivityIndicator>}
{notes?.data?.pages?.length == 0 && <ActivityIndicator></ActivityIndicator>}

<FlatList
ListHeaderComponent={<>
Expand Down
12 changes: 6 additions & 6 deletions apps/mobile/src/types/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export const TABS_TIP_LIST: {screen?: string; title: string; tab: SelectedTab}[]
tab: SelectedTab.TIPS,
},
{
title: 'Messages',
screen: 'Messages',
tab: SelectedTab.MESSAGES,
title: 'All Group',
screen: 'AllGroup',
tab: SelectedTab.ALL_GROUP,
},
{
title: 'Channels',
screen: 'ChannelsFeed',
tab: SelectedTab.CHANNELS,
},
{
title: 'All Group',
screen: 'AllGroup',
tab: SelectedTab.ALL_GROUP,
title: 'Messages',
screen: 'Messages',
tab: SelectedTab.MESSAGES,
},
// {
// title: 'Messages',
Expand Down
Loading

0 comments on commit f645a46

Please sign in to comment.