-
Notifications
You must be signed in to change notification settings - Fork 32
✨ [Frontend] Conversations: notify users #7916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 48 commits into
ITISFoundation:master
from
odeimaiz:feature/notify-in-conversations
Jun 20, 2025
Merged
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
6391704
notify-user-button
odeimaiz c22c488
notifyUser in store
odeimaiz 4574e36
minor
odeimaiz c90ed7c
Show notification in conversation
odeimaiz 321a9fb
was notified
odeimaiz 42de8d1
bell
odeimaiz cfc3b95
minor
odeimaiz 85b96d1
pass userGid
odeimaiz 9311ee8
accept only one
odeimaiz abd1572
minor
odeimaiz a15bc60
notify works
odeimaiz 049dde1
stack button
odeimaiz 40e63c8
TODOs
odeimaiz 534cbc2
Merge branch 'master' into feature/notify-in-conversations
odeimaiz d4ef75a
first share project
odeimaiz 873b8e0
minor
odeimaiz 932b218
feedback to user
odeimaiz 338ce59
share study
odeimaiz f5a9cae
refactor
odeimaiz 172a4eb
refactor
odeimaiz ea40cc8
minor
odeimaiz 59cc658
improved workflow
odeimaiz 372c55b
renaming
odeimaiz 0ad220d
renaming
odeimaiz 7da1d4c
CONVERSATION_NOTIFICATION
odeimaiz 3271998
minor
odeimaiz 329d3d4
redis notification handling
odeimaiz 98eeca5
Merge branch 'master' into feature/notify-in-conversations
odeimaiz 7ad4728
refactor
odeimaiz a8f0d57
fixes
odeimaiz 3632a67
remove default
odeimaiz f94b968
notification ui
odeimaiz 62d695a
Merge branch 'master' into feature/notify-in-conversations
odeimaiz 72f5e42
only make the needed calls
odeimaiz 84597f0
refactor
odeimaiz d99dac0
Merge branch 'master' into feature/notify-in-conversations
odeimaiz 7482971
Merge branch 'master' into feature/notify-in-conversations
odeimaiz 099551f
rename
odeimaiz 6d03649
conversation folder
odeimaiz e95c9b9
NotificationUI
odeimaiz 296e40b
aesthetics
odeimaiz 6e96949
scroll messages
odeimaiz 692a6db
last fix
odeimaiz 7c9b5c5
openConversations
odeimaiz 7443e2d
minor
odeimaiz ff2b2bc
Merge branch 'master' into feature/notify-in-conversations
odeimaiz 1b974e8
not needed
odeimaiz 3affc7f
minor
odeimaiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
243 changes: 243 additions & 0 deletions
243
services/static-webserver/client/source/class/osparc/conversation/AddMessage.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| /* ************************************************************************ | ||
|
|
||
| osparc - the simcore frontend | ||
|
|
||
| https://osparc.io | ||
|
|
||
| Copyright: | ||
| 2023 IT'IS Foundation, https://itis.swiss | ||
|
|
||
| License: | ||
| MIT: https://opensource.org/licenses/MIT | ||
|
|
||
| Authors: | ||
| * Odei Maiz (odeimaiz) | ||
|
|
||
| ************************************************************************ */ | ||
|
|
||
|
|
||
| qx.Class.define("osparc.conversation.AddMessage", { | ||
| extend: qx.ui.core.Widget, | ||
|
|
||
| /** | ||
| * @param studyData {Object} serialized Study Data | ||
| * @param conversationId {String} Conversation Id | ||
| */ | ||
| construct: function(studyData, conversationId = null) { | ||
| this.base(arguments); | ||
|
|
||
| this.__studyData = studyData; | ||
| this.__conversationId = conversationId; | ||
|
|
||
| this._setLayout(new qx.ui.layout.VBox(5)); | ||
|
|
||
| this.__buildLayout(); | ||
| }, | ||
|
|
||
| events: { | ||
| "commentAdded": "qx.event.type.Event" | ||
| }, | ||
|
|
||
| members: { | ||
| __studyData: null, | ||
| __conversationId: null, | ||
|
|
||
| _createChildControlImpl: function(id) { | ||
| let control; | ||
| switch (id) { | ||
| case "add-comment-label": | ||
| control = new qx.ui.basic.Label().set({ | ||
| value: this.tr("Add comment") | ||
| }); | ||
| this._add(control); | ||
| break; | ||
| case "add-comment-layout": { | ||
| const grid = new qx.ui.layout.Grid(8, 5); | ||
| grid.setColumnWidth(0, 32); | ||
| grid.setColumnFlex(1, 1); | ||
| control = new qx.ui.container.Composite(grid); | ||
| this._add(control, { | ||
| flex: 1 | ||
| }); | ||
| break; | ||
| } | ||
| case "thumbnail": { | ||
| control = new qx.ui.basic.Image().set({ | ||
| alignY: "middle", | ||
| scale: true, | ||
| allowGrowX: true, | ||
| allowGrowY: true, | ||
| allowShrinkX: true, | ||
| allowShrinkY: true, | ||
| maxWidth: 32, | ||
| maxHeight: 32, | ||
| decorator: "rounded", | ||
| }); | ||
| const authData = osparc.auth.Data.getInstance(); | ||
| const myUsername = authData.getUsername(); | ||
| const myEmail = authData.getEmail(); | ||
| control.set({ | ||
| source: osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32) | ||
| }); | ||
| const layout = this.getChildControl("add-comment-layout"); | ||
| layout.add(control, { | ||
| row: 0, | ||
| column: 0 | ||
| }); | ||
| break; | ||
| } | ||
| case "comment-field": | ||
| control = new osparc.editor.MarkdownEditor(); | ||
| control.getChildControl("buttons").exclude(); | ||
| const layout = this.getChildControl("add-comment-layout"); | ||
| layout.add(control, { | ||
| row: 0, | ||
| column: 1 | ||
| }); | ||
| break; | ||
| case "add-comment-button": | ||
| control = new qx.ui.form.Button(this.tr("Add message")).set({ | ||
| appearance: "form-button", | ||
| allowGrowX: false, | ||
| alignX: "right" | ||
| }); | ||
| control.setEnabled(osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])); | ||
| this._add(control); | ||
| break; | ||
| case "notify-user-button": | ||
| control = new qx.ui.form.Button("🔔 " + this.tr("Notify user")).set({ | ||
| appearance: "form-button", | ||
| allowGrowX: false, | ||
| alignX: "right" | ||
| }); | ||
| control.setEnabled(osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])); | ||
| this._add(control); | ||
| break; | ||
| } | ||
|
|
||
| return control || this.base(arguments, id); | ||
| }, | ||
|
|
||
| __buildLayout: function() { | ||
| this.getChildControl("thumbnail"); | ||
| this.getChildControl("comment-field"); | ||
|
|
||
| const addMessageButton = this.getChildControl("add-comment-button"); | ||
| addMessageButton.addListener("execute", () => this.__addComment()); | ||
|
|
||
| const notifyUserButton = this.getChildControl("notify-user-button"); | ||
| notifyUserButton.addListener("execute", () => this.__notifyUserTapped()); | ||
| }, | ||
|
|
||
| __addComment: function() { | ||
| if (this.__conversationId) { | ||
| this.__postMessage(); | ||
| } else { | ||
| // create new conversation first | ||
| osparc.study.Conversations.addConversation(this.__studyData["uuid"]) | ||
| .then(data => { | ||
| this.__conversationId = data["conversationId"]; | ||
| this.__postMessage(); | ||
| }) | ||
| } | ||
| }, | ||
|
|
||
| __notifyUserTapped: function() { | ||
| const showOrganizations = false; | ||
| const showAccessRights = false; | ||
| const userManager = new osparc.share.NewCollaboratorsManager(this.__studyData, showOrganizations, showAccessRights).set({ | ||
| acceptOnlyOne: true, | ||
| }); | ||
| userManager.setCaption(this.tr("Notify user")); | ||
| userManager.getActionButton().setLabel(this.tr("Notify")); | ||
| userManager.addListener("addCollaborators", e => { | ||
| userManager.close(); | ||
| const data = e.getData(); | ||
| const userGids = data["selectedGids"]; | ||
| if (userGids && userGids.length) { | ||
| const userGid = parseInt(userGids[0]); | ||
| this.__notifyUser(userGid); | ||
| } | ||
| }); | ||
| }, | ||
|
|
||
| __notifyUser: function(userGid) { | ||
| // Note! | ||
| // This check only works if the project is directly shared with the user. | ||
| // If it's shared through a group, it might be a bit confusing | ||
| if (userGid in this.__studyData["accessRights"]) { | ||
| this.__addNotify(userGid); | ||
| } else { | ||
| const msg = this.tr("This user has no access to the project. Do you want to share it?"); | ||
| const win = new osparc.ui.window.Confirmation(msg).set({ | ||
| caption: this.tr("Share"), | ||
| confirmText: this.tr("Share"), | ||
| confirmAction: "create" | ||
| }); | ||
| win.center(); | ||
| win.open(); | ||
| win.addListener("close", () => { | ||
| if (win.getConfirmed()) { | ||
| const newCollaborators = { | ||
| [userGid]: osparc.data.Roles.STUDY["write"].accessRights | ||
| }; | ||
| osparc.store.Study.addCollaborators(this.__studyData, newCollaborators) | ||
| .then(() => { | ||
| this.__addNotify(userGid); | ||
| const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() | ||
| if (userGid in potentialCollaborators && "getUserId" in potentialCollaborators[userGid]) { | ||
| const uid = potentialCollaborators[userGid].getUserId(); | ||
| osparc.notification.Notifications.pushStudyShared(uid, this.__studyData["uuid"]); | ||
| } | ||
| }) | ||
| .catch(err => osparc.FlashMessenger.logError(err)); | ||
| } | ||
| }, this); | ||
| } | ||
| }, | ||
|
|
||
| __addNotify: function(userGid) { | ||
| if (this.__conversationId) { | ||
| this.__postNotify(userGid); | ||
| } else { | ||
| // create new conversation first | ||
| osparc.study.Conversations.addConversation(this.__studyData["uuid"]) | ||
| .then(data => { | ||
| this.__conversationId = data["conversationId"]; | ||
| this.__postNotify(userGid); | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| __postMessage: function() { | ||
| const commentField = this.getChildControl("comment-field"); | ||
| const comment = commentField.getChildControl("text-area").getValue(); | ||
| if (comment) { | ||
| osparc.study.Conversations.addMessage(this.__studyData["uuid"], this.__conversationId, comment) | ||
| .then(data => { | ||
| this.fireDataEvent("commentAdded", data); | ||
| commentField.getChildControl("text-area").setValue(""); | ||
| osparc.FlashMessenger.logAs(this.tr("Message added"), "INFO"); | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| __postNotify: function(userGid) { | ||
| if (userGid) { | ||
| osparc.study.Conversations.notifyUser(this.__studyData["uuid"], this.__conversationId, userGid) | ||
| .then(data => { | ||
| this.fireDataEvent("commentAdded", data); | ||
| const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); | ||
| if (userGid in potentialCollaborators) { | ||
| if ("getUserId" in potentialCollaborators[userGid]) { | ||
| const uid = potentialCollaborators[userGid].getUserId(); | ||
| osparc.notification.Notifications.pushConversationNotification(uid, this.__studyData["uuid"]); | ||
| } | ||
| const msg = "getLabel" in potentialCollaborators[userGid] ? potentialCollaborators[userGid].getLabel() + this.tr(" was notified") : this.tr("Notification sent"); | ||
| osparc.FlashMessenger.logAs(msg, "INFO"); | ||
| } | ||
| }); | ||
| } | ||
| }, | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.