Skip to content

Commit 285c718

Browse files
committed
use model
1 parent dcefb12 commit 285c718

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

services/static-webserver/client/source/class/osparc/data/model/Conversation.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ qx.Class.define("osparc.data.model.Conversation", {
2424

2525
/**
2626
* @param conversationData {Object} Object containing the serialized Conversation Data
27+
* @param studyData {Object} Object containing the Study Data
2728
* */
28-
construct: function(conversationData) {
29+
construct: function(conversationData, studyData) {
2930
this.base(arguments);
3031

3132
this.set({
@@ -37,6 +38,7 @@ qx.Class.define("osparc.data.model.Conversation", {
3738
modified: new Date(conversationData.modified),
3839
projectId: conversationData.projectUuid || null,
3940
extraContext: conversationData.extraContext || null,
41+
studyData: studyData || null,
4042
});
4143

4244
this.__messages = [];
@@ -134,6 +136,12 @@ qx.Class.define("osparc.data.model.Conversation", {
134136
event: "changeLastMessage",
135137
apply: "__applyLastMessage",
136138
},
139+
140+
studyData: {
141+
check: "Object",
142+
nullable: true,
143+
init: null,
144+
},
137145
},
138146

139147
events: {
@@ -221,6 +229,10 @@ qx.Class.define("osparc.data.model.Conversation", {
221229
limit: 42
222230
}
223231
};
232+
if (this.getStudyData()) {
233+
params.url.studyId = this.getStudyData().uuid;
234+
}
235+
224236
const nextRequestParams = this.__nextRequestParams;
225237
if (nextRequestParams) {
226238
params.url.offset = nextRequestParams.offset;
@@ -229,7 +241,10 @@ qx.Class.define("osparc.data.model.Conversation", {
229241
const options = {
230242
resolveWResponse: true
231243
};
232-
return osparc.data.Resources.fetch("conversationsSupport", "getMessagesPage", params, options)
244+
const promise = this.getStudyData() ?
245+
osparc.data.Resources.fetch("conversationsStudies", "getMessagesPage", params, options) :
246+
osparc.data.Resources.fetch("conversationsSupport", "getMessagesPage", params, options);
247+
return promise
233248
.then(resp => {
234249
const messages = resp["data"];
235250
messages.forEach(message => this.addMessage(message));

services/static-webserver/client/source/class/osparc/study/Conversation.js

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ qx.Class.define("osparc.study.Conversation", {
3030
this.__messages = [];
3131

3232
if (conversationData) {
33-
const conversation = new osparc.data.model.Conversation(conversationData);
33+
const conversation = new osparc.data.model.Conversation(conversationData, this.__studyData);
3434
this.setConversation(conversation);
3535
this.setLabel(conversationData["name"]);
3636
} else {
@@ -120,7 +120,7 @@ qx.Class.define("osparc.study.Conversation", {
120120
// create new conversation first
121121
osparc.store.ConversationsProject.getInstance().postConversation(this.__studyData["uuid"], newLabel)
122122
.then(data => {
123-
const conversation = new osparc.data.model.Conversation(data);
123+
const conversation = new osparc.data.model.Conversation(data, this.__studyData);
124124
this.setConversation(conversation);
125125
this.getChildControl("button").setLabel(newLabel);
126126
});
@@ -209,7 +209,7 @@ qx.Class.define("osparc.study.Conversation", {
209209
// create new conversation first
210210
osparc.store.ConversationsProject.getInstance().postConversation(this.__studyData["uuid"])
211211
.then(data => {
212-
const newConversation = new osparc.data.model.Conversation(data);
212+
const newConversation = new osparc.data.model.Conversation(data, this.__studyData);
213213
this.setConversation(newConversation);
214214
this.__postMessage(content);
215215
});
@@ -224,7 +224,7 @@ qx.Class.define("osparc.study.Conversation", {
224224
// create new conversation first
225225
osparc.store.ConversationsProject.getInstance().postConversation(this.__studyData["uuid"])
226226
.then(data => {
227-
const newConversation = new osparc.data.model.Conversation(data);
227+
const newConversation = new osparc.data.model.Conversation(data, this.__studyData);
228228
this.setConversation(newConversation);
229229
this.__postNotify(userGid);
230230
});
@@ -255,27 +255,6 @@ qx.Class.define("osparc.study.Conversation", {
255255
});
256256
},
257257

258-
__getNextRequest: function() {
259-
const params = {
260-
url: {
261-
studyId: this.__studyData["uuid"],
262-
conversationId: this.getConversationId(),
263-
offset: 0,
264-
limit: 42
265-
}
266-
};
267-
const nextRequestParams = this.__nextRequestParams;
268-
if (nextRequestParams) {
269-
params.url.offset = nextRequestParams.offset;
270-
params.url.limit = nextRequestParams.limit;
271-
}
272-
const options = {
273-
resolveWResponse: true
274-
};
275-
return osparc.data.Resources.fetch("conversationsStudies", "getMessagesPage", params, options)
276-
.catch(err => osparc.FlashMessenger.logError(err));
277-
},
278-
279258
__reloadMessages: function(removeMessages = true) {
280259
if (this.getConversationId() === null) {
281260
// temporary conversation page
@@ -285,16 +264,15 @@ qx.Class.define("osparc.study.Conversation", {
285264
return;
286265
}
287266

288-
this.__messagesList.show();
289-
this.__loadMoreMessages.show();
290-
this.__loadMoreMessages.setFetching(true);
291-
292267
if (removeMessages) {
293268
this.__messages = [];
294269
this.__messagesList.removeAll();
295270
}
271+
this.__messagesList.show();
296272

297-
this.__getNextRequest()
273+
this.__loadMoreMessages.show();
274+
this.__loadMoreMessages.setFetching(true);
275+
this.getConversation().getNextMessages()
298276
.then(resp => {
299277
const messages = resp["data"];
300278
messages.forEach(message => this.addMessage(message));
@@ -403,7 +381,8 @@ qx.Class.define("osparc.study.Conversation", {
403381
// Update the UI element from the messages list
404382
this.__messagesList.getChildren().forEach(control => {
405383
if ("getMessage" in control && control.getMessage()["messageId"] === message["messageId"]) {
406-
control.setMessage(message);
384+
// Force a new reference
385+
control.setMessage(Object.assign({}, message));
407386
return;
408387
}
409388
});

0 commit comments

Comments
 (0)