feat: support for multi char
This commit is contained in:
parent
c813c08aa1
commit
54f76d2a64
|
|
@ -100,25 +100,17 @@ export const getUserSites = async (params: GetUserSitesParams) => {
|
|||
}
|
||||
|
||||
export type GetAccountSitesParams = {
|
||||
account: GeneralAccount
|
||||
handle: string
|
||||
unidata?: Unidata
|
||||
}
|
||||
|
||||
export const getAccountSites = (
|
||||
params: GetAccountSitesParams,
|
||||
): Promise<Profile[] | null> => {
|
||||
switch (params.account.type) {
|
||||
case "email":
|
||||
return getUserSites({
|
||||
handle: params.account.character.handle,
|
||||
unidata: params.unidata,
|
||||
})
|
||||
case "wallet":
|
||||
return getUserSites({
|
||||
address: params.account.address,
|
||||
unidata: params.unidata,
|
||||
})
|
||||
}
|
||||
return getUserSites({
|
||||
handle: params.handle,
|
||||
unidata: params.unidata,
|
||||
})
|
||||
}
|
||||
|
||||
export const getSite = async (input: string, customUnidata?: Unidata) => {
|
||||
|
|
@ -210,27 +202,15 @@ export const getSites = async (input: string[]) => {
|
|||
|
||||
export const getSubscription = async (
|
||||
siteId: string,
|
||||
account: GeneralAccount,
|
||||
handle: string,
|
||||
customUnidata?: Unidata,
|
||||
) => {
|
||||
const links = await (() => {
|
||||
switch (account.type) {
|
||||
case "email":
|
||||
return (customUnidata || unidata).links.get({
|
||||
source: "Crossbell Link",
|
||||
identity: account.character.handle,
|
||||
platform: "Crossbell",
|
||||
filter: { to: siteId },
|
||||
})
|
||||
case "wallet":
|
||||
return (customUnidata || unidata).links.get({
|
||||
source: "Crossbell Link",
|
||||
identity: account.address,
|
||||
platform: "Ethereum",
|
||||
filter: { to: siteId },
|
||||
})
|
||||
}
|
||||
})()
|
||||
const links = await (customUnidata || unidata).links.get({
|
||||
source: "Crossbell Link",
|
||||
identity: handle,
|
||||
platform: "Crossbell",
|
||||
filter: { to: siteId },
|
||||
})
|
||||
|
||||
return !!links?.list?.length
|
||||
}
|
||||
|
|
@ -387,27 +367,6 @@ export async function createSite(
|
|||
)
|
||||
}
|
||||
|
||||
export async function subscribeToSite(
|
||||
input: {
|
||||
userId: string
|
||||
siteId: string
|
||||
},
|
||||
customUnidata?: Unidata,
|
||||
) {
|
||||
return (customUnidata || unidata).links.set(
|
||||
{
|
||||
source: "Crossbell Link",
|
||||
identity: input.userId,
|
||||
platform: "Ethereum",
|
||||
action: "add",
|
||||
},
|
||||
{
|
||||
to: input.siteId,
|
||||
type: "follow",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export async function subscribeToSites(
|
||||
input: {
|
||||
user: Profile
|
||||
|
|
@ -427,27 +386,6 @@ export async function subscribeToSites(
|
|||
}
|
||||
}
|
||||
|
||||
export async function unsubscribeFromSite(
|
||||
input: {
|
||||
userId: string
|
||||
siteId: string
|
||||
},
|
||||
customUnidata?: Unidata,
|
||||
) {
|
||||
return (customUnidata || unidata).links.set(
|
||||
{
|
||||
source: "Crossbell Link",
|
||||
identity: input.userId,
|
||||
platform: "Ethereum",
|
||||
action: "remove",
|
||||
},
|
||||
{
|
||||
to: input.siteId,
|
||||
type: "follow",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const xLogOperatorPermissions: CharacterOperatorPermission[] = [
|
||||
CharacterOperatorPermission.SET_NOTE_URI,
|
||||
CharacterOperatorPermission.DELETE_NOTE,
|
||||
|
|
|
|||
|
|
@ -13,14 +13,15 @@ import { useUnidata } from "./unidata"
|
|||
export const useAccountSites = () => {
|
||||
const unidata = useUnidata()
|
||||
const account = useAccountState((s) => s.computed.account)
|
||||
const address = account?.type === "email" ? account.email : account?.address
|
||||
const handle =
|
||||
account?.type === "email" ? account.character?.handle : account?.handle
|
||||
|
||||
return useQuery(["getUserSites", address], async () => {
|
||||
if (!account) {
|
||||
return useQuery(["getUserSites", handle], async () => {
|
||||
if (!account || !handle) {
|
||||
return []
|
||||
}
|
||||
|
||||
return siteModel.getAccountSites({ account, unidata })
|
||||
return siteModel.getAccountSites({ handle, unidata })
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -45,18 +46,18 @@ export const useGetSites = (input: string[]) => {
|
|||
|
||||
export const useGetSubscription = (siteId: string | undefined) => {
|
||||
const account = useAccountState((s) => s.computed.account)
|
||||
const handle =
|
||||
account?.type === "email" ? account.character?.handle : account?.handle
|
||||
const unidata = useUnidata()
|
||||
|
||||
return useQuery(
|
||||
["getSubscription", siteId, account?.characterId],
|
||||
async () => {
|
||||
if (!account || !siteId) {
|
||||
return false
|
||||
}
|
||||
console.log(["getSubscription", siteId, handle])
|
||||
return useQuery(["getSubscription", siteId, handle], async () => {
|
||||
if (!handle || !siteId) {
|
||||
return false
|
||||
}
|
||||
|
||||
return siteModel.getSubscription(siteId, account, unidata)
|
||||
},
|
||||
)
|
||||
return siteModel.getSubscription(siteId, handle, unidata)
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetSiteSubscriptions = (data: { siteId: string }) => {
|
||||
|
|
@ -135,7 +136,9 @@ export function useSubscribeToSite() {
|
|||
queryClient.invalidateQueries([
|
||||
"getSubscription",
|
||||
variables.siteId,
|
||||
account?.characterId,
|
||||
account?.type === "email"
|
||||
? account?.character?.handle
|
||||
: account?.handle,
|
||||
]),
|
||||
])
|
||||
},
|
||||
|
|
@ -187,7 +190,9 @@ export function useUnsubscribeFromSite() {
|
|||
queryClient.invalidateQueries([
|
||||
"getSubscription",
|
||||
variables.siteId,
|
||||
account?.characterId,
|
||||
account?.type === "email"
|
||||
? account?.character?.handle
|
||||
: account?.handle,
|
||||
]),
|
||||
])
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue