@evanp/activitypub-bot 0.25.0 → 0.26.0
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/botcontext.js +12 -6
- package/lib/botfactory.js +4 -0
- package/lib/bots/relayclient.js +12 -7
- package/lib/routes/sharedinbox.js +4 -1
- package/package.json +1 -1
package/lib/botcontext.js
CHANGED
|
@@ -378,12 +378,18 @@ export class BotContext {
|
|
|
378
378
|
return `${username}@${actorUrl.hostname}`
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
async announceObject (obj) {
|
|
381
|
+
async announceObject (obj, actors = null) {
|
|
382
382
|
assert.ok(obj)
|
|
383
383
|
assert.equal(typeof obj, 'object')
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
|
|
385
|
+
const owners = (actors)
|
|
386
|
+
? Array.from(actors).map(actor => actor.id)
|
|
387
|
+
: (obj.attributedTo)
|
|
388
|
+
? Array.from(obj.attributedTo).map((owner) => owner.id)
|
|
389
|
+
: (obj.actor)
|
|
390
|
+
? Array.from(obj.actor).map((owner) => owner.id)
|
|
391
|
+
: []
|
|
392
|
+
|
|
387
393
|
const summary = `${this.#botId} shared "${await this.#nameOf(obj)}"`
|
|
388
394
|
const activity = await this.#doActivity({
|
|
389
395
|
type: 'Announce',
|
|
@@ -447,9 +453,9 @@ export class BotContext {
|
|
|
447
453
|
|
|
448
454
|
#nameOf (obj) {
|
|
449
455
|
if (obj.name) {
|
|
450
|
-
return obj.name.
|
|
456
|
+
return obj.name.get()
|
|
451
457
|
} else if (obj.summary) {
|
|
452
|
-
return obj.summary.
|
|
458
|
+
return obj.summary.get()
|
|
453
459
|
} else if (obj.type) {
|
|
454
460
|
return `a(n) ${obj.type.first}`
|
|
455
461
|
} else {
|
package/lib/botfactory.js
CHANGED
package/lib/bots/relayclient.js
CHANGED
|
@@ -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(
|
|
36
|
+
if (await this._context.hasData(this.key)) {
|
|
33
37
|
await this.#unfollowRelay()
|
|
34
38
|
}
|
|
35
39
|
} else {
|
|
36
|
-
if (!(await this._context.hasData(
|
|
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(
|
|
78
|
+
this._context.setData(this.key, activity.id)
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
async #unfollowRelay () {
|
|
77
|
-
const activityId = await this._context.getData(
|
|
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.
|
|
100
|
+
this._context.deleteData(this.key)
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
async #handleAccept (activity) {
|
|
99
|
-
const activityId = await this._context.getData(
|
|
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(
|
|
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(
|
|
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) => {
|