@evanp/activitypub-bot 0.25.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/botfactory.js CHANGED
@@ -21,4 +21,8 @@ export default class BotFactory {
21
21
  async onPublic (activity) {
22
22
  ; // no-op
23
23
  }
24
+
25
+ async actorOK (actorId, activity) {
26
+ return false
27
+ }
24
28
  }
@@ -22,6 +22,10 @@ export default class RelayClientBot extends Bot {
22
22
  return 'A bot for subscribing to relays'
23
23
  }
24
24
 
25
+ get key () {
26
+ return `follow:${this.#relay}`
27
+ }
28
+
25
29
  async initialize (context) {
26
30
  super.initialize(context)
27
31
  this._context.logger.info(
@@ -29,11 +33,12 @@ export default class RelayClientBot extends Bot {
29
33
  'Initialising relay client'
30
34
  )
31
35
  if (this.#unsubscribe) {
32
- if (await this._context.hasData(`follow:${this.#relay}`)) {
36
+ if (await this._context.hasData(this.key)) {
33
37
  await this.#unfollowRelay()
34
38
  }
35
39
  } else {
36
- if (!(await this._context.hasData(`follow:${this.#relay}`))) {
40
+ if (!(await this._context.hasData(this.key)) ||
41
+ ((await this._context.getData(this.key)) == null)) {
37
42
  await this.#followRelay()
38
43
  }
39
44
  }
@@ -70,11 +75,11 @@ export default class RelayClientBot extends Bot {
70
75
  { relay: this.#relay, activity: activity.id },
71
76
  'Saving follow for later'
72
77
  )
73
- this._context.setData(`follow:${this.#relay}`, activity.id)
78
+ this._context.setData(this.key, activity.id)
74
79
  }
75
80
 
76
81
  async #unfollowRelay () {
77
- const activityId = await this._context.getData(`follow:${this.#relay}`)
82
+ const activityId = await this._context.getData(this.key)
78
83
  this._context.logger.info(
79
84
  { relay: this.#relay, activity: activityId },
80
85
  'Unfollowing relay'
@@ -92,11 +97,11 @@ export default class RelayClientBot extends Bot {
92
97
  { relay: this.#relay },
93
98
  'Clearing follow data'
94
99
  )
95
- this._context.setData(`follow:${this.#relay}`, null)
100
+ this._context.deleteData(this.key)
96
101
  }
97
102
 
98
103
  async #handleAccept (activity) {
99
- const activityId = await this._context.getData(`follow:${this.#relay}`)
104
+ const activityId = await this._context.getData(this.key)
100
105
  if (activity.object?.first?.id === activityId) {
101
106
  this._context.logger.info(
102
107
  { accept: activity.id, follow: activityId },
@@ -109,7 +114,7 @@ export default class RelayClientBot extends Bot {
109
114
  }
110
115
 
111
116
  async #handleReject (activity) {
112
- const activityId = await this._context.getData(`follow:${this.#relay}`)
117
+ const activityId = await this._context.getData(this.key)
113
118
  if (activity.object?.first?.id === activityId) {
114
119
  this._context.logger.info(
115
120
  { accept: activity.id, follow: activityId },
@@ -15,7 +15,10 @@ async function asyncSome (array, asyncPredicate) {
15
15
  }
16
16
 
17
17
  async function actorOK (subject, activity, bots) {
18
- await asyncSome(Object.values(bots), bot => bot.actorOK(subject, activity))
18
+ return await asyncSome(
19
+ Object.values(bots),
20
+ bot => bot.actorOK(subject, activity)
21
+ )
19
22
  }
20
23
 
21
24
  router.post('/shared/inbox', async (req, res, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",