mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 16:31:04 +00:00
Replace agent/social
This commit is contained in:
parent
0a63300151
commit
2656db8992
@ -1,25 +0,0 @@
|
||||
import {uniq, identity, without} from "ramda"
|
||||
import {Tags} from "src/util/nostr"
|
||||
import {getPersonWithFallback} from "src/agent/db"
|
||||
import user from "src/agent/user"
|
||||
|
||||
const {VITE_DEFAULT_FOLLOWS} = import.meta.env
|
||||
|
||||
export const defaultFollows = (VITE_DEFAULT_FOLLOWS || "").split(",").filter(identity)
|
||||
|
||||
export const getFollows = pubkey =>
|
||||
Tags.wrap(getPersonWithFallback(pubkey).petnames).type("p").values().all()
|
||||
|
||||
export const getNetwork = pubkey => {
|
||||
const follows = getFollows(pubkey)
|
||||
|
||||
return uniq(without(follows, follows.flatMap(getFollows)))
|
||||
}
|
||||
|
||||
export const getUserFollows = (): Array<string> => Tags.wrap(user.getPetnames()).values().all()
|
||||
|
||||
export const getUserNetwork = () => {
|
||||
const follows = getUserFollows()
|
||||
|
||||
return uniq(without(follows, follows.flatMap(getFollows)))
|
||||
}
|
@ -13,8 +13,8 @@
|
||||
import SelectButton from "src/partials/SelectButton.svelte"
|
||||
import MultiSelect from "src/partials/MultiSelect.svelte"
|
||||
import PersonBadge from "src/app/shared/PersonBadge.svelte"
|
||||
import {social} from "src/system"
|
||||
import {searchTopics, searchPeople, getPersonWithFallback} from "src/agent/db"
|
||||
import {getUserFollows} from "src/agent/social"
|
||||
|
||||
export let filter
|
||||
export let onChange
|
||||
@ -138,7 +138,7 @@
|
||||
|
||||
$: {
|
||||
scopeOptions =
|
||||
getUserFollows().length > 0
|
||||
social.getUserFollows().length > 0
|
||||
? ["follows", "network", "global", "custom"]
|
||||
: ["network", "global", "custom"]
|
||||
}
|
||||
|
@ -15,11 +15,10 @@ import {findReplyId} from "src/util/nostr"
|
||||
import {modal, toast} from "src/partials/state"
|
||||
import {notifications, watch, userEvents, contacts, rooms} from "src/agent/db"
|
||||
import {enableZaps} from "src/agent/settings"
|
||||
import {keys} from "src/system"
|
||||
import {DEFAULT_FOLLOWS, keys, social} from "src/system"
|
||||
import network from "src/agent/network"
|
||||
import pool from "src/agent/pool"
|
||||
import {getUserReadRelays, getUserRelays} from "src/agent/relays"
|
||||
import {getUserFollows, getUserNetwork, defaultFollows} from "src/agent/social"
|
||||
import user from "src/agent/user"
|
||||
|
||||
// Routing
|
||||
@ -221,7 +220,7 @@ export const loadAppData = async pubkey => {
|
||||
|
||||
// Make sure the user and their network is loaded
|
||||
await network.loadPeople([pubkey], {force: true, kinds: userKinds})
|
||||
await network.loadPeople(getUserFollows())
|
||||
await network.loadPeople(social.getUserFollows())
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,14 +293,15 @@ export const publishWithToast = (relays, thunk) =>
|
||||
// Feeds
|
||||
|
||||
export const compileFilter = (filter: DynamicFilter): Filter => {
|
||||
const getAuthors = pubkeys => shuffle(pubkeys.length > 0 ? pubkeys : defaultFollows).slice(0, 256)
|
||||
const getAuthors = pubkeys =>
|
||||
shuffle(pubkeys.length > 0 ? pubkeys : DEFAULT_FOLLOWS).slice(0, 256)
|
||||
|
||||
if (filter.authors === "global") {
|
||||
filter = omit(["authors"], filter)
|
||||
} else if (filter.authors === "follows") {
|
||||
filter = {...filter, authors: getAuthors(getUserFollows())}
|
||||
filter = {...filter, authors: getAuthors(social.getUserFollows())}
|
||||
} else if (filter.authors === "network") {
|
||||
filter = {...filter, authors: getAuthors(getUserNetwork())}
|
||||
filter = {...filter, authors: getAuthors(social.getUserNetwork())}
|
||||
}
|
||||
|
||||
return filter
|
||||
|
@ -8,9 +8,8 @@
|
||||
import Content from "src/partials/Content.svelte"
|
||||
import Popover from "src/partials/Popover.svelte"
|
||||
import Feed from "src/app/shared/Feed.svelte"
|
||||
import {keys} from "src/system"
|
||||
import {keys, social} from "src/system"
|
||||
import user from "src/agent/user"
|
||||
import {getUserFollows} from "src/agent/social"
|
||||
|
||||
const {canSign} = keys
|
||||
const {lists} = user
|
||||
@ -19,7 +18,7 @@
|
||||
let key = Math.random()
|
||||
let filter = {
|
||||
kinds: noteKinds,
|
||||
authors: getUserFollows().length > 0 ? "follows" : "network",
|
||||
authors: social.getUserFollows().length > 0 ? "follows" : "network",
|
||||
} as DynamicFilter
|
||||
|
||||
$: listsByName = indexBy(l => Tags.from(l).getMeta("d"), $lists)
|
||||
|
@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import {uniq} from "ramda"
|
||||
import {onMount} from "svelte"
|
||||
import {generatePrivateKey} from "nostr-tools"
|
||||
import {fly} from "src/util/transition"
|
||||
@ -12,7 +11,7 @@
|
||||
import OnboardingRelays from "src/app/views/OnboardingRelays.svelte"
|
||||
import OnboardingFollows from "src/app/views/OnboardingFollows.svelte"
|
||||
import OnboardingNote from "src/app/views/OnboardingNote.svelte"
|
||||
import {getFollows, defaultFollows} from "src/agent/social"
|
||||
import {DEFAULT_FOLLOWS, social} from "src/system"
|
||||
import {getPubkeyWriteRelays, sampleRelays} from "src/agent/relays"
|
||||
import {getPersonWithFallback} from "src/agent/db"
|
||||
import network from "src/agent/network"
|
||||
@ -65,11 +64,11 @@
|
||||
// Prime our people cache for hardcoded follows and a sample of people they follow
|
||||
onMount(async () => {
|
||||
const relays = sampleRelays(user.getRelays())
|
||||
const follows = user.getPetnamePubkeys().concat(defaultFollows)
|
||||
const follows = user.getPetnamePubkeys().concat(DEFAULT_FOLLOWS)
|
||||
|
||||
await network.loadPeople(follows, {relays})
|
||||
|
||||
const others = shuffle(uniq(follows.flatMap(getFollows))).slice(0, 256)
|
||||
const others = shuffle(social.getNetwork(follows)).slice(0, 256)
|
||||
|
||||
await network.loadPeople(others, {relays})
|
||||
})
|
||||
|
@ -6,8 +6,8 @@
|
||||
import Heading from "src/partials/Heading.svelte"
|
||||
import Content from "src/partials/Content.svelte"
|
||||
import PersonInfo from "src/app/shared/PersonInfo.svelte"
|
||||
import {DEFAULT_FOLLOWS} from "src/system"
|
||||
import {getPersonWithFallback, searchPeople} from "src/agent/db"
|
||||
import {defaultFollows} from "src/agent/social"
|
||||
import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays"
|
||||
import {modal} from "src/partials/state"
|
||||
import user from "src/agent/user"
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
if ($petnamePubkeys.length === 0) {
|
||||
user.updatePetnames(() =>
|
||||
defaultFollows.map(pubkey => {
|
||||
DEFAULT_FOLLOWS.map(pubkey => {
|
||||
const [{url}] = sampleRelays(getPubkeyWriteRelays(pubkey))
|
||||
const name = displayPerson(getPersonWithFallback(pubkey))
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from "src/system/env"
|
||||
import keys from "src/system/keys"
|
||||
import initSync from "src/system/sync"
|
||||
import initSocial from "src/system/social"
|
||||
|
@ -1,8 +1,9 @@
|
||||
import {sortBy, reject, prop} from "ramda"
|
||||
import {get} from "svelte/store"
|
||||
import {now, gettable} from "src/util/misc"
|
||||
import {ensurePlural} from "hurdak/lib/hurdak"
|
||||
import {now} from "src/util/misc"
|
||||
import {Tags} from "src/util/nostr"
|
||||
import {Table, watch} from "src/agent/db"
|
||||
import {Table} from "src/agent/db"
|
||||
|
||||
export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
// Don't delete the user's own info or those of direct follows
|
||||
@ -18,7 +19,7 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
}
|
||||
}
|
||||
|
||||
const graph = new Table("system.social/graph", "pubkey", {max: 5000, sort: sortByGraph})
|
||||
const graph = new Table("social/graph", "pubkey", {max: 5000, sort: sortByGraph})
|
||||
|
||||
sync.addHandler(3, e => {
|
||||
const entry = graph.get(e.pubkey)
|
||||
@ -38,10 +39,10 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
|
||||
const getPetnamePubkeys = pubkey => getPetnames(pubkey).map(t => t[1])
|
||||
|
||||
const getFollows = pubkeys => {
|
||||
const getFollowsSet = pubkeys => {
|
||||
const follows = new Set()
|
||||
|
||||
for (const pubkey of pubkeys) {
|
||||
for (const pubkey of ensurePlural(pubkeys)) {
|
||||
for (const follow of getPetnamePubkeys(pubkey)) {
|
||||
follows.add(follow)
|
||||
}
|
||||
@ -50,8 +51,10 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
return follows
|
||||
}
|
||||
|
||||
const getNetwork = (pubkeys, includeFollows = false) => {
|
||||
const follows = getFollows(pubkeys)
|
||||
const getFollows = pubkeys => Array.from(getFollowsSet(pubkeys))
|
||||
|
||||
const getNetworkSet = (pubkeys, includeFollows = false) => {
|
||||
const follows = getFollowsSet(pubkeys)
|
||||
const network = includeFollows ? follows : new Set()
|
||||
|
||||
for (const pubkey of getFollows(follows)) {
|
||||
@ -63,13 +66,15 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
return network
|
||||
}
|
||||
|
||||
const isFollowing = (a, b) => getFollows(a).has(b)
|
||||
const getNetwork = pubkeys => Array.from(getNetworkSet(pubkeys))
|
||||
|
||||
const isFollowing = (a, b) => getFollowsSet(a).has(b)
|
||||
|
||||
const getUserKey = () => keys.getPubkey() || "anonymous"
|
||||
const userPetnames = gettable(watch(graph, () => getPetnames(getUserKey())))
|
||||
const userPetnamePubkeys = gettable(watch(graph, () => getPetnamePubkeys(getUserKey())))
|
||||
const userFollows = gettable(watch(graph, () => getFollows(getUserKey())))
|
||||
const userNetwork = gettable(watch(graph, () => getNetwork(getUserKey())))
|
||||
const getUserPetnames = () => getPetnames(getUserKey())
|
||||
const getUserPetnamePubkeys = () => getPetnamePubkeys(getUserKey())
|
||||
const getUserFollows = () => getFollows(getUserKey())
|
||||
const getUserNetwork = () => getNetwork(getUserKey())
|
||||
const isUserFollowing = pubkey => isFollowing(getUserKey(), pubkey)
|
||||
|
||||
const updatePetnames = async $petnames => {
|
||||
@ -86,13 +91,12 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
|
||||
const follow = (pubkey, url, name) =>
|
||||
updatePetnames(
|
||||
userPetnames
|
||||
.get()
|
||||
getUserPetnames()
|
||||
.filter(t => t[1] !== pubkey)
|
||||
.concat([["p", pubkey, url, name || ""]])
|
||||
)
|
||||
|
||||
const unfollow = pubkey => updatePetnames(reject(t => t[1] === pubkey, userPetnames.get()))
|
||||
const unfollow = pubkey => updatePetnames(reject(t => t[1] === pubkey, getUserPetnames()))
|
||||
|
||||
return {
|
||||
graph,
|
||||
@ -101,10 +105,10 @@ export default ({keys, sync, cmd, getUserWriteRelays}) => {
|
||||
getFollows,
|
||||
getNetwork,
|
||||
isFollowing,
|
||||
userPetnames,
|
||||
userPetnamePubkeys,
|
||||
userFollows,
|
||||
userNetwork,
|
||||
getUserPetnames,
|
||||
getUserPetnamePubkeys,
|
||||
getUserFollows,
|
||||
getUserNetwork,
|
||||
isUserFollowing,
|
||||
follow,
|
||||
unfollow,
|
||||
|
Loading…
Reference in New Issue
Block a user