@sprucelabs/spruce-feed-view-controllers 0.0.6 → 0.0.7
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,15 @@ 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
|
+
if (idx === -1) {
|
|
94
|
+
this.pushItem(item);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.pendingAddedMessages.splice(idx, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
sendMessage(message) {
|
|
91
101
|
var _a;
|
|
92
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -101,9 +111,10 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
101
111
|
},
|
|
102
112
|
},
|
|
103
113
|
});
|
|
114
|
+
this.pendingAddedMessages.push(message);
|
|
104
115
|
}
|
|
105
116
|
catch (err) {
|
|
106
|
-
this.
|
|
117
|
+
this.removeItem(added.id);
|
|
107
118
|
yield this.setMessage(added.message);
|
|
108
119
|
yield this.alert({
|
|
109
120
|
title: 'Failed to send message!',
|
|
@@ -113,11 +124,16 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
113
124
|
}
|
|
114
125
|
});
|
|
115
126
|
}
|
|
116
|
-
|
|
127
|
+
removeItem(id) {
|
|
117
128
|
const feed = this.getFeed();
|
|
118
129
|
feed.items = feed.items.filter((i) => i.id !== id);
|
|
119
130
|
this.cardVc.updateSection('feed', { feed });
|
|
120
131
|
}
|
|
132
|
+
pushItem(item) {
|
|
133
|
+
const { items } = this.getFeed();
|
|
134
|
+
items.push(item);
|
|
135
|
+
this.cardVc.triggerRender();
|
|
136
|
+
}
|
|
121
137
|
addSentMessage(message) {
|
|
122
138
|
const person = this.auth.getPerson();
|
|
123
139
|
const item = {
|
|
@@ -134,11 +150,6 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
134
150
|
this.pushItem(item);
|
|
135
151
|
return item;
|
|
136
152
|
}
|
|
137
|
-
pushItem(item) {
|
|
138
|
-
const { items } = this.getFeed();
|
|
139
|
-
items.push(item);
|
|
140
|
-
this.cardVc.triggerRender();
|
|
141
|
-
}
|
|
142
153
|
getFeed() {
|
|
143
154
|
const { feed } = this.cardVc.getSection('feed');
|
|
144
155
|
return feed;
|
|
@@ -153,7 +164,8 @@ export default class FeedCardViewController extends AbstractViewController {
|
|
|
153
164
|
this.auth = authenticator;
|
|
154
165
|
const client = yield this.connectToApi();
|
|
155
166
|
yield client.on('did-update-feed::v2020_12_25', ({ payload }) => {
|
|
156
|
-
|
|
167
|
+
const { item } = payload;
|
|
168
|
+
this.handleDidUpdateFeed(item);
|
|
157
169
|
});
|
|
158
170
|
yield this.refresh();
|
|
159
171
|
});
|
|
@@ -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,15 @@ 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
|
+
if (idx === -1) {
|
|
81
|
+
this.pushItem(item);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.pendingAddedMessages.splice(idx, 1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
async sendMessage(message) {
|
|
78
88
|
var _a;
|
|
79
89
|
const added = this.addSentMessage(message);
|
|
@@ -87,9 +97,10 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
87
97
|
},
|
|
88
98
|
},
|
|
89
99
|
});
|
|
100
|
+
this.pendingAddedMessages.push(message);
|
|
90
101
|
}
|
|
91
102
|
catch (err) {
|
|
92
|
-
this.
|
|
103
|
+
this.removeItem(added.id);
|
|
93
104
|
await this.setMessage(added.message);
|
|
94
105
|
await this.alert({
|
|
95
106
|
title: 'Failed to send message!',
|
|
@@ -98,11 +109,16 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
98
109
|
console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
|
-
|
|
112
|
+
removeItem(id) {
|
|
102
113
|
const feed = this.getFeed();
|
|
103
114
|
feed.items = feed.items.filter((i) => i.id !== id);
|
|
104
115
|
this.cardVc.updateSection('feed', { feed });
|
|
105
116
|
}
|
|
117
|
+
pushItem(item) {
|
|
118
|
+
const { items } = this.getFeed();
|
|
119
|
+
items.push(item);
|
|
120
|
+
this.cardVc.triggerRender();
|
|
121
|
+
}
|
|
106
122
|
addSentMessage(message) {
|
|
107
123
|
const person = this.auth.getPerson();
|
|
108
124
|
const item = {
|
|
@@ -119,11 +135,6 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
119
135
|
this.pushItem(item);
|
|
120
136
|
return item;
|
|
121
137
|
}
|
|
122
|
-
pushItem(item) {
|
|
123
|
-
const { items } = this.getFeed();
|
|
124
|
-
items.push(item);
|
|
125
|
-
this.cardVc.triggerRender();
|
|
126
|
-
}
|
|
127
138
|
getFeed() {
|
|
128
139
|
const { feed } = this.cardVc.getSection('feed');
|
|
129
140
|
return feed;
|
|
@@ -137,7 +148,8 @@ class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewCo
|
|
|
137
148
|
this.auth = authenticator;
|
|
138
149
|
const client = await this.connectToApi();
|
|
139
150
|
await client.on('did-update-feed::v2020_12_25', ({ payload }) => {
|
|
140
|
-
|
|
151
|
+
const { item } = payload;
|
|
152
|
+
this.handleDidUpdateFeed(item);
|
|
141
153
|
});
|
|
142
154
|
await this.refresh();
|
|
143
155
|
}
|