Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added resolver for perspective from url method #44

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/core/PerspectivesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Perspective from './Perspective'
export default class PerspectivesController {
#perspectiveHandles: Map<string, PerspectiveHandle>
#perspectiveInstances: Map<string, Perspective>
#urlPerspectiveMap: Map<string, string>
#rootConfigPath
pubsub
#context
Expand All @@ -20,6 +21,7 @@ export default class PerspectivesController {

this.#perspectiveHandles = new Map<string, PerspectiveHandle>()
this.#perspectiveInstances = new Map<string, Perspective>()
this.#urlPerspectiveMap = new Map<string, string>()

const FILENAME = 'perspectives.json'
const FILEPATH = path.join(rootConfigPath, FILENAME)
Expand All @@ -32,6 +34,9 @@ export default class PerspectivesController {
console.debug(`PerspectivesController: Found existing perspective "${k}":`, perspective)
this.#perspectiveInstances.set(k, new Perspective(perspective, this.#context, perspective.neighbourhood as Neighbourhood))
this.#perspectiveHandles.set(k, perspective)
if (perspective.sharedUrl && perspective.sharedUrl.includes('neighbourhood://')) {
this.#urlPerspectiveMap.set(perspective.sharedUrl, k);
}
})
}

Expand Down Expand Up @@ -94,6 +99,12 @@ export default class PerspectivesController {
}
}

fromUrl(url: string): Perspective {
const uuid = this.#urlPerspectiveMap.get(url);

return this.perspective(uuid || "");
}

async perspectiveSnapshot(uuid: string): Promise<Ad4mPerspective> {
let perspective = this.#perspectiveInstances.get(uuid)
if (!perspective) {
Expand All @@ -111,6 +122,9 @@ export default class PerspectivesController {
} as PerspectiveHandle;
this.#perspectiveHandles.set(perspective.uuid, perspective)
this.#perspectiveInstances.set(perspective.uuid, new Perspective(perspective, this.#context, neighbourhood))
if (sharedUrl) {
this.#urlPerspectiveMap.set(sharedUrl, perspective.uuid)
}
this.save()
this.pubsub.publish(PubSub.PERSPECTIVE_ADDED_TOPIC, { perspective })
return perspective
Expand All @@ -119,10 +133,15 @@ export default class PerspectivesController {
replace(perspectiveHandle: PerspectiveHandle, neighbourhood: Neighbourhood) {
this.#perspectiveHandles.set(perspectiveHandle.uuid, perspectiveHandle);
this.#perspectiveInstances.set(perspectiveHandle.uuid, new Perspective(perspectiveHandle, this.#context, neighbourhood));
if (perspectiveHandle.sharedUrl) {
this.#urlPerspectiveMap.set(perspectiveHandle.sharedUrl, perspectiveHandle.uuid)
}
this.save()
}

remove(uuid: string) {
const perspective = this.perspective(uuid);
this.#urlPerspectiveMap.delete(perspective.sharedUrl!);
this.#perspectiveHandles.delete(uuid)
this.#perspectiveInstances.delete(uuid)
this.save()
Expand Down
1 change: 1 addition & 0 deletions src/core/PerspectivismCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default class PerspectivismCore {
params.ipfsSwarmPort,
params.ipfsRepoPath
), this.#holochain.run()]);
// @ts-ignore
this.#IPFS = ipfs;
//this.connectToHardwiredPerspect3vismAgent()
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/graphQL-interface/GraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ function createResolvers(core: PerspectivismCore) {
return core.perspectivesController.perspectiveID(args.uuid)
},
//@ts-ignore
fromUrl: (parent, args, context, info) => {
return core.perspectivesController.fromUrl(args.url)
},
//@ts-ignore
perspectiveQueryLinks: async (parent, args, context, info) => {
const { uuid, query } = args
const perspective = core.perspectivesController.perspective(uuid)
Expand Down