Skip to content

Commit

Permalink
Add retrieval of communities from Ariton DWN
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sondreb committed Nov 8, 2024
1 parent f8c5536 commit fb24fdc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
5 changes: 3 additions & 2 deletions app/src/app/communities/communities-datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ export interface Community {
}

export class TableDataSource extends MatTableDataSource<RecordEntry<any>> {
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];
}
}

Expand Down
19 changes: 17 additions & 2 deletions app/src/app/communities/communities.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +66,8 @@ export class CommunitiesComponent {

layout = inject(LayoutService);

admin = inject(AdminService);

images = ['nature', 'sky', 'grass', 'mountains', 'rivers', 'glacier', 'forest'];

// hideSingleSelectionIndicator = signal(false);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/src/app/community/community.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions app/src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 9 additions & 3 deletions app/src/app/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class StorageService {
return entry;
}

async load<T>(configuration: StorageQueryConfiguration, tags: any) {
var { records } = await this.identity.web5.dwn.records.query({
async load<T>(configuration: StorageQueryConfiguration, tags: any, from: string | null = null) {
let query: any = {
message: {
filter: {
tags: tags,
Expand All @@ -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 [];
Expand Down

0 comments on commit fb24fdc

Please sign in to comment.