1 | const guid = require('guid');
|
2 |
|
3 | let activityClass = class JSONActivityStreamish {
|
4 | constructor(args) {
|
5 | this._id = guid.raw();
|
6 | this._context = 'http://www.w3.org/ns/activitystreams#';
|
7 | this._published = new Date().toISOString();
|
8 | this._actor = args && 'actor' in args ? args.actor : {};
|
9 | this._target = args && 'target' in args ? args.target : {};
|
10 | this._type = args && 'type' in args ? args.type : '';
|
11 | }
|
12 |
|
13 |
|
14 | actor(newActor) {
|
15 | if (newActor) {
|
16 | this._actor = newActor;
|
17 | return;
|
18 | }
|
19 | return this._actor;
|
20 | }
|
21 |
|
22 | target(newTarget) {
|
23 | if (newTarget) {
|
24 | return this._target = newTarget;
|
25 | return;
|
26 | }
|
27 | return this._target;
|
28 | }
|
29 |
|
30 | type(newType) {
|
31 | if (newType) {
|
32 | return this._type = newType;
|
33 | }
|
34 | return this._type;
|
35 | }
|
36 |
|
37 | toJSON() {
|
38 | let object = {
|
39 | '@context': this._context,
|
40 | id: this._id,
|
41 | actor: this._actor,
|
42 | target: this._target,
|
43 | type: this._type,
|
44 | published: this._published
|
45 | }
|
46 | return JSON.stringify(object);
|
47 | }
|
48 | }
|
49 |
|
50 | module.exports = activityClass;
|