mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Support Add/Remove notifications on containers
This commit is contained in:
@@ -324,7 +324,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
|
||||
if (!this.identifierStrategy.isRootContainer(identifier)) {
|
||||
const container = this.identifierStrategy.getParentContainer(identifier);
|
||||
this.addActivityMetadata(changes, container, AS.terms.Update);
|
||||
|
||||
this.addContainerActivity(changes, container, false, identifier);
|
||||
|
||||
// Update modified date of parent
|
||||
await this.updateContainerModifiedDate(container);
|
||||
@@ -424,7 +425,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
|
||||
const changes: ChangeMap = new IdentifierMap();
|
||||
|
||||
// Tranform representation data to quads and add them to the metadata object
|
||||
// Transform representation data to quads and add them to the metadata object
|
||||
const metadata = new RepresentationMetadata(subjectIdentifier);
|
||||
const quads = await arrayifyStream(representation.data);
|
||||
metadata.addQuads(quads);
|
||||
@@ -482,7 +483,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
|
||||
// No changes means the parent container exists and will be updated
|
||||
if (changes.size === 0) {
|
||||
this.addActivityMetadata(changes, parent, AS.terms.Update);
|
||||
this.addContainerActivity(changes, parent, true, identifier);
|
||||
}
|
||||
|
||||
// Parent container is also modified
|
||||
@@ -710,4 +711,19 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
private addActivityMetadata(map: ChangeMap, id: ResourceIdentifier, activity: NamedNode): void {
|
||||
map.set(id, new RepresentationMetadata(id, { [SOLID_AS.activity]: activity }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates activity metadata specifically for Add/Remove events on a container.
|
||||
* @param map - ChangeMap to update.
|
||||
* @param id - Identifier of the container.
|
||||
* @param add - If there is a resource being added (`true`) or removed (`false`).
|
||||
* @param object - The object that is being added/removed.
|
||||
*/
|
||||
private addContainerActivity(map: ChangeMap, id: ResourceIdentifier, add: boolean, object: ResourceIdentifier): void {
|
||||
const metadata = new RepresentationMetadata({
|
||||
[SOLID_AS.activity]: add ? AS.terms.Add : AS.terms.Remove,
|
||||
[AS.object]: namedNode(object.path),
|
||||
});
|
||||
map.set(id, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { Conditions } from './Conditions';
|
||||
import type { ResourceStore, ChangeMap } from './ResourceStore';
|
||||
|
||||
// The ActivityStream terms for which we emit an event
|
||||
const knownActivities = [ AS.terms.Create, AS.terms.Delete, AS.terms.Update ];
|
||||
const knownActivities = [ AS.terms.Add, AS.terms.Create, AS.terms.Delete, AS.terms.Remove, AS.terms.Update ];
|
||||
|
||||
/**
|
||||
* Store that notifies listeners of changes to its source
|
||||
@@ -57,8 +57,8 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
|
||||
for (const [ identifier, metadata ] of changes) {
|
||||
const activity = metadata.get(SOLID_AS.terms.activity);
|
||||
if (this.isKnownActivity(activity)) {
|
||||
this.emit('changed', identifier, activity);
|
||||
this.emit(activity.value, identifier);
|
||||
this.emit('changed', identifier, activity, metadata);
|
||||
this.emit(activity.value, identifier, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user