@evanp/activitypub-bot 0.25.1 → 0.26.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.
@@ -72,8 +72,8 @@ export class ActorStorage {
72
72
  page: first
73
73
  }),
74
74
  last: this.#formatter.format({ username, collection: property, page: 1 }),
75
- published: createdAt,
76
- updated: updatedAt
75
+ published: (new Date(createdAt)).toISOString(),
76
+ updated: (new Date(updatedAt)).toISOString()
77
77
  })
78
78
  }
79
79
 
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
- const owners = obj.attributedTo
385
- ? Array.from(obj.attributedTo).map((owner) => owner.id)
386
- : Array.from(obj.actor).map((owner) => owner.id)
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.valueOf()
456
+ return obj.name.get()
451
457
  } else if (obj.summary) {
452
- return obj.summary.valueOf()
458
+ return obj.summary.get()
453
459
  } else if (obj.type) {
454
460
  return `a(n) ${obj.type.first}`
455
461
  } else {
@@ -76,13 +76,15 @@ export class ObjectStorage {
76
76
  let totalItems = 0
77
77
  let first = 1
78
78
  let createdAt = null
79
+ let updatedAt = null
79
80
  const row = await this.#connection.query(
80
- 'SELECT first, createdAt AS createdat FROM collections WHERE id = ? AND property = ?',
81
+ 'SELECT first, createdAt AS createdat, updatedAt AS updatedat FROM collections WHERE id = ? AND property = ?',
81
82
  { replacements: [id, property] }
82
83
  )
83
84
  if (row[0].length > 0) {
84
85
  first = row[0][0].first
85
86
  createdAt = row[0][0].createdat
87
+ updatedAt = row[0][0].updatedat
86
88
  }
87
89
  const count = await this.#connection.query(
88
90
  'SELECT COUNT(*) AS count FROM pages WHERE id = ? AND property = ?',
@@ -95,14 +97,14 @@ export class ObjectStorage {
95
97
  assert.ok(totalItems >= 0, 'totalItems must be greater than or equal to 0')
96
98
  assert.equal(typeof first, 'number', 'first must be a number')
97
99
  assert.ok(first >= 1, 'first must be greater than or equal to 1')
98
- return [totalItems, first, createdAt]
100
+ return [totalItems, first, createdAt, updatedAt]
99
101
  }
100
102
 
101
103
  async getCollection (id, property) {
102
104
  assert.ok(this.#connection, 'ObjectStorage not initialized')
103
105
  assert.ok(id, 'id is required')
104
106
  assert.ok(property, 'property is required')
105
- const [totalItems, first, createdAt] = await this.#collectionInfo(
107
+ const [totalItems, first, createdAt, updatedAt] = await this.#collectionInfo(
106
108
  id,
107
109
  property
108
110
  )
@@ -122,7 +124,8 @@ export class ObjectStorage {
122
124
  totalItems,
123
125
  first: `${id}/${property}/${first}`,
124
126
  last: `${id}/${property}/1`,
125
- published: createdAt,
127
+ published: (new Date(createdAt)).toISOString(),
128
+ updated: (new Date(updatedAt)).toISOString(),
126
129
  [inverse]: id
127
130
  })
128
131
  assert.ok(collection, 'collection is required')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.25.1",
3
+ "version": "0.26.1",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",