forked from coracle/flotilla
Switch wording to messaging from inbox
This commit is contained in:
+15
-15
@@ -31,7 +31,7 @@ import {
|
||||
DELETE,
|
||||
REPORT,
|
||||
PROFILE,
|
||||
INBOX_RELAYS,
|
||||
MESSAGING_RELAYS,
|
||||
RELAYS,
|
||||
FOLLOWS,
|
||||
REACTION,
|
||||
@@ -82,8 +82,8 @@ import {
|
||||
profilesByPubkey,
|
||||
tagEvent,
|
||||
tagEventForReaction,
|
||||
userRelaySelections,
|
||||
userInboxRelaySelections,
|
||||
userRelayList,
|
||||
userMessagingRelayList,
|
||||
nip44EncryptToSelf,
|
||||
dropSession,
|
||||
tagEventForComment,
|
||||
@@ -106,8 +106,8 @@ import {
|
||||
userSpaceUrls,
|
||||
userSettingsValues,
|
||||
getSetting,
|
||||
userInboxRelays,
|
||||
userGroupSelections,
|
||||
userMessagingRelays,
|
||||
userGroupList,
|
||||
shouldIgnoreError,
|
||||
} from "@app/core/state"
|
||||
import {loadAlertStatuses} from "@app/core/requests"
|
||||
@@ -164,7 +164,7 @@ export const logout = async () => {
|
||||
|
||||
export const broadcastUserData = async (relays: string[]) => {
|
||||
const authors = [pubkey.get()!]
|
||||
const kinds = [RELAYS, INBOX_RELAYS, FOLLOWS, PROFILE]
|
||||
const kinds = [RELAYS, MESSAGING_RELAYS, FOLLOWS, PROFILE]
|
||||
const events = repository.query([{kinds, authors}])
|
||||
|
||||
for (const event of events) {
|
||||
@@ -177,7 +177,7 @@ export const broadcastUserData = async (relays: string[]) => {
|
||||
// List updates
|
||||
|
||||
export const addSpaceMembership = async (url: string) => {
|
||||
const list = get(userGroupSelections) || makeList({kind: ROOMS})
|
||||
const list = get(userGroupList) || makeList({kind: ROOMS})
|
||||
const event = await addToListPublicly(list, ["r", url]).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
|
||||
@@ -185,7 +185,7 @@ export const addSpaceMembership = async (url: string) => {
|
||||
}
|
||||
|
||||
export const removeSpaceMembership = async (url: string) => {
|
||||
const list = get(userGroupSelections) || makeList({kind: ROOMS})
|
||||
const list = get(userGroupList) || makeList({kind: ROOMS})
|
||||
const pred = (t: string[]) => t[t[0] === "r" ? 1 : 2] === url
|
||||
const event = await removeFromListByPredicate(list, pred).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([url, ...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
@@ -194,7 +194,7 @@ export const removeSpaceMembership = async (url: string) => {
|
||||
}
|
||||
|
||||
export const addRoomMembership = async (url: string, h: string) => {
|
||||
const list = get(userGroupSelections) || makeList({kind: ROOMS})
|
||||
const list = get(userGroupList) || makeList({kind: ROOMS})
|
||||
const newTags = [
|
||||
["r", url],
|
||||
["group", h, url],
|
||||
@@ -206,7 +206,7 @@ export const addRoomMembership = async (url: string, h: string) => {
|
||||
}
|
||||
|
||||
export const removeRoomMembership = async (url: string, h: string) => {
|
||||
const list = get(userGroupSelections) || makeList({kind: ROOMS})
|
||||
const list = get(userGroupList) || makeList({kind: ROOMS})
|
||||
const pred = (t: string[]) => equals(["group", h, url], t.slice(0, 3))
|
||||
const event = await removeFromListByPredicate(list, pred).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([url, ...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
@@ -215,7 +215,7 @@ export const removeRoomMembership = async (url: string, h: string) => {
|
||||
}
|
||||
|
||||
export const setRelayPolicy = (url: string, read: boolean, write: boolean) => {
|
||||
const list = get(userRelaySelections) || makeList({kind: RELAYS})
|
||||
const list = get(userRelayList) || makeList({kind: RELAYS})
|
||||
const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url)
|
||||
|
||||
if (read && write) {
|
||||
@@ -232,10 +232,10 @@ export const setRelayPolicy = (url: string, read: boolean, write: boolean) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const setInboxRelayPolicy = (url: string, enabled: boolean) => {
|
||||
const list = get(userInboxRelaySelections) || makeList({kind: INBOX_RELAYS})
|
||||
export const setMessagingRelayPolicy = (url: string, enabled: boolean) => {
|
||||
const list = get(userMessagingRelayList) || makeList({kind: MESSAGING_RELAYS})
|
||||
|
||||
// Only update inbox policies if they already exist or we're adding them
|
||||
// Only update messaging policies if they already exist or we're adding them
|
||||
if (enabled || getRelaysFromList(list).includes(url)) {
|
||||
const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url)
|
||||
|
||||
@@ -542,7 +542,7 @@ export const createDmAlert = async () => {
|
||||
description: `for direct messages.`,
|
||||
feed: makeIntersectionFeed(
|
||||
feedFromFilters([{kinds: [WRAP], "#p": [pubkey.get()!]}]),
|
||||
makeRelayFeed(...get(userInboxRelays)),
|
||||
makeRelayFeed(...get(userMessagingRelays)),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
+22
-37
@@ -122,8 +122,8 @@ import {
|
||||
appContext,
|
||||
getThunkError,
|
||||
publishThunk,
|
||||
userRelaySelections,
|
||||
userInboxRelaySelections,
|
||||
userRelayList,
|
||||
userMessagingRelayList,
|
||||
deriveRelay,
|
||||
makeUserData,
|
||||
makeUserLoader,
|
||||
@@ -390,18 +390,6 @@ export const relaysPendingTrust = writable<string[]>([])
|
||||
|
||||
export const relaysMostlyRestricted = writable<Record<string, string>>({})
|
||||
|
||||
// Relay selections
|
||||
|
||||
export const userReadRelays = derived(userRelaySelections, $l =>
|
||||
getRelaysFromList($l, RelayMode.Read),
|
||||
)
|
||||
|
||||
export const userWriteRelays = derived(userRelaySelections, $l =>
|
||||
getRelaysFromList($l, RelayMode.Write),
|
||||
)
|
||||
|
||||
export const userInboxRelays = derived(userInboxRelaySelections, $l => getRelaysFromList($l))
|
||||
|
||||
// Alerts
|
||||
|
||||
export type Alert = {
|
||||
@@ -610,29 +598,29 @@ export const displayRoom = (url: string, h: string) =>
|
||||
|
||||
export const roomComparator = (url: string) => (h: string) => displayRoom(url, h).toLowerCase()
|
||||
|
||||
// User space/room selections
|
||||
// User space/room lists
|
||||
|
||||
export const groupSelections = deriveEventsMapped<PublishedList>(repository, {
|
||||
export const groupLists = deriveEventsMapped<PublishedList>(repository, {
|
||||
filters: [{kinds: [ROOMS]}],
|
||||
itemToEvent: item => item.event,
|
||||
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
|
||||
})
|
||||
|
||||
export const {
|
||||
indexStore: groupSelectionsByPubkey,
|
||||
deriveItem: deriveGroupSelections,
|
||||
loadItem: loadGroupSelections,
|
||||
indexStore: groupListsByPubkey,
|
||||
deriveItem: deriveGroupList,
|
||||
loadItem: loadGroupList,
|
||||
} = collection({
|
||||
name: "groupSelections",
|
||||
store: groupSelections,
|
||||
name: "groupLists",
|
||||
store: groupLists,
|
||||
getKey: list => list.event.pubkey,
|
||||
load: makeOutboxLoader(ROOMS),
|
||||
})
|
||||
|
||||
export const groupSelectionsPubkeysByUrl = derived(groupSelections, $groupSelections => {
|
||||
export const groupListsPubkeysByUrl = derived(groupLists, $groupLists => {
|
||||
const result = new Map<string, Set<string>>()
|
||||
|
||||
for (const list of $groupSelections) {
|
||||
for (const list of $groupLists) {
|
||||
const tags = getListTags(list)
|
||||
|
||||
for (const url of getRelayTagValues(tags)) {
|
||||
@@ -651,8 +639,8 @@ export const groupSelectionsPubkeysByUrl = derived(groupSelections, $groupSelect
|
||||
return result
|
||||
})
|
||||
|
||||
export const getSpaceUrlsFromGroupSelections = ($groupSelections: List | undefined) => {
|
||||
const tags = getListTags($groupSelections)
|
||||
export const getSpaceUrlsFromGroupList = ($groupLists: List | undefined) => {
|
||||
const tags = getListTags($groupLists)
|
||||
const urls = getRelayTagValues(tags)
|
||||
|
||||
for (const tag of getGroupTags(tags)) {
|
||||
@@ -666,13 +654,10 @@ export const getSpaceUrlsFromGroupSelections = ($groupSelections: List | undefin
|
||||
return uniq(urls.map(normalizeRelayUrl))
|
||||
}
|
||||
|
||||
export const getSpaceRoomsFromGroupSelections = (
|
||||
url: string,
|
||||
$groupSelections: List | undefined,
|
||||
) => {
|
||||
export const getSpaceRoomsFromGroupList = (url: string, $groupList: List | undefined) => {
|
||||
const rooms: string[] = []
|
||||
|
||||
for (const [_, h, relay] of getGroupTags(getListTags($groupSelections))) {
|
||||
for (const [_, h, relay] of getGroupTags(getListTags($groupList))) {
|
||||
if (url === relay) {
|
||||
rooms.push(h)
|
||||
}
|
||||
@@ -681,20 +666,20 @@ export const getSpaceRoomsFromGroupSelections = (
|
||||
return sortBy(roomComparator(url), rooms)
|
||||
}
|
||||
|
||||
export const userGroupSelections = makeUserData({
|
||||
mapStore: groupSelectionsByPubkey,
|
||||
loadItem: loadGroupSelections,
|
||||
export const userGroupList = makeUserData({
|
||||
mapStore: groupListsByPubkey,
|
||||
loadItem: loadGroupList,
|
||||
})
|
||||
|
||||
export const loadUserGroupSelections = makeUserLoader(loadGroupSelections)
|
||||
export const loadUserGroupList = makeUserLoader(loadGroupList)
|
||||
|
||||
export const userSpaceUrls = derived(userGroupSelections, getSpaceUrlsFromGroupSelections)
|
||||
export const userSpaceUrls = derived(userGroupList, getSpaceUrlsFromGroupLists)
|
||||
|
||||
export const deriveUserRooms = (url: string) =>
|
||||
derived([userGroupSelections, roomsById], ([$userGroupSelections, $roomsById]) => {
|
||||
derived([userGroupList, roomsById], ([$userGroupList, $roomsById]) => {
|
||||
const rooms: string[] = []
|
||||
|
||||
for (const h of getSpaceRoomsFromGroupSelections(url, $userGroupSelections)) {
|
||||
for (const h of getSpaceRoomsFromGroupList(url, $userGroupList)) {
|
||||
if ($roomsById.has(makeRoomId(url, h))) {
|
||||
rooms.push(h)
|
||||
}
|
||||
|
||||
+25
-25
@@ -25,10 +25,10 @@ import {
|
||||
pubkey,
|
||||
loadRelay,
|
||||
userFollows,
|
||||
userRelaySelections,
|
||||
userInboxRelaySelections,
|
||||
loadRelaySelections,
|
||||
loadInboxRelaySelections,
|
||||
userRelayList,
|
||||
userMessagingRelayList,
|
||||
loadRelayList,
|
||||
loadMessagingRelayList,
|
||||
loadBlossomServers,
|
||||
loadFollows,
|
||||
loadMutes,
|
||||
@@ -43,14 +43,14 @@ import {
|
||||
CONTENT_KINDS,
|
||||
INDEXER_RELAYS,
|
||||
loadSettings,
|
||||
loadGroupSelections,
|
||||
loadGroupList,
|
||||
userSpaceUrls,
|
||||
userGroupSelections,
|
||||
userGroupList,
|
||||
bootstrapPubkeys,
|
||||
decodeRelay,
|
||||
getUrlsForEvent,
|
||||
getSpaceUrlsFromGroupSelections,
|
||||
getSpaceRoomsFromGroupSelections,
|
||||
getSpaceUrlsFromGroupList,
|
||||
getSpaceRoomsFromGroupList,
|
||||
makeCommentFilter,
|
||||
} from "@app/core/state"
|
||||
import {loadAlerts, loadAlertStatuses} from "@app/core/requests"
|
||||
@@ -173,20 +173,20 @@ const syncUserRoomMembership = (url: string, h: string) => {
|
||||
const syncUserData = () => {
|
||||
const unsubscribersByKey = new Map<string, Unsubscriber>()
|
||||
|
||||
const unsubscribeGroupSelections = userGroupSelections.subscribe($l => {
|
||||
const unsubscribeGroupList = userGroupList.subscribe($l => {
|
||||
const $pubkey = pubkey.get()
|
||||
|
||||
if ($pubkey) {
|
||||
const keys = new Set<string>()
|
||||
|
||||
for (const url of getSpaceUrlsFromGroupSelections($l)) {
|
||||
for (const url of getSpaceUrlsFromGroupList($l)) {
|
||||
if (!unsubscribersByKey.has(url)) {
|
||||
unsubscribersByKey.set(url, syncUserSpaceMembership(url))
|
||||
}
|
||||
|
||||
keys.add(url)
|
||||
|
||||
for (const h of getSpaceRoomsFromGroupSelections(url, $l)) {
|
||||
for (const h of getSpaceRoomsFromGroupList(url, $l)) {
|
||||
const key = `${url}'${h}`
|
||||
|
||||
if (!unsubscribersByKey.has(key)) {
|
||||
@@ -206,7 +206,7 @@ const syncUserData = () => {
|
||||
}
|
||||
})
|
||||
|
||||
const unsubscribeSelections = userRelaySelections.subscribe($l => {
|
||||
const unsubscribeList = userRelayList.subscribe($l => {
|
||||
const $pubkey = pubkey.get()
|
||||
|
||||
if ($pubkey) {
|
||||
@@ -214,7 +214,7 @@ const syncUserData = () => {
|
||||
loadAlertStatuses($pubkey)
|
||||
loadBlossomServers($pubkey)
|
||||
loadFollows($pubkey)
|
||||
loadGroupSelections($pubkey)
|
||||
loadGroupList($pubkey)
|
||||
loadMutes($pubkey)
|
||||
loadProfile($pubkey)
|
||||
loadSettings($pubkey)
|
||||
@@ -228,8 +228,8 @@ const syncUserData = () => {
|
||||
|
||||
await Promise.all(
|
||||
pubkeys.map(async pk => {
|
||||
await loadRelaySelections(pk)
|
||||
await loadGroupSelections(pk)
|
||||
await loadRelayList(pk)
|
||||
await loadGroupList(pk)
|
||||
await loadProfile(pk)
|
||||
await loadFollows(pk)
|
||||
await loadMutes(pk)
|
||||
@@ -240,14 +240,14 @@ const syncUserData = () => {
|
||||
|
||||
const unsubscribePubkey = pubkey.subscribe($pubkey => {
|
||||
if ($pubkey) {
|
||||
loadRelaySelections($pubkey)
|
||||
loadRelayList($pubkey)
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsubscribersByKey.forEach(call)
|
||||
unsubscribeGroupSelections()
|
||||
unsubscribeSelections()
|
||||
unsubscribeGroupList()
|
||||
unsubscribeList()
|
||||
unsubscribeFollows()
|
||||
unsubscribePubkey()
|
||||
}
|
||||
@@ -386,10 +386,10 @@ const syncDMs = () => {
|
||||
unsubscribeAll()
|
||||
}
|
||||
|
||||
// If we have a pubkey, refresh our user's relay selections then sync our subscriptions
|
||||
// If we have a pubkey, refresh our user's relay list then sync our subscriptions
|
||||
if ($pubkey && $shouldUnwrap) {
|
||||
loadRelaySelections($pubkey)
|
||||
.then(() => loadInboxRelaySelections($pubkey))
|
||||
loadRelayList($pubkey)
|
||||
.then(() => loadMessagingRelayList($pubkey))
|
||||
.then($l => subscribeAll($pubkey, getRelayTagValues(getListTags($l))))
|
||||
}
|
||||
|
||||
@@ -397,20 +397,20 @@ const syncDMs = () => {
|
||||
},
|
||||
)
|
||||
|
||||
// When user inbox relays change, update synchronization
|
||||
const unsubscribeSelections = userInboxRelaySelections.subscribe($userInboxRelaySelections => {
|
||||
// When user messaging relays change, update synchronization
|
||||
const unsubscribeList = userMessagingRelayList.subscribe($userMessagingRelayList => {
|
||||
const $pubkey = pubkey.get()
|
||||
const $shouldUnwrap = shouldUnwrap.get()
|
||||
|
||||
if ($pubkey && $shouldUnwrap) {
|
||||
subscribeAll($pubkey, getRelayTagValues(getListTags($userInboxRelaySelections)))
|
||||
subscribeAll($pubkey, getRelayTagValues(getListTags($userMessagingRelayList)))
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsubscribeAll()
|
||||
unsubscribePubkey()
|
||||
unsubscribeSelections()
|
||||
unsubscribeList()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user