From fb24fdc2c032209b83711e6dcfe47565edcb6f2d Mon Sep 17 00:00:00 2001 From: SondreB Date: Fri, 8 Nov 2024 16:12:49 +0100 Subject: [PATCH] Add retrieval of communities from Ariton DWN - Approved and published communities are retrieved from the Ariton DWN. - When viewing a community, it will default to Ariton DWN, but can also retrieve from user specific DWN. --- .../app/communities/communities-datasource.ts | 5 +++-- .../app/communities/communities.component.ts | 19 +++++++++++++++++-- app/src/app/community/community.component.ts | 2 +- app/src/app/data.service.ts | 4 ++-- app/src/app/storage.service.ts | 12 +++++++++--- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/app/communities/communities-datasource.ts b/app/src/app/communities/communities-datasource.ts index 2c11501..7aafdd0 100644 --- a/app/src/app/communities/communities-datasource.ts +++ b/app/src/app/communities/communities-datasource.ts @@ -38,14 +38,15 @@ export interface Community { } export class TableDataSource extends MatTableDataSource> { - constructor(private dataService: DataService) { + constructor(private dataService: DataService, private did: string) { super(); this.load(); } async load() { const entries = await this.dataService.load({ type: 'community', status: 'active' }); - this.data = entries; + const entriesExternal = await this.dataService.load({ type: 'community', status: 'active' }, this.did); + this.data = [...entries, ...entriesExternal]; } } diff --git a/app/src/app/communities/communities.component.ts b/app/src/app/communities/communities.component.ts index 8bce895..6aabf61 100644 --- a/app/src/app/communities/communities.component.ts +++ b/app/src/app/communities/communities.component.ts @@ -18,6 +18,7 @@ import { AppService } from '../app.service'; import { LayoutService } from '../layout.service'; import { DataService } from '../data.service'; import { RecordEntry } from '../data'; +import { AdminService } from '../admin.service'; type CardContent = { title: string; @@ -65,6 +66,8 @@ export class CommunitiesComponent { layout = inject(LayoutService); + admin = inject(AdminService); + images = ['nature', 'sky', 'grass', 'mountains', 'rivers', 'glacier', 'forest']; // hideSingleSelectionIndicator = signal(false); @@ -151,7 +154,7 @@ export class CommunitiesComponent { // await this.loadCommunities(); await this.loadDrafts(); - this.dataSource = new TableDataSource(this.data); + this.dataSource = new TableDataSource(this.data, this.admin.getIdentifierForApp('communities')); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; @@ -296,7 +299,19 @@ export class CommunitiesComponent { async loadCommunities() { const entries = await this.data.load({ type: 'community', status: 'active' }); - this.communities.set(entries); + + console.log('Found local communities:', entries); + // this.communities.set(entries); + + // const did = this.admin + + const entriesExternal = await this.data.load( + { type: 'community', status: 'active' }, + this.admin.getIdentifierForApp('communities'), + ); + this.communities.set([...entries, ...entriesExternal]); + + console.log('Found external communities:', entriesExternal); // this.dataSource.data = entries; diff --git a/app/src/app/community/community.component.ts b/app/src/app/community/community.component.ts index 64c6366..dc069ab 100644 --- a/app/src/app/community/community.component.ts +++ b/app/src/app/community/community.component.ts @@ -84,7 +84,7 @@ export class CommunityComponent { const id = params.get('id'); const did = params.get('did'); - this.did = did || ''; + this.did = did || this.admin.getIdentifierForApp('communities'); console.log('Loading community: ', id); console.log('Loading owner: ', did); diff --git a/app/src/app/data.service.ts b/app/src/app/data.service.ts index d10410b..a9feb30 100644 --- a/app/src/app/data.service.ts +++ b/app/src/app/data.service.ts @@ -35,8 +35,8 @@ export class DataService { return this.app.storage.save(this.configuration, data, tags, published); } - async load(tags: any) { - return this.app.storage.load(this.configuration, tags); + async load(tags: any, from: string | null = null) { + return this.app.storage.load(this.configuration, tags, from); } async get(recordId: string, from: string | null = null) { diff --git a/app/src/app/storage.service.ts b/app/src/app/storage.service.ts index 642cd26..ebadef1 100644 --- a/app/src/app/storage.service.ts +++ b/app/src/app/storage.service.ts @@ -46,8 +46,8 @@ export class StorageService { return entry; } - async load(configuration: StorageQueryConfiguration, tags: any) { - var { records } = await this.identity.web5.dwn.records.query({ + async load(configuration: StorageQueryConfiguration, tags: any, from: string | null = null) { + let query: any = { message: { filter: { tags: tags, @@ -56,7 +56,13 @@ export class StorageService { dataFormat: configuration.dataFormat, }, }, - }); + }; + + if (from) { + query.from = from; + } + + var { records } = await this.identity.web5.dwn.records.query(query); if (!records || records.length === 0) { return [];