diff --git a/CHANGELOG.md b/CHANGELOG.md index 1111c19..3e4aa32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## Unreleased + +### Added + +* `ImmersClient.removeAvatar` - new high-level api to remove models from user's Avatar collection +* `Activities.remove` - new low-level api to remove activities + +### Fixed + +* `Activities.add` - fixed target URL logic + ## v2.9.0 (2022-10-05) ### Added diff --git a/source/activities.js b/source/activities.js index 4edae24..1add141 100644 --- a/source/activities.js +++ b/source/activities.js @@ -238,7 +238,7 @@ export class Activities { object: typeof activity === 'string' ? activity : activity.id, target: target.startsWith('https://') ? target - : `https://${this.homeImmer}/collection/${this.actor.preferredUsername}/${target}` + : `https://${getURLPart(this.homeImmer, 'host')})/collection/${this.actor.preferredUsername}/${target}` }) } @@ -385,6 +385,17 @@ export class Activities { }) } + remove (activity, target) { + return this.postActivity({ + type: 'Remove', + actor: this.actor.id, + object: typeof activity === 'string' ? activity : activity.id, + target: target.startsWith('https://') + ? target + : `https://${getURLPart(this.homeImmer, 'host')})/collection/${this.actor.preferredUsername}/${target}` + }) + } + undo (activity) { return this.postActivity({ type: 'Undo', diff --git a/source/client.js b/source/client.js index 7689133..e3b343c 100644 --- a/source/client.js +++ b/source/client.js @@ -397,10 +397,10 @@ export class ImmersClient extends window.EventTarget { /** * Send a message with text content. - * Privacy level determines who receives and can acccess the message. - * Direct: Only those named in `to` receive the message. - * Friends: Direct plus friends list. - * Public: Direct plus Friends plus accessible via URL for sharing. + * privacy level determines who receives and can acccess the message. + * direct: Only those named in `to` receive the message. + * friends: Direct plus friends list. + * public: Direct plus Friends plus accessible via URL for sharing. * @param {string} content - The text/HTML content. Will be sanitized before sending * @param {string} privacy - 'direct', 'friends', or 'public' * @param {string[]} [to] - Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs @@ -573,6 +573,15 @@ export class ImmersClient extends window.EventTarget { return this.activities.updateProfile(profileUpdate) } + /** + * Remove user's avatar from their Avatar Collection. + * @param {(string|Activities.APActivity)} sourceActivity - Activity IRI or Activity from the Avatars Collection to remove + * @returns {Promise} IRI of the remove activity + */ + async removeAvatar (sourceActivity) { + return this.activities.remove(sourceActivity, this.profile.collections.avatars) + } + // Misc utilities /** * Attempt to fetch a cross-domain resource.