Skip to content

Commit 84ffd79

Browse files
committed
use model
1 parent 5755d87 commit 84ffd79

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ qx.Class.define("osparc.data.model.Conversation", {
4040
});
4141

4242
this.__messages = [];
43-
this.__fetchLastMessage();
44-
4543
this.__listenToConversationMessageWS();
44+
45+
if (conversationData.type === "SUPPORT") {
46+
this.__fetchLastMessage();
47+
}
4648
},
4749

4850
statics: {

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ qx.Class.define("osparc.study.Conversation", {
2121

2222
/**
2323
* @param studyData {String} Study Data
24-
* @param conversationId {String} Conversation Id
24+
* @param conversationData {Object} Conversation Data
2525
*/
26-
construct: function(studyData, conversationId) {
26+
construct: function(studyData, conversationData) {
2727
this.base(arguments);
2828

2929
this.__studyData = studyData;
3030
this.__messages = [];
3131

32-
if (conversationId) {
33-
this.setConversationId(conversationId);
32+
if (conversationData) {
33+
const conversation = new osparc.data.model.Conversation(conversationData);
34+
this.setConversation(conversation);
3435
}
3536

3637
this._setLayout(new qx.ui.layout.VBox(5));
@@ -51,11 +52,12 @@ qx.Class.define("osparc.study.Conversation", {
5152
},
5253

5354
properties: {
54-
conversationId: {
55-
check: "String",
55+
conversation: {
56+
check: "osparc.data.model.Conversation",
5657
init: null,
5758
nullable: false,
58-
event: "changeConversationId"
59+
event: "changeConversation",
60+
apply: "__applyConversation",
5961
},
6062
},
6163

@@ -68,6 +70,28 @@ qx.Class.define("osparc.study.Conversation", {
6870
__messagesList: null,
6971
__loadMoreMessages: null,
7072

73+
__applyConversation: function(conversation) {
74+
conversation.addListener("messageAdded", e => {
75+
const message = e.getData();
76+
this.addMessage(message);
77+
}, this);
78+
conversation.addListener("messageUpdated", e => {
79+
const message = e.getData();
80+
this.updateMessage(message);
81+
}, this);
82+
conversation.addListener("messageDeleted", e => {
83+
const message = e.getData();
84+
this.deleteMessage(message);
85+
}, this);
86+
},
87+
88+
getConversationId: function() {
89+
if (this.getConversation()) {
90+
return this.getConversation().getConversationId();
91+
}
92+
return null;
93+
},
94+
7195
__addConversationButtons: function() {
7296
const tabButton = this.getChildControl("button");
7397

@@ -93,7 +117,8 @@ qx.Class.define("osparc.study.Conversation", {
93117
// create new conversation first
94118
osparc.store.ConversationsProject.getInstance().postConversation(this.__studyData["uuid"], newLabel)
95119
.then(data => {
96-
this.setConversationId(data["conversationId"]);
120+
const conversation = new osparc.data.model.Conversation(data);
121+
this.setConversation(conversation);
97122
this.getChildControl("button").setLabel(newLabel);
98123
});
99124
}
@@ -135,7 +160,7 @@ qx.Class.define("osparc.study.Conversation", {
135160
row: 0,
136161
column: 4
137162
});
138-
this.bind("conversationId", closeButton, "visibility", {
163+
this.bind("conversation", closeButton, "visibility", {
139164
converter: value => value ? "visible" : "excluded"
140165
});
141166
},

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,10 @@ qx.Class.define("osparc.study.Conversations", {
127127
socket.on(eventName, eventHandler, this);
128128
this.__wsHandlers.push({ eventName, handler: eventHandler });
129129
});
130-
131-
[
132-
osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_CREATED,
133-
osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_UPDATED,
134-
osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_DELETED,
135-
].forEach(eventName => {
136-
const eventHandler = message => {
137-
if (message) {
138-
const conversationId = message["conversationId"];
139-
const conversationPage = this.__getConversationPage(conversationId);
140-
if (conversationPage) {
141-
switch (eventName) {
142-
case osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_CREATED:
143-
conversationPage.addMessage(message);
144-
break;
145-
case osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_UPDATED:
146-
conversationPage.updateMessage(message);
147-
break;
148-
case osparc.data.model.Conversation.CHANNELS.CONVERSATION_MESSAGE_DELETED:
149-
conversationPage.deleteMessage(message);
150-
break;
151-
}
152-
}
153-
}
154-
};
155-
socket.on(eventName, eventHandler, this);
156-
this.__wsHandlers.push({ eventName, handler: eventHandler });
157-
});
158130
},
159131

160132
__getConversationPage: function(conversationId) {
161-
return this.__conversationsPages.find(conversation => conversation.getConversationId() === conversationId);
133+
return this.__conversationsPages.find(conversationPage => conversationPage.getConversation() && conversationPage.getConversation().getConversationId() === conversationId);
162134
},
163135

164136
__applyStudyData: function(studyData) {
@@ -171,7 +143,7 @@ qx.Class.define("osparc.study.Conversations", {
171143
conversations.forEach(conversation => this.__addConversationPage(conversation));
172144
if (this.__openConversationId) {
173145
const conversationsLayout = this.getChildControl("conversations-layout");
174-
const conversation = conversationsLayout.getSelectables().find(c => c.getConversationId() === this.__openConversationId);
146+
const conversation = conversationsLayout.getSelectables().find(c => c.getConversationId() && c.getConversationId().getConversationId() === this.__openConversationId);
175147
if (conversation) {
176148
conversationsLayout.setSelection([conversation]);
177149
}
@@ -191,9 +163,9 @@ qx.Class.define("osparc.study.Conversations", {
191163
const studyData = this.getStudyData();
192164
let conversationPage = null;
193165
if (conversationData) {
194-
const conversationId = conversationData["conversationId"];
195-
conversationPage = new osparc.study.Conversation(studyData, conversationId);
166+
conversationPage = new osparc.study.Conversation(studyData, conversationData);
196167
conversationPage.setLabel(conversationData["name"]);
168+
const conversationId = conversationData["conversationId"];
197169
osparc.store.ConversationsProject.getInstance().addListener("conversationDeleted", e => {
198170
const data = e.getData();
199171
if (conversationId === data["conversationId"]) {
@@ -233,7 +205,7 @@ qx.Class.define("osparc.study.Conversations", {
233205
const conversationsLayout = this.getChildControl("conversations-layout");
234206
if (conversationsLayout.getChildren().length === 1) {
235207
// remove the temporary conversation page
236-
if (conversationsLayout.getChildren()[0].getConversationId() === null) {
208+
if (conversationsLayout.getChildren()[0].getConversation() === null) {
237209
conversationsLayout.remove(conversationsLayout.getChildren()[0]);
238210
}
239211
}

0 commit comments

Comments
 (0)