@sprucelabs/spruce-feed-view-controllers 0.0.185 → 0.0.187
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,5 +1,5 @@
|
|
|
1
|
-
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { Card, FeedPredicate } from '../feed.types';
|
|
1
|
+
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Card, FeedItem, FeedPredicate } from '../feed.types';
|
|
3
3
|
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
4
4
|
static id: string;
|
|
5
5
|
private isLoaded;
|
|
@@ -9,24 +9,29 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
9
|
private sentMessageCount;
|
|
10
10
|
private pendingAddedMessages;
|
|
11
11
|
protected feedVc: FeedViewController;
|
|
12
|
+
private recipientId?;
|
|
12
13
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
13
14
|
private FeedVc;
|
|
14
15
|
private CardVc;
|
|
15
16
|
private handleSubmitForm;
|
|
16
|
-
|
|
17
|
+
protected handleDidUpdateFeedItem(item: FeedItem): void;
|
|
18
|
+
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.Mercury.v2020_12_25.DidUpdateFeedEmitTargetAndPayload): void;
|
|
17
19
|
private sendMessage;
|
|
18
20
|
private removeItem;
|
|
19
21
|
private pushItem;
|
|
20
22
|
private addSentMessage;
|
|
21
23
|
getIsLoaded(): boolean;
|
|
22
|
-
load(options:
|
|
23
|
-
|
|
24
|
-
authenticator: Authenticator;
|
|
25
|
-
}): Promise<void>;
|
|
24
|
+
load(options: FeedCardLoadOptions): Promise<void>;
|
|
25
|
+
destroy(): Promise<void>;
|
|
26
26
|
private refresh;
|
|
27
27
|
private handleTryAgain;
|
|
28
|
-
render():
|
|
28
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
29
29
|
}
|
|
30
30
|
export type FeedCardViewControllerOptions = {
|
|
31
31
|
id?: string;
|
|
32
32
|
};
|
|
33
|
+
export interface FeedCardLoadOptions {
|
|
34
|
+
predicates: FeedPredicate[];
|
|
35
|
+
authenticator: Authenticator;
|
|
36
|
+
recipientId?: string;
|
|
37
|
+
}
|
|
@@ -18,6 +18,7 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
18
18
|
this.pendingAddedMessages = [];
|
|
19
19
|
this.feedVc = this.FeedVc();
|
|
20
20
|
this.cardVc = this.CardVc(options);
|
|
21
|
+
this.handleDidUpdateFeed = this.handleDidUpdateFeed.bind(this);
|
|
21
22
|
}
|
|
22
23
|
FeedVc() {
|
|
23
24
|
return this.Controller('feed', {
|
|
@@ -46,9 +47,8 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
46
47
|
return this.sendMessage(message);
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
handleDidUpdateFeedItem(item) {
|
|
50
51
|
const idx = this.pendingAddedMessages.indexOf(item.message);
|
|
51
|
-
console.log({ idx });
|
|
52
52
|
if (idx === -1) {
|
|
53
53
|
this.pushItem(item);
|
|
54
54
|
}
|
|
@@ -56,6 +56,10 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
56
56
|
this.pendingAddedMessages.splice(idx, 1);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
handleDidUpdateFeed({ payload, }) {
|
|
60
|
+
const { item } = payload;
|
|
61
|
+
this.handleDidUpdateFeedItem(item);
|
|
62
|
+
}
|
|
59
63
|
sendMessage(message) {
|
|
60
64
|
var _a;
|
|
61
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,6 +67,9 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
63
67
|
const client = yield this.connectToApi();
|
|
64
68
|
try {
|
|
65
69
|
yield client.emitAndFlattenResponses('send-message::v2020_12_25', {
|
|
70
|
+
target: {
|
|
71
|
+
personId: this.recipientId,
|
|
72
|
+
},
|
|
66
73
|
payload: {
|
|
67
74
|
message: {
|
|
68
75
|
body: message,
|
|
@@ -111,17 +118,25 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
111
118
|
}
|
|
112
119
|
load(options) {
|
|
113
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const { predicates, authenticator } = assertOptions(options, ['predicates', 'authenticator'], `You have to pass the search predicates and the authenticator to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
121
|
+
const { predicates, authenticator, recipientId } = assertOptions(options, ['predicates', 'authenticator'], `You have to pass the search predicates and the authenticator to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
122
|
+
this.recipientId = recipientId;
|
|
115
123
|
this.predicates = predicates;
|
|
116
124
|
this.auth = authenticator;
|
|
117
125
|
const client = yield this.connectToApi();
|
|
118
|
-
yield client.on('did-update-feed::v2020_12_25',
|
|
119
|
-
const { item } = payload;
|
|
120
|
-
this.handleDidUpdateFeed(item);
|
|
121
|
-
});
|
|
126
|
+
yield client.on('did-update-feed::v2020_12_25', this.handleDidUpdateFeed);
|
|
122
127
|
yield this.refresh();
|
|
123
128
|
});
|
|
124
129
|
}
|
|
130
|
+
destroy() {
|
|
131
|
+
const _super = Object.create(null, {
|
|
132
|
+
destroy: { get: () => super.destroy }
|
|
133
|
+
});
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
yield _super.destroy.call(this);
|
|
136
|
+
const client = yield this.connectToApi();
|
|
137
|
+
yield client.off('did-update-feed::v2020_12_25', this.handleDidUpdateFeed);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
125
140
|
refresh() {
|
|
126
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
142
|
const client = yield this.connectToApi();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { Card, FeedPredicate } from '../feed.types';
|
|
1
|
+
import { AbstractViewController, Authenticator, CardViewController, FeedViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Card, FeedItem, FeedPredicate } from '../feed.types';
|
|
3
3
|
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
4
4
|
static id: string;
|
|
5
5
|
private isLoaded;
|
|
@@ -9,24 +9,29 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
9
|
private sentMessageCount;
|
|
10
10
|
private pendingAddedMessages;
|
|
11
11
|
protected feedVc: FeedViewController;
|
|
12
|
+
private recipientId?;
|
|
12
13
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
13
14
|
private FeedVc;
|
|
14
15
|
private CardVc;
|
|
15
16
|
private handleSubmitForm;
|
|
16
|
-
|
|
17
|
+
protected handleDidUpdateFeedItem(item: FeedItem): void;
|
|
18
|
+
protected handleDidUpdateFeed({ payload, }: SpruceSchemas.Mercury.v2020_12_25.DidUpdateFeedEmitTargetAndPayload): void;
|
|
17
19
|
private sendMessage;
|
|
18
20
|
private removeItem;
|
|
19
21
|
private pushItem;
|
|
20
22
|
private addSentMessage;
|
|
21
23
|
getIsLoaded(): boolean;
|
|
22
|
-
load(options:
|
|
23
|
-
|
|
24
|
-
authenticator: Authenticator;
|
|
25
|
-
}): Promise<void>;
|
|
24
|
+
load(options: FeedCardLoadOptions): Promise<void>;
|
|
25
|
+
destroy(): Promise<void>;
|
|
26
26
|
private refresh;
|
|
27
27
|
private handleTryAgain;
|
|
28
|
-
render():
|
|
28
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
29
29
|
}
|
|
30
30
|
export type FeedCardViewControllerOptions = {
|
|
31
31
|
id?: string;
|
|
32
32
|
};
|
|
33
|
+
export interface FeedCardLoadOptions {
|
|
34
|
+
predicates: FeedPredicate[];
|
|
35
|
+
authenticator: Authenticator;
|
|
36
|
+
recipientId?: string;
|
|
37
|
+
}
|
|
@@ -11,6 +11,7 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
11
11
|
this.pendingAddedMessages = [];
|
|
12
12
|
this.feedVc = this.FeedVc();
|
|
13
13
|
this.cardVc = this.CardVc(options);
|
|
14
|
+
this.handleDidUpdateFeed = this.handleDidUpdateFeed.bind(this);
|
|
14
15
|
}
|
|
15
16
|
FeedVc() {
|
|
16
17
|
return this.Controller('feed', {
|
|
@@ -37,9 +38,8 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
37
38
|
async handleSubmitForm(message) {
|
|
38
39
|
return this.sendMessage(message);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
handleDidUpdateFeedItem(item) {
|
|
41
42
|
const idx = this.pendingAddedMessages.indexOf(item.message);
|
|
42
|
-
console.log({ idx });
|
|
43
43
|
if (idx === -1) {
|
|
44
44
|
this.pushItem(item);
|
|
45
45
|
}
|
|
@@ -47,12 +47,19 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
47
47
|
this.pendingAddedMessages.splice(idx, 1);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
handleDidUpdateFeed({ payload, }) {
|
|
51
|
+
const { item } = payload;
|
|
52
|
+
this.handleDidUpdateFeedItem(item);
|
|
53
|
+
}
|
|
50
54
|
async sendMessage(message) {
|
|
51
55
|
var _a;
|
|
52
56
|
const added = this.addSentMessage(message);
|
|
53
57
|
const client = await this.connectToApi();
|
|
54
58
|
try {
|
|
55
59
|
await client.emitAndFlattenResponses('send-message::v2020_12_25', {
|
|
60
|
+
target: {
|
|
61
|
+
personId: this.recipientId,
|
|
62
|
+
},
|
|
56
63
|
payload: {
|
|
57
64
|
message: {
|
|
58
65
|
body: message,
|
|
@@ -99,16 +106,19 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
99
106
|
return this.isLoaded;
|
|
100
107
|
}
|
|
101
108
|
async load(options) {
|
|
102
|
-
const { predicates, authenticator } = (0, schema_1.assertOptions)(options, ['predicates', 'authenticator'], `You have to pass the search predicates and the authenticator to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
109
|
+
const { predicates, authenticator, recipientId } = (0, schema_1.assertOptions)(options, ['predicates', 'authenticator'], `You have to pass the search predicates and the authenticator to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
110
|
+
this.recipientId = recipientId;
|
|
103
111
|
this.predicates = predicates;
|
|
104
112
|
this.auth = authenticator;
|
|
105
113
|
const client = await this.connectToApi();
|
|
106
|
-
await client.on('did-update-feed::v2020_12_25',
|
|
107
|
-
const { item } = payload;
|
|
108
|
-
this.handleDidUpdateFeed(item);
|
|
109
|
-
});
|
|
114
|
+
await client.on('did-update-feed::v2020_12_25', this.handleDidUpdateFeed);
|
|
110
115
|
await this.refresh();
|
|
111
116
|
}
|
|
117
|
+
async destroy() {
|
|
118
|
+
await super.destroy();
|
|
119
|
+
const client = await this.connectToApi();
|
|
120
|
+
await client.off('did-update-feed::v2020_12_25', this.handleDidUpdateFeed);
|
|
121
|
+
}
|
|
112
122
|
async refresh() {
|
|
113
123
|
const client = await this.connectToApi();
|
|
114
124
|
try {
|