@sprucelabs/spruce-feed-view-controllers 0.0.6 → 0.0.9
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.
|
@@ -9,16 +9,18 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
9
|
private shouldEnableChat;
|
|
10
10
|
private auth;
|
|
11
11
|
private sentMessageCount;
|
|
12
|
+
private pendingAddedMessages;
|
|
12
13
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
13
14
|
private CardVc;
|
|
14
15
|
private FormVc;
|
|
15
16
|
private handleChangeForm;
|
|
16
17
|
private handleSubmitForm;
|
|
17
18
|
private setMessage;
|
|
19
|
+
private handleDidUpdateFeed;
|
|
18
20
|
private sendMessage;
|
|
19
|
-
private
|
|
20
|
-
private addSentMessage;
|
|
21
|
+
private removeItem;
|
|
21
22
|
private pushItem;
|
|
23
|
+
private addSentMessage;
|
|
22
24
|
private getFeed;
|
|
23
25
|
getIsLoaded(): boolean;
|
|
24
26
|
load(options: {
|
|
@@ -15,6 +15,7 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
15
15
|
this.isLoaded = false;
|
|
16
16
|
this.predicates = [];
|
|
17
17
|
this.sentMessageCount = 0;
|
|
18
|
+
this.pendingAddedMessages = [];
|
|
18
19
|
const { shouldEnableChat } = options;
|
|
19
20
|
this.shouldEnableChat = !!shouldEnableChat;
|
|
20
21
|
this.formVc = this.FormVc();
|
|
@@ -87,6 +88,16 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
87
88
|
yield this.formVc.setValue('message', value);
|
|
88
89
|
});
|
|
89
90
|
}
|
|
91
|
+
handleDidUpdateFeed(item) {
|
|
92
|
+
const idx = this.pendingAddedMessages.indexOf(item.message);
|
|
93
|
+
console.log({ idx });
|
|
94
|
+
if (idx === -1) {
|
|
95
|
+
this.pushItem(item);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.pendingAddedMessages.splice(idx, 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
90
101
|
sendMessage(message) {
|
|
91
102
|
var _a;
|
|
92
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -101,9 +112,10 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
101
112
|
},
|
|
102
113
|
},
|
|
103
114
|
});
|
|
115
|
+
this.pendingAddedMessages.push(message);
|
|
104
116
|
}
|
|
105
117
|
catch (err) {
|
|
106
|
-
this.
|
|
118
|
+
this.removeItem(added.id);
|
|
107
119
|
yield this.setMessage(added.message);
|
|
108
120
|
yield this.alert({
|
|
109
121
|
title: 'Failed to send message!',
|
|
@@ -113,11 +125,16 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
113
125
|
}
|
|
114
126
|
});
|
|
115
127
|
}
|
|
116
|
-
|
|
128
|
+
removeItem(id) {
|
|
117
129
|
const feed = this.getFeed();
|
|
118
130
|
feed.items = feed.items.filter((i) => i.id !== id);
|
|
119
131
|
this.cardVc.updateSection('feed', { feed });
|
|
120
132
|
}
|
|
133
|
+
pushItem(item) {
|
|
134
|
+
const { items } = this.getFeed();
|
|
135
|
+
items.push(item);
|
|
136
|
+
this.cardVc.triggerRender();
|
|
137
|
+
}
|
|
121
138
|
addSentMessage(message) {
|
|
122
139
|
const person = this.auth.getPerson();
|
|
123
140
|
const item = {
|
|
@@ -134,11 +151,6 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
134
151
|
this.pushItem(item);
|
|
135
152
|
return item;
|
|
136
153
|
}
|
|
137
|
-
pushItem(item) {
|
|
138
|
-
const { items } = this.getFeed();
|
|
139
|
-
items.push(item);
|
|
140
|
-
this.cardVc.triggerRender();
|
|
141
|
-
}
|
|
142
154
|
getFeed() {
|
|
143
155
|
const { feed } = this.cardVc.getSection('feed');
|
|
144
156
|
return feed;
|
|
@@ -153,7 +165,8 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
153
165
|
this.auth = authenticator;
|
|
154
166
|
const client = yield this.connectToApi();
|
|
155
167
|
yield client.on('did-update-feed::v2020_12_25', ({ payload }) => {
|
|
156
|
-
|
|
168
|
+
const { item } = payload;
|
|
169
|
+
this.handleDidUpdateFeed(item);
|
|
157
170
|
});
|
|
158
171
|
yield this.refresh();
|
|
159
172
|
});
|
|
@@ -167,12 +180,12 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
167
180
|
predicates: this.predicates,
|
|
168
181
|
},
|
|
169
182
|
});
|
|
183
|
+
feed.items.reverse();
|
|
170
184
|
this.cardVc.setSection('feed', {
|
|
171
185
|
feed: Object.assign(Object.assign({}, feed), { shouldEnableChat: true }),
|
|
172
186
|
});
|
|
173
187
|
}
|
|
174
188
|
catch (err) {
|
|
175
|
-
console.error(err.stack || err.message);
|
|
176
189
|
this.cardVc.setCriticalError({
|
|
177
190
|
title: 'Feed error!',
|
|
178
191
|
message: err.message,
|
|
@@ -9,16 +9,18 @@ export default class FeedCardViewController extends AbstractViewController<Card>
|
|
|
9
9
|
private shouldEnableChat;
|
|
10
10
|
private auth;
|
|
11
11
|
private sentMessageCount;
|
|
12
|
+
private pendingAddedMessages;
|
|
12
13
|
constructor(options: ViewControllerOptions & FeedCardViewControllerOptions);
|
|
13
14
|
private CardVc;
|
|
14
15
|
private FormVc;
|
|
15
16
|
private handleChangeForm;
|
|
16
17
|
private handleSubmitForm;
|
|
17
18
|
private setMessage;
|
|
19
|
+
private handleDidUpdateFeed;
|
|
18
20
|
private sendMessage;
|
|
19
|
-
private
|
|
20
|
-
private addSentMessage;
|
|
21
|
+
private removeItem;
|
|
21
22
|
private pushItem;
|
|
23
|
+
private addSentMessage;
|
|
22
24
|
private getFeed;
|
|
23
25
|
getIsLoaded(): boolean;
|
|
24
26
|
load(options: {
|
|
@@ -8,6 +8,7 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
8
8
|
this.isLoaded = false;
|
|
9
9
|
this.predicates = [];
|
|
10
10
|
this.sentMessageCount = 0;
|
|
11
|
+
this.pendingAddedMessages = [];
|
|
11
12
|
const { shouldEnableChat } = options;
|
|
12
13
|
this.shouldEnableChat = !!shouldEnableChat;
|
|
13
14
|
this.formVc = this.FormVc();
|
|
@@ -74,6 +75,16 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
74
75
|
async setMessage(value) {
|
|
75
76
|
await this.formVc.setValue('message', value);
|
|
76
77
|
}
|
|
78
|
+
handleDidUpdateFeed(item) {
|
|
79
|
+
const idx = this.pendingAddedMessages.indexOf(item.message);
|
|
80
|
+
console.log({ idx });
|
|
81
|
+
if (idx === -1) {
|
|
82
|
+
this.pushItem(item);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.pendingAddedMessages.splice(idx, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
77
88
|
async sendMessage(message) {
|
|
78
89
|
var _a;
|
|
79
90
|
const added = this.addSentMessage(message);
|
|
@@ -87,9 +98,10 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
87
98
|
},
|
|
88
99
|
},
|
|
89
100
|
});
|
|
101
|
+
this.pendingAddedMessages.push(message);
|
|
90
102
|
}
|
|
91
103
|
catch (err) {
|
|
92
|
-
this.
|
|
104
|
+
this.removeItem(added.id);
|
|
93
105
|
await this.setMessage(added.message);
|
|
94
106
|
await this.alert({
|
|
95
107
|
title: 'Failed to send message!',
|
|
@@ -98,11 +110,16 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
98
110
|
console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
|
-
|
|
113
|
+
removeItem(id) {
|
|
102
114
|
const feed = this.getFeed();
|
|
103
115
|
feed.items = feed.items.filter((i) => i.id !== id);
|
|
104
116
|
this.cardVc.updateSection('feed', { feed });
|
|
105
117
|
}
|
|
118
|
+
pushItem(item) {
|
|
119
|
+
const { items } = this.getFeed();
|
|
120
|
+
items.push(item);
|
|
121
|
+
this.cardVc.triggerRender();
|
|
122
|
+
}
|
|
106
123
|
addSentMessage(message) {
|
|
107
124
|
const person = this.auth.getPerson();
|
|
108
125
|
const item = {
|
|
@@ -119,11 +136,6 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
119
136
|
this.pushItem(item);
|
|
120
137
|
return item;
|
|
121
138
|
}
|
|
122
|
-
pushItem(item) {
|
|
123
|
-
const { items } = this.getFeed();
|
|
124
|
-
items.push(item);
|
|
125
|
-
this.cardVc.triggerRender();
|
|
126
|
-
}
|
|
127
139
|
getFeed() {
|
|
128
140
|
const { feed } = this.cardVc.getSection('feed');
|
|
129
141
|
return feed;
|
|
@@ -137,7 +149,8 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
137
149
|
this.auth = authenticator;
|
|
138
150
|
const client = await this.connectToApi();
|
|
139
151
|
await client.on('did-update-feed::v2020_12_25', ({ payload }) => {
|
|
140
|
-
|
|
152
|
+
const { item } = payload;
|
|
153
|
+
this.handleDidUpdateFeed(item);
|
|
141
154
|
});
|
|
142
155
|
await this.refresh();
|
|
143
156
|
}
|
|
@@ -149,12 +162,12 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
149
162
|
predicates: this.predicates,
|
|
150
163
|
},
|
|
151
164
|
});
|
|
165
|
+
feed.items.reverse();
|
|
152
166
|
this.cardVc.setSection('feed', {
|
|
153
167
|
feed: Object.assign(Object.assign({}, feed), { shouldEnableChat: true }),
|
|
154
168
|
});
|
|
155
169
|
}
|
|
156
170
|
catch (err) {
|
|
157
|
-
console.error(err.stack || err.message);
|
|
158
171
|
this.cardVc.setCriticalError({
|
|
159
172
|
title: 'Feed error!',
|
|
160
173
|
message: err.message,
|