@evanp/activitypub-bot 0.24.1 → 0.24.2
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/bots/relayclient.js +45 -2
- package/package.json +1 -1
package/lib/bots/relayclient.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import Bot from '../bot.js'
|
|
2
2
|
|
|
3
|
+
const NS = 'https://www.w3.org/ns/activitystreams#'
|
|
4
|
+
const ACCEPT = `${NS}Accept`
|
|
5
|
+
const REJECT = `${NS}Reject`
|
|
6
|
+
|
|
3
7
|
export default class RelayClientBot extends Bot {
|
|
4
8
|
#relay
|
|
5
9
|
#unsubscribe
|
|
@@ -35,6 +39,23 @@ export default class RelayClientBot extends Bot {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
async handleActivity (activity) {
|
|
43
|
+
this._context.logger.debug(
|
|
44
|
+
'handling activity'
|
|
45
|
+
)
|
|
46
|
+
if (activity.type === ACCEPT) {
|
|
47
|
+
return await this.#handleAccept(activity)
|
|
48
|
+
} else if (activity.type === REJECT) {
|
|
49
|
+
return await this.#handleReject(activity)
|
|
50
|
+
} else {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async actorOK (actorId, activity) {
|
|
56
|
+
return (actorId === this.#relay && !this.#unsubscribe)
|
|
57
|
+
}
|
|
58
|
+
|
|
38
59
|
async #followRelay () {
|
|
39
60
|
this._context.logger.info(
|
|
40
61
|
{ relay: this.#relay },
|
|
@@ -74,7 +95,29 @@ export default class RelayClientBot extends Bot {
|
|
|
74
95
|
this._context.setData(`follow:${this.#relay}`, null)
|
|
75
96
|
}
|
|
76
97
|
|
|
77
|
-
async
|
|
78
|
-
|
|
98
|
+
async #handleAccept (activity) {
|
|
99
|
+
const activityId = await this._context.getData(`follow:${this.#relay}`)
|
|
100
|
+
if (activity.object?.first?.id === activityId) {
|
|
101
|
+
this._context.logger.info(
|
|
102
|
+
{ accept: activity.id, follow: activityId },
|
|
103
|
+
'Follow accepted'
|
|
104
|
+
)
|
|
105
|
+
return true
|
|
106
|
+
} else {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async #handleReject (activity) {
|
|
112
|
+
const activityId = await this._context.getData(`follow:${this.#relay}`)
|
|
113
|
+
if (activity.object?.first?.id === activityId) {
|
|
114
|
+
this._context.logger.info(
|
|
115
|
+
{ accept: activity.id, follow: activityId },
|
|
116
|
+
'Follow rejected'
|
|
117
|
+
)
|
|
118
|
+
return true
|
|
119
|
+
} else {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
79
122
|
}
|
|
80
123
|
}
|