Skip to content

Commit

Permalink
Merge pull request #26 from immers-space/remove-activity
Browse files Browse the repository at this point in the history
add Remove activity
  • Loading branch information
wmurphyrd authored Oct 14, 2022
2 parents 1eaa877 + 7832176 commit dba68c5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 12 additions & 1 deletion source/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
})
}

Expand Down Expand Up @@ -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',
Expand Down
17 changes: 13 additions & 4 deletions source/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string>} 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.
Expand Down

0 comments on commit dba68c5

Please sign in to comment.