Skip to content

Commit

Permalink
Merge pull request #422 from arkin0x/social-graph
Browse files Browse the repository at this point in the history
implement basic reputation visualization in chats
  • Loading branch information
reyamir authored Jul 22, 2023
2 parents c909609 + 3e031e2 commit 260b777
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/components/RelayProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ArcadeIdentity,
NostrPool,
ArcadeDb,
ArcadeSocial,
ChannelManager,
PrivateMessageManager,
} from "app/arclib/src"
Expand All @@ -18,6 +19,7 @@ export const RelayContext = createContext({
contactManager: null as ContactManager,
profileManager: null as ProfileManager,
privMessageManager: null as PrivateMessageManager,
social: null as ArcadeSocial,
})
const db: ArcadeDb = connectDb()

Expand All @@ -36,6 +38,7 @@ export const RelayProvider = observer(function RelayProvider({
const [pool, _setPool] = useState<NostrPool>(
() => new NostrPool(ident, db, { skipVerification: true }),
)
const social = useMemo(() => new ArcadeSocial(pool, ident), [pool, ident])
const channelManager = useMemo(() => new ChannelManager(pool), [pool])
const contactManager = useMemo(() => new ContactManager(pool), [pool])
const profileManager = useMemo(() => new ProfileManager(pool), [pool])
Expand All @@ -58,7 +61,7 @@ export const RelayProvider = observer(function RelayProvider({

return (
<RelayContext.Provider
value={{ pool, channelManager, contactManager, profileManager, privMessageManager }}
value={{ pool, channelManager, contactManager, profileManager, privMessageManager, social }}
>
{children}
</RelayContext.Provider>
Expand Down
20 changes: 15 additions & 5 deletions app/components/User.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useContext } from "react"
import React, { memo, useContext, useEffect } from "react"
import { AutoImage, RelayContext, Text } from "app/components"
import { ImageStyle, Pressable, TextStyle, View, ViewStyle } from "react-native"
import { colors, spacing } from "app/theme"
Expand All @@ -18,9 +18,11 @@ export const User = memo(function User({ pubkey, reverse, blinded }: UserProp) {
const queryClient = useQueryClient()
const navigation = useNavigation<any>()

const { pool } = useContext(RelayContext)
const { pool, social } = useContext(RelayContext)
const { userStore } = useStores()

const [reputation, setReputation] = React.useState(null)

const { data: profile } = useQuery({
queryKey: ["user", pubkey],
queryFn: async () => {
Expand All @@ -42,6 +44,14 @@ export const User = memo(function User({ pubkey, reverse, blinded }: UserProp) {
}
}

useEffect(() => {
const getReputation = async () => {
const rep = await social.getReputation(pubkey)
setReputation(rep)
}
getReputation()
}, [])

return (
<>
<Pressable onPress={() => redirect()} style={$user}>
Expand All @@ -57,12 +67,12 @@ export const User = memo(function User({ pubkey, reverse, blinded }: UserProp) {
</Pressable>
<View style={reverse ? $userTitleReverse : $userTitle}>
<Text
text={profile?.username || profile?.display_name || shortenKey(pubkey)}
preset="bold"
size="xs"
style={$userName}
numberOfLines={1}
/>
numberOfLines={1} >
{profile?.username || profile?.display_name || shortenKey(pubkey)} { reputation === null ? <Text size="xxs">(loading)</Text> : isNaN(reputation) ? <Text size="xxs">(no reputation)</Text> : <Text size="xs">{(reputation * 100).toFixed(2)}%</Text> }
</Text>
</View>
</>
)
Expand Down

0 comments on commit 260b777

Please sign in to comment.