@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 +4 -0
- package/lib/bots/relayclient.js +12 -7
- package/lib/routes/sharedinbox.js +4 -1
- package/package.json +1 -1
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) => {
|