@sprucelabs/spruce-feed-view-controllers 1.0.9 → 1.1.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.
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
1
|
+
import { FeedItem, SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
2
|
+
import { SubscribeOptions } from './respondingToMercuryDidUpdate/MessageDistributor';
|
|
2
3
|
export type FeedPredicate = SpruceSchemas.Mercury.v2020_12_25.FeedPredicate;
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type SubscribeTargetAndPayload = SpruceSchemas.Feed.v2023_03_04.SubscribeEmitTargetAndPayload;
|
|
5
|
+
declare module '@sprucelabs/spruce-skill-utils/build/types/skill.types' {
|
|
6
|
+
interface SkillContext {
|
|
7
|
+
handleMercuryDidUpdate: (item: FeedItem) => Promise<void>;
|
|
8
|
+
handleSubscribe: (options: SubscribeOptions) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractViewController, Authenticator, Card, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { FeedItem } from '@sprucelabs/spruce-core-schemas';
|
|
3
|
+
import { FeedPredicate } from '../feed.types';
|
|
3
4
|
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
4
5
|
static id: string;
|
|
5
6
|
private isLoaded;
|
|
@@ -9,19 +10,20 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
10
|
private sentMessageCount;
|
|
10
11
|
private pendingAddedMessages;
|
|
11
12
|
protected feedVc: FeedViewController;
|
|
12
|
-
|
|
13
|
+
protected recipientId?: string;
|
|
13
14
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
14
15
|
private FeedVc;
|
|
15
16
|
private CardVc;
|
|
16
17
|
private handleSubmitForm;
|
|
17
18
|
protected handleDidUpdateFeedItem(item: FeedItem): void;
|
|
18
|
-
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.
|
|
19
|
+
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.Feed.v2023_03_04.DidUpdateFeedEmitTargetAndPayload): Promise<void>;
|
|
19
20
|
private sendMessage;
|
|
20
21
|
private removeItem;
|
|
21
22
|
private pushItem;
|
|
22
23
|
private addSentMessage;
|
|
23
24
|
getIsLoaded(): boolean;
|
|
24
25
|
load(options: FeedCardLoadOptions): Promise<void>;
|
|
26
|
+
private subscribe;
|
|
25
27
|
destroy(): Promise<void>;
|
|
26
28
|
private refresh;
|
|
27
29
|
private handleTryAgain;
|
|
@@ -47,22 +47,24 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
handleDidUpdateFeedItem(item) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
else {
|
|
55
|
-
this.pendingAddedMessages.splice(idx, 1);
|
|
50
|
+
var _a;
|
|
51
|
+
const trackingId = (_a = item.context) === null || _a === void 0 ? void 0 : _a.trackingId;
|
|
52
|
+
if (trackingId) {
|
|
53
|
+
item.id = trackingId;
|
|
56
54
|
}
|
|
55
|
+
this.feedVc.addItem(item);
|
|
57
56
|
}
|
|
58
57
|
handleDidUpdateFeed({ payload, }) {
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const { item } = payload;
|
|
60
|
+
this.handleDidUpdateFeedItem(item);
|
|
61
|
+
});
|
|
61
62
|
}
|
|
62
63
|
sendMessage(message) {
|
|
63
64
|
var _a;
|
|
64
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const
|
|
66
|
+
const id = `${new Date().getTime()}-${this.sentMessageCount++}`;
|
|
67
|
+
const added = this.addSentMessage(message, id);
|
|
66
68
|
const client = yield this.connectToApi();
|
|
67
69
|
try {
|
|
68
70
|
yield client.emitAndFlattenResponses('send-message::v2020_12_25', {
|
|
@@ -71,8 +73,12 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
71
73
|
},
|
|
72
74
|
payload: {
|
|
73
75
|
message: {
|
|
76
|
+
trackingId: id,
|
|
74
77
|
body: message,
|
|
75
78
|
classification: 'transactional',
|
|
79
|
+
context: {
|
|
80
|
+
trackingId: id,
|
|
81
|
+
},
|
|
76
82
|
},
|
|
77
83
|
},
|
|
78
84
|
});
|
|
@@ -96,17 +102,23 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
96
102
|
pushItem(item) {
|
|
97
103
|
this.feedVc.addItem(item);
|
|
98
104
|
}
|
|
99
|
-
addSentMessage(message) {
|
|
105
|
+
addSentMessage(message, id) {
|
|
100
106
|
const person = this.auth.getPerson();
|
|
101
107
|
const item = {
|
|
102
|
-
id
|
|
103
|
-
isMe: true,
|
|
108
|
+
id,
|
|
104
109
|
message: message,
|
|
105
|
-
fromCasualName: person.casualName,
|
|
106
110
|
dateCreated: this.dates.date(),
|
|
107
|
-
avatar: person.avatar,
|
|
108
111
|
source: {
|
|
109
112
|
personId: person.id,
|
|
113
|
+
avatar: person.avatar,
|
|
114
|
+
isMe: true,
|
|
115
|
+
isSprucebot: false,
|
|
116
|
+
casualName: person.casualName,
|
|
117
|
+
},
|
|
118
|
+
target: {
|
|
119
|
+
casualName: 'aou',
|
|
120
|
+
isMe: false,
|
|
121
|
+
isSprucebot: false,
|
|
110
122
|
},
|
|
111
123
|
};
|
|
112
124
|
this.pushItem(item);
|
|
@@ -122,10 +134,27 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
122
134
|
this.predicates = predicates;
|
|
123
135
|
this.auth = authenticator;
|
|
124
136
|
const client = yield this.connectToApi();
|
|
125
|
-
yield client.on('did-update-feed::
|
|
137
|
+
yield client.on('feed.did-update-feed::v2023_03_04', this.handleDidUpdateFeed);
|
|
138
|
+
if (recipientId) {
|
|
139
|
+
yield Promise.all([
|
|
140
|
+
this.subscribe(client, {
|
|
141
|
+
toPersonId: recipientId,
|
|
142
|
+
}),
|
|
143
|
+
this.subscribe(client, {
|
|
144
|
+
fromPersonId: recipientId,
|
|
145
|
+
}),
|
|
146
|
+
]);
|
|
147
|
+
}
|
|
126
148
|
yield this.refresh();
|
|
127
149
|
});
|
|
128
150
|
}
|
|
151
|
+
subscribe(client, target) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
yield client.emitAndFlattenResponses('feed.subscribe::v2023_03_04', {
|
|
154
|
+
target,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
129
158
|
destroy() {
|
|
130
159
|
const _super = Object.create(null, {
|
|
131
160
|
destroy: { get: () => super.destroy }
|
|
@@ -133,7 +162,7 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
133
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
163
|
yield _super.destroy.call(this);
|
|
135
164
|
const client = yield this.connectToApi();
|
|
136
|
-
yield client.off('did-update-feed::
|
|
165
|
+
yield client.off('feed.did-update-feed::v2023_03_04', this.handleDidUpdateFeed);
|
|
137
166
|
});
|
|
138
167
|
}
|
|
139
168
|
refresh() {
|
package/build/feed.types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
1
|
+
import { FeedItem, SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
2
|
+
import { SubscribeOptions } from './respondingToMercuryDidUpdate/MessageDistributor';
|
|
2
3
|
export type FeedPredicate = SpruceSchemas.Mercury.v2020_12_25.FeedPredicate;
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type SubscribeTargetAndPayload = SpruceSchemas.Feed.v2023_03_04.SubscribeEmitTargetAndPayload;
|
|
5
|
+
declare module '@sprucelabs/spruce-skill-utils/build/types/skill.types' {
|
|
6
|
+
interface SkillContext {
|
|
7
|
+
handleMercuryDidUpdate: (item: FeedItem) => Promise<void>;
|
|
8
|
+
handleSubscribe: (options: SubscribeOptions) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractViewController, Authenticator, Card, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { FeedItem } from '@sprucelabs/spruce-core-schemas';
|
|
3
|
+
import { FeedPredicate } from '../feed.types';
|
|
3
4
|
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
4
5
|
static id: string;
|
|
5
6
|
private isLoaded;
|
|
@@ -9,19 +10,20 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
10
|
private sentMessageCount;
|
|
10
11
|
private pendingAddedMessages;
|
|
11
12
|
protected feedVc: FeedViewController;
|
|
12
|
-
|
|
13
|
+
protected recipientId?: string;
|
|
13
14
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
14
15
|
private FeedVc;
|
|
15
16
|
private CardVc;
|
|
16
17
|
private handleSubmitForm;
|
|
17
18
|
protected handleDidUpdateFeedItem(item: FeedItem): void;
|
|
18
|
-
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.
|
|
19
|
+
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.Feed.v2023_03_04.DidUpdateFeedEmitTargetAndPayload): Promise<void>;
|
|
19
20
|
private sendMessage;
|
|
20
21
|
private removeItem;
|
|
21
22
|
private pushItem;
|
|
22
23
|
private addSentMessage;
|
|
23
24
|
getIsLoaded(): boolean;
|
|
24
25
|
load(options: FeedCardLoadOptions): Promise<void>;
|
|
26
|
+
private subscribe;
|
|
25
27
|
destroy(): Promise<void>;
|
|
26
28
|
private refresh;
|
|
27
29
|
private handleTryAgain;
|
|
@@ -38,21 +38,21 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
38
38
|
return this.sendMessage(message);
|
|
39
39
|
}
|
|
40
40
|
handleDidUpdateFeedItem(item) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
else {
|
|
46
|
-
this.pendingAddedMessages.splice(idx, 1);
|
|
41
|
+
var _a;
|
|
42
|
+
const trackingId = (_a = item.context) === null || _a === void 0 ? void 0 : _a.trackingId;
|
|
43
|
+
if (trackingId) {
|
|
44
|
+
item.id = trackingId;
|
|
47
45
|
}
|
|
46
|
+
this.feedVc.addItem(item);
|
|
48
47
|
}
|
|
49
|
-
handleDidUpdateFeed({ payload, }) {
|
|
48
|
+
async handleDidUpdateFeed({ payload, }) {
|
|
50
49
|
const { item } = payload;
|
|
51
50
|
this.handleDidUpdateFeedItem(item);
|
|
52
51
|
}
|
|
53
52
|
async sendMessage(message) {
|
|
54
53
|
var _a;
|
|
55
|
-
const
|
|
54
|
+
const id = `${new Date().getTime()}-${this.sentMessageCount++}`;
|
|
55
|
+
const added = this.addSentMessage(message, id);
|
|
56
56
|
const client = await this.connectToApi();
|
|
57
57
|
try {
|
|
58
58
|
await client.emitAndFlattenResponses('send-message::v2020_12_25', {
|
|
@@ -61,8 +61,12 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
61
61
|
},
|
|
62
62
|
payload: {
|
|
63
63
|
message: {
|
|
64
|
+
trackingId: id,
|
|
64
65
|
body: message,
|
|
65
66
|
classification: 'transactional',
|
|
67
|
+
context: {
|
|
68
|
+
trackingId: id,
|
|
69
|
+
},
|
|
66
70
|
},
|
|
67
71
|
},
|
|
68
72
|
});
|
|
@@ -85,17 +89,23 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
85
89
|
pushItem(item) {
|
|
86
90
|
this.feedVc.addItem(item);
|
|
87
91
|
}
|
|
88
|
-
addSentMessage(message) {
|
|
92
|
+
addSentMessage(message, id) {
|
|
89
93
|
const person = this.auth.getPerson();
|
|
90
94
|
const item = {
|
|
91
|
-
id
|
|
92
|
-
isMe: true,
|
|
95
|
+
id,
|
|
93
96
|
message: message,
|
|
94
|
-
fromCasualName: person.casualName,
|
|
95
97
|
dateCreated: this.dates.date(),
|
|
96
|
-
avatar: person.avatar,
|
|
97
98
|
source: {
|
|
98
99
|
personId: person.id,
|
|
100
|
+
avatar: person.avatar,
|
|
101
|
+
isMe: true,
|
|
102
|
+
isSprucebot: false,
|
|
103
|
+
casualName: person.casualName,
|
|
104
|
+
},
|
|
105
|
+
target: {
|
|
106
|
+
casualName: 'aou',
|
|
107
|
+
isMe: false,
|
|
108
|
+
isSprucebot: false,
|
|
99
109
|
},
|
|
100
110
|
};
|
|
101
111
|
this.pushItem(item);
|
|
@@ -110,13 +120,28 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
110
120
|
this.predicates = predicates;
|
|
111
121
|
this.auth = authenticator;
|
|
112
122
|
const client = await this.connectToApi();
|
|
113
|
-
await client.on('did-update-feed::
|
|
123
|
+
await client.on('feed.did-update-feed::v2023_03_04', this.handleDidUpdateFeed);
|
|
124
|
+
if (recipientId) {
|
|
125
|
+
await Promise.all([
|
|
126
|
+
this.subscribe(client, {
|
|
127
|
+
toPersonId: recipientId,
|
|
128
|
+
}),
|
|
129
|
+
this.subscribe(client, {
|
|
130
|
+
fromPersonId: recipientId,
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
114
134
|
await this.refresh();
|
|
115
135
|
}
|
|
136
|
+
async subscribe(client, target) {
|
|
137
|
+
await client.emitAndFlattenResponses('feed.subscribe::v2023_03_04', {
|
|
138
|
+
target,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
116
141
|
async destroy() {
|
|
117
142
|
await super.destroy();
|
|
118
143
|
const client = await this.connectToApi();
|
|
119
|
-
await client.off('did-update-feed::
|
|
144
|
+
await client.off('feed.did-update-feed::v2023_03_04', this.handleDidUpdateFeed);
|
|
120
145
|
}
|
|
121
146
|
async refresh() {
|
|
122
147
|
const client = await this.connectToApi();
|