Skip to content

Commit

Permalink
Offline and Contacts fixes (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat authored Dec 11, 2023
2 parents b04544c + c2fcbfe commit 5679289
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 86 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.apk
**Torrent**
https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.torrent
**Changelog**
https://github.com/KoalaSat/nostros/releases/${{ github.ref_name }}
Expand Down Expand Up @@ -75,4 +79,13 @@ jobs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: app-armeabi-v7a-release.apk
asset_name: nostros-${{ github.ref_name }}-armeabi-v7a.apk
asset_content_type: application/apk
asset_content_type: application/apk
- name: Install torf-cli
run: sudo pip3 install torf-cli
- name: Create torrent using torf-cli
run: torf "nostros-${{ github.ref_name }}-universal.apk" -o "nostros-${{ github.ref_name }}-universal.torrent" -w "https://github.com/KoalaSat/nostros/releases/download/${{ github.ref_name }}/nostros-${{ github.ref_name }}-universal.apk" -s "torrent-webseed-creator"
- name: Upload torrent file
uses: actions/upload-artifact@v3
with:
name: Torrent
path: nostros-${{ github.ref_name }}-universal.torrent
2 changes: 1 addition & 1 deletion frontend/Components/MenuItems/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const MenuItems: React.FC = () => {
/>
</TouchableRipple>
<View style={styles.cardEdit}>
{privateKey && (
{privateKey && online && (
<IconButton
icon='pencil-outline'
size={20}
Expand Down
4 changes: 2 additions & 2 deletions frontend/Components/NoteCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export const NoteCard: React.FC<NoteCardProps> = ({
<View style={styles.reactionsPopupContent}>
<Button
onPress={() => {
if (!userDownvoted && privateKey) {
if (!userDownvoted && privateKey && online) {
setUserDownvoted(true)
setNegativeReactions((prev) => prev + 1)
publishReaction(false)
Expand All @@ -325,7 +325,7 @@ export const NoteCard: React.FC<NoteCardProps> = ({
</Button>
<Button
onPress={() => {
if (!userUpvoted && privateKey) {
if (!userUpvoted && privateKey && online) {
setUserUpvoted(true)
setPositiveReactions((prev) => prev + 1)
publishReaction(true)
Expand Down
5 changes: 0 additions & 5 deletions frontend/Contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface AppContextProps {
setClipboardNip21: (clipboardNip21: string | undefined) => void
checkClipboard: () => void
displayUserDrawer?: string
setDisplayUserDrawer: (displayUserDrawer: string | undefined) => void
displayNoteDrawer?: string
refreshBottomBarAt?: number
setRefreshBottomBarAt: (refreshBottomBarAt: number) => void
Expand Down Expand Up @@ -98,7 +97,6 @@ export const initialAppContext: AppContextProps = {
getImageHostingService: () => '',
getSatoshiSymbol: () => <></>,
setClipboardNip21: () => {},
setDisplayUserDrawer: () => {},
longPressZap: undefined,
setLongPressZap: () => {},
signHeight: false,
Expand Down Expand Up @@ -130,7 +128,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps): JSX.E
const [loadingDb, setLoadingDb] = useState<boolean>(initialAppContext.loadingDb)
const [clipboardLoads, setClipboardLoads] = React.useState<string[]>([])
const [clipboardNip21, setClipboardNip21] = React.useState<string>()
const [displayUserDrawer, setDisplayUserDrawer] = React.useState<string>()
const [pushedTab, setPushedTab] = useState<string>()
const [signHeight, setSignWithHeight] = useState<boolean>(initialAppContext.signHeight)
const [online, setOnline] = React.useState<boolean>(initialAppContext.online)
Expand Down Expand Up @@ -249,8 +246,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps): JSX.E
value={{
relayColouring,
setRelayColouring,
displayUserDrawer,
setDisplayUserDrawer,
language,
setLanguage,
checkClipboard,
Expand Down
1 change: 1 addition & 0 deletions frontend/Functions/DatabaseFunctions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const dropTables: (db: QuickSQLiteConnection) => Promise<BatchQueryResult
['DELETE FROM nostros_reactions;', [[]]],
['DELETE FROM nostros_relays;', [[]]],
['DELETE FROM nostros_notes_relays;', [[]]],
['DELETE FROM nostros_relay_metadata;', [[]]],
['DELETE FROM nostros_direct_messages;', [[]]],
['DELETE FROM nostros_group_meta;', [[]]],
['DELETE FROM nostros_group_messages;', [[]]],
Expand Down
14 changes: 4 additions & 10 deletions frontend/Pages/ContactsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import ProfileData from '../../Components/ProfileData'
import { handleInfinityScroll } from '../../Functions/NativeFunctions'
import DatabaseModule from '../../lib/Native/DatabaseModule'
import { removeMutedUsersList } from '../../Functions/RelayFunctions/Lists'
import { push } from '../../lib/Navigation'

export const ContactsPage: React.FC = () => {
const { t } = useTranslation('common')
const theme = useTheme()
const initialPageSize = 20
const { database, setDisplayUserDrawer, qrReader, setQrReader, online } = useContext(AppContext)
const { database, qrReader, setQrReader, online } = useContext(AppContext)
const { privateKey, publicKey, nPub, mutedUsers, reloadLists } = React.useContext(UserContext)
const { relayPool, lastEventId, sendEvent } = useContext(RelayPoolContext)
const [pageSize, setPageSize] = useState<number>(initialPageSize)
const bottomSheetAddContactRef = React.useRef<RBSheet>(null)
const bottomSheetProfileRef = React.useRef<RBSheet>(null)
// State
const [followers, setFollowers] = useState<User[]>([])
const [following, setFollowing] = useState<User[]>([])
Expand Down Expand Up @@ -208,10 +208,7 @@ export const ContactsPage: React.FC = () => {
const renderContactItem: ListRenderItem<User> = ({ index, item }) => {
return (
<TouchableRipple
onPress={() => {
setDisplayUserDrawer(item.id)
bottomSheetProfileRef.current?.open()
}}
onPress={() => push('ProfileActions', { userId: item.id, title: item?.name })}
>
<View key={item.id} style={styles.contactRow}>
<View style={styles.profileData}>
Expand All @@ -238,10 +235,7 @@ export const ContactsPage: React.FC = () => {
const renderMutedItem: ListRenderItem<User> = ({ index, item }) => {
return (
<TouchableRipple
onPress={() => {
setDisplayUserDrawer(item.id)
bottomSheetProfileRef.current?.open()
}}
onPress={() => push('ProfileActions', { userId: item.id, title: item?.name })}
>
<View key={item.id} style={styles.contactRow}>
<View style={styles.profileData}>
Expand Down
13 changes: 7 additions & 6 deletions frontend/Pages/ConversationPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import UploadImage from '../../Components/UploadImage'
import { Swipeable } from 'react-native-gesture-handler'
import { getETags } from '../../Functions/RelayFunctions/Events'
import DatabaseModule from '../../lib/Native/DatabaseModule'
import { push } from '../../lib/Navigation'

interface ConversationPageProps {
route: { params: { pubKey: string; conversationId: string } }
Expand All @@ -50,8 +51,8 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
const initialPageSize = 10
const theme = useTheme()
const scrollViewRef = useRef<ScrollView>()
const { database, setRefreshBottomBarAt, setDisplayUserDrawer } = useContext(AppContext)
const { relayPool, lastEventId, sendEvent, online } = useContext(RelayPoolContext)
const { database, setRefreshBottomBarAt, online } = useContext(AppContext)
const { relayPool, lastEventId, sendEvent } = useContext(RelayPoolContext)
const { publicKey, privateKey, name, picture, validNip05 } = useContext(UserContext)
const otherPubKey = useMemo(() => route.params.pubKey, [])
const [pageSize, setPageSize] = useState<number>(initialPageSize)
Expand Down Expand Up @@ -254,7 +255,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
<TextContent
content={message?.content}
event={message}
onPressUser={(user) => setDisplayUserDrawer(user.id)}
onPressUser={(user) => push('ProfileActions', { userId: user.id, title: user?.name })}
copyText
/>
) : (
Expand Down Expand Up @@ -292,7 +293,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
{publicKey !== item.pubkey && (
<View style={styles.pictureSpaceLeft}>
{showAvatar && (
<TouchableRipple onPress={() => setDisplayUserDrawer(otherPubKey)}>
<TouchableRipple onPress={() => push('ProfileActions', { userId: otherUser.id, title: otherUser.name })}>
<NostrosAvatar
name={otherUser.name}
pubKey={otherPubKey}
Expand Down Expand Up @@ -334,7 +335,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
{publicKey === item.pubkey && (
<View style={styles.pictureSpaceRight}>
{showAvatar && (
<TouchableRipple onPress={() => setDisplayUserDrawer(publicKey)}>
<TouchableRipple onPress={() => push('ProfileActions', { userId: publicKey, title: name })}>
<NostrosAvatar name={name} pubKey={publicKey} src={picture} size={40} />
</TouchableRipple>
)}
Expand Down Expand Up @@ -400,7 +401,7 @@ export const ConversationPage: React.FC<ConversationPageProps> = ({ route }) =>
<TextContent
content={reply.content}
event={reply}
onPressUser={(user) => setDisplayUserDrawer(user.id)}
onPressUser={(user) => push('ProfileActions', { userId: user.id, title: user?.name })}
showPreview={false}
numberOfLines={3}
/>
Expand Down
11 changes: 6 additions & 5 deletions frontend/Pages/GroupPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ProfileData from '../../Components/ProfileData'
import { ScrollView, Swipeable } from 'react-native-gesture-handler'
import { getETags } from '../../Functions/RelayFunctions/Events'
import DatabaseModule from '../../lib/Native/DatabaseModule'
import { push } from '../../lib/Navigation'

interface GroupPageProps {
route: { params: { groupId: string } }
Expand All @@ -46,7 +47,7 @@ interface GroupPageProps {
export const GroupPage: React.FC<GroupPageProps> = ({ route }) => {
const initialPageSize = 20
const theme = useTheme()
const { database, setDisplayUserDrawer, online } = useContext(AppContext)
const { database, online } = useContext(AppContext)
const { relayPool, lastEventId, sendEvent } = useContext(RelayPoolContext)
const { publicKey, privateKey, name, picture, validNip05 } = useContext(UserContext)
const [pageSize, setPageSize] = useState<number>(initialPageSize)
Expand Down Expand Up @@ -308,7 +309,7 @@ export const GroupPage: React.FC<GroupPageProps> = ({ route }) => {
<TextContent
content={message?.content}
event={message}
onPressUser={(user) => setDisplayUserDrawer(user.id)}
onPressUser={(user) => push('ProfileActions', { userId: user.id, title: user?.name })}
copyText
/>
) : (
Expand All @@ -335,7 +336,7 @@ export const GroupPage: React.FC<GroupPageProps> = ({ route }) => {
{publicKey !== item.pubkey && (
<View style={styles.pictureSpaceLeft}>
{showAvatar && (
<TouchableRipple onPress={() => setDisplayUserDrawer(item.pubkey)}>
<TouchableRipple onPress={() => push('ProfileActions', { userId: item.id, title: item?.name })}>
<NostrosAvatar
name={displayName(item)}
pubKey={item.pubkey}
Expand Down Expand Up @@ -379,7 +380,7 @@ export const GroupPage: React.FC<GroupPageProps> = ({ route }) => {
{publicKey === item.pubkey && (
<View style={styles.pictureSpaceRight}>
{showAvatar && (
<TouchableRipple onPress={() => setDisplayUserDrawer(publicKey)}>
<TouchableRipple onPress={() => push('ProfileActions', { userId: publicKey, title: name })}>
<NostrosAvatar name={name} pubKey={publicKey} src={picture} size={40} />
</TouchableRipple>
)}
Expand Down Expand Up @@ -435,7 +436,7 @@ export const GroupPage: React.FC<GroupPageProps> = ({ route }) => {
<TextContent
content={reply.content}
event={reply}
onPressUser={(user) => setDisplayUserDrawer(user.id)}
onPressUser={(user) => push('ProfileActions', { userId: user.id, title: user?.name })}
showPreview={false}
numberOfLines={3}
/>
Expand Down
20 changes: 11 additions & 9 deletions frontend/Pages/HomePage/ConversationsFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,17 @@ export const ConversationsFeed: React.FC = () => {
</Button>
</View>
)}
<AnimatedFAB
style={[styles.fab, { top: Dimensions.get('window').height - 191 }]}
icon='pencil-outline'
label='Label'
onPress={() => bottomSheetCreateRef.current?.open()}
animateFrom='right'
iconMode='static'
extended={false}
/>
{privateKey && online && (
<AnimatedFAB
style={[styles.fab, { top: Dimensions.get('window').height - 191 }]}
icon='pencil-outline'
label='Label'
onPress={() => bottomSheetCreateRef.current?.open()}
animateFrom='right'
iconMode='static'
extended={false}
/>
)}
<RBSheet ref={bottomSheetCreateRef} closeOnDragDown={true} customStyles={bottomSheetStyles}>
<FlatList
data={createOptions}
Expand Down
22 changes: 12 additions & 10 deletions frontend/Pages/HomePage/GroupsFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const GroupsFeed: React.FC = () => {
const { t } = useTranslation('common')
const theme = useTheme()
const { database, qrReader, setQrReader, refreshBottomBarAt, online } = useContext(AppContext)
const { publicKey } = useContext(UserContext)
const { publicKey, privateKey } = useContext(UserContext)
const { relayPool, lastEventId, lastConfirmationtId, sendEvent, setNewGroupMessages, newGroupMessages } = useContext(RelayPoolContext)
const bottomSheetSearchRef = React.useRef<RBSheet>(null)
const bottomSheetCreateRef = React.useRef<RBSheet>(null)
Expand Down Expand Up @@ -297,15 +297,17 @@ export const GroupsFeed: React.FC = () => {
horizontal={false}
estimatedItemSize={76}
/>
<AnimatedFAB
style={[styles.fab, { top: Dimensions.get('window').height - 191 }]}
icon='plus'
label='Label'
onPress={() => bottomSheetFabActionRef.current?.open()}
animateFrom='right'
iconMode='static'
extended={false}
/>
{privateKey && online && (
<AnimatedFAB
style={[styles.fab, { top: Dimensions.get('window').height - 191 }]}
icon='plus'
label='Label'
onPress={() => bottomSheetFabActionRef.current?.open()}
animateFrom='right'
iconMode='static'
extended={false}
/>
)}
<RBSheet ref={bottomSheetCreateRef} closeOnDragDown={true} customStyles={bottomSheetStyles}>
<View>
<Text style={styles.input} variant='titleLarge'>
Expand Down
4 changes: 3 additions & 1 deletion frontend/Pages/HomePage/HomeFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Tabs from '../../../Components/Tabs'
import ZapsFeed from './ZapsFeed'
import BookmarksFeed from './BookmarksFeed'
import { RelayPoolContext } from '../../../Contexts/RelayPoolContext'
import { AppContext } from '../../../Contexts/AppContext'

interface HomeFeedProps {
navigation: any
}

export const HomeFeed: React.FC<HomeFeedProps> = ({ navigation }) => {
const { online } = useContext(AppContext)
const { privateKey, publicKey } = useContext(UserContext)
const { relayPool } = useContext(RelayPoolContext)
const [activeTab, setActiveTab] = React.useState('myFeed')
Expand Down Expand Up @@ -80,7 +82,7 @@ export const HomeFeed: React.FC<HomeFeedProps> = ({ navigation }) => {
defaultTab='myFeed'
/>
<View style={styles.feed}>{renderScene[activeTab]}</View>
{privateKey && (
{privateKey && online && (
<AnimatedFAB
style={[styles.fab, { top: Dimensions.get('window').height - 191 }]}
icon='pencil-outline'
Expand Down
2 changes: 1 addition & 1 deletion frontend/Pages/NotePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const NotePage: React.FC<NotePageProps> = ({ route }) => {
/>
</View>
</ScrollView>
{privateKey && (
{privateKey && online && (
<AnimatedFAB
style={[styles.fabSend, { top: Dimensions.get('window').height - 136 }]}
icon='message-plus-outline'
Expand Down
12 changes: 6 additions & 6 deletions frontend/Pages/ProfileCreatePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ interface ProfileCreatePageProps {
export const ProfileCreatePage: React.FC<ProfileCreatePageProps> = ({ navigation }) => {
const { t } = useTranslation('common')
const { setPrivateKey, setUserState, publicKey } = useContext(UserContext)
const { createRandomRelays, sendEvent, relays } = useContext(RelayPoolContext)
const [key, setKey] = useState<string>()
const { createRandomRelays, sendEvent, relays, relayPoolReady } = useContext(RelayPoolContext)
const [inputValue, setInputValue] = useState<string>()
const [keyboardShow, setKeyboardShow] = useState<boolean>(false)
const [step, setStep] = useState<number>(0)
Expand All @@ -35,13 +34,16 @@ export const ProfileCreatePage: React.FC<ProfileCreatePageProps> = ({ navigation
generateRandomMnemonic().then((words) => {
setMnemonicWords(words)
const privateKey = nip06.privateKeyFromSeedWords(Object.values(words).join(' '))
setKey(privateKey)
setPrivateKey(privateKey)
const nsec = nip19.nsecEncode(privateKey)
setInputValue(nsec)
})
createRandomRelays()
}, [])

React.useEffect(() => {
if (relayPoolReady) createRandomRelays()
}, [relayPoolReady])

useEffect(() => {
if (inputValue) setLoading(false)
}, [inputValue])
Expand Down Expand Up @@ -92,7 +94,6 @@ export const ProfileCreatePage: React.FC<ProfileCreatePageProps> = ({ navigation
sendEvent(event)
}
if (validConfirmation()) {
setPrivateKey(key)
publishRelays()
setUserState('ready')
} else {
Expand All @@ -104,7 +105,6 @@ export const ProfileCreatePage: React.FC<ProfileCreatePageProps> = ({ navigation
}

const onPressSkip: () => void = () => {
setPrivateKey(key)
publishRelays()
setUserState('ready')
}
Expand Down
Loading

0 comments on commit 5679289

Please sign in to comment.