Skip to content

Commit 8515df3

Browse files
committed
list to websocket
1 parent dd8161e commit 8515df3

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ qx.Class.define("osparc.conversation.Conversation", {
2727
this.base(arguments);
2828

2929
this.__studyData = studyData;
30+
this.__messages = [];
3031

3132
if (conversationId) {
3233
this.setConversationId(conversationId);
@@ -64,6 +65,7 @@ qx.Class.define("osparc.conversation.Conversation", {
6465

6566
members: {
6667
__studyData: null,
68+
__messages: null,
6769
__nextRequestParams: null,
6870
__messagesTitle: null,
6971
__messagesList: null,
@@ -189,14 +191,13 @@ qx.Class.define("osparc.conversation.Conversation", {
189191
this.__loadMoreMessages.setFetching(true);
190192

191193
if (removeMessages) {
194+
this.__messages = [];
192195
this.__messagesList.removeAll();
193196
}
194197

195198
this.__getNextRequest()
196199
.then(resp => {
197200
const messages = resp["data"];
198-
// it's not provided by the backend
199-
messages.forEach(message => message["studyId"] = this.__studyData["uuid"]);
200201
this.__addMessages(messages);
201202
this.__nextRequestParams = resp["_links"]["next"];
202203
if (this.__nextRequestParams === null) {
@@ -227,6 +228,11 @@ qx.Class.define("osparc.conversation.Conversation", {
227228
},
228229

229230
__addMessages: function(messages) {
231+
// it's not provided by the backend
232+
messages.forEach(message => message["projectId"] = this.__studyData["uuid"]);
233+
234+
this.__messages = this.__messages.concat(messages);
235+
230236
const nMessages = messages.filter(msg => msg["type"] === "MESSAGE").length;
231237
if (nMessages === 1) {
232238
this.__messagesTitle.setValue(this.tr("1 Message"));

services/static-webserver/client/source/class/osparc/conversation/MessageUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ qx.Class.define("osparc.conversation.MessageUI", {
211211
win.open();
212212
win.addListener("close", () => {
213213
if (win.getConfirmed()) {
214-
osparc.study.Conversations.deleteMessage(this.__message["studyId"], this.__message["conversationId"], this.__message["messageId"])
214+
osparc.study.Conversations.deleteMessage(this.__message["projectId"], this.__message["conversationId"], this.__message["messageId"])
215215
.then(() => this.fireEvent("messageDeleted"))
216216
.catch(err => osparc.FlashMessenger.logError(err));
217217
}

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ qx.Class.define("osparc.study.Conversations", {
2727

2828
this._setLayout(new qx.ui.layout.VBox());
2929

30+
this.__conversations = [];
31+
3032
this.fetchConversations(studyData);
3133
},
3234

@@ -138,6 +140,8 @@ qx.Class.define("osparc.study.Conversations", {
138140
},
139141

140142
members: {
143+
__conversations: null,
144+
141145
_createChildControlImpl: function(id) {
142146
let control;
143147
switch (id) {
@@ -156,6 +160,37 @@ qx.Class.define("osparc.study.Conversations", {
156160
return control || this.base(arguments, id);
157161
},
158162

163+
__listenToConversationWS: function() {
164+
const socket = osparc.wrapper.WebSocket.getInstance();
165+
166+
socket.on("conversation:message:created", data => {
167+
if (data) {
168+
const projectId = data["projectId"];
169+
const conversationId = data["conversationId"];
170+
const messageId = data["messageId"];
171+
console.log("Conversation message created", projectId, conversationId, messageId);
172+
}
173+
}, this);
174+
175+
socket.on("conversation:message:update", data => {
176+
if (data) {
177+
const projectId = data["projectId"];
178+
const conversationId = data["conversationId"];
179+
const messageId = data["messageId"];
180+
console.log("Conversation message created", projectId, conversationId, messageId);
181+
}
182+
}, this);
183+
184+
socket.on("conversation:message:deleted", data => {
185+
if (data) {
186+
const projectId = data["projectId"];
187+
const conversationId = data["conversationId"];
188+
const messageId = data["messageId"];
189+
console.log("Conversation message created", projectId, conversationId, messageId);
190+
}
191+
}, this);
192+
},
193+
159194
fetchConversations: function(studyData) {
160195
const loadMoreButton = this.getChildControl("loading-button");
161196
loadMoreButton.setFetching(true);
@@ -192,20 +227,22 @@ qx.Class.define("osparc.study.Conversations", {
192227
this.fetchConversations(studyData);
193228
};
194229

230+
this.__conversations = [];
195231
if (conversations.length === 0) {
196232
const noConversationTab = new osparc.conversation.Conversation(studyData);
197233
conversationPages.push(noConversationTab);
198234
noConversationTab.setLabel(this.tr("new"));
199235
noConversationTab.addListener("conversationDeleted", () => reloadConversations());
200236
conversationsLayout.add(noConversationTab);
201237
} else {
202-
conversations.forEach(conversation => {
203-
const conversationId = conversation["conversationId"];
204-
const conversationTab = new osparc.conversation.Conversation(studyData, conversationId);
205-
conversationPages.push(conversationTab);
206-
conversationTab.setLabel(conversation["name"]);
207-
conversationTab.addListener("conversationDeleted", () => reloadConversations());
208-
conversationsLayout.add(conversationTab);
238+
conversations.forEach(conversationData => {
239+
const conversationId = conversationData["conversationId"];
240+
const conversation = new osparc.conversation.Conversation(studyData, conversationId);
241+
this.__conversations.push(conversation);
242+
conversationPages.push(conversation);
243+
conversation.setLabel(conversationData["name"]);
244+
conversation.addListener("conversationDeleted", () => reloadConversations());
245+
conversationsLayout.add(conversation);
209246
});
210247
}
211248

0 commit comments

Comments
 (0)