Skip to content

Commit

Permalink
[MM-343] Updated meeting flow for new users. (#344)
Browse files Browse the repository at this point in the history
* [MM-257] Updated meeting flow for new users.
- User will get a post to select the default meeting ID when they try to start a meeting for the first time.

* [MM-269] Added logic to automaticallly open the meeting

* Added EOF

* [MM-269] Review fixes

* {MM-269] Review fix

* [MM-289] Fix lint errors

* [MM-343] Update successfull connection post and fix flaky test

---------

Co-authored-by: ayusht2810 <ayush.thakur@brightscout.com>
  • Loading branch information
raghavaggarwal2308 and ayusht2810 authored Apr 15, 2024
1 parent 755ac01 commit 3206b7c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 31 deletions.
14 changes: 7 additions & 7 deletions build/pluginctl/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ func TestFilterLogEntries(t *testing.T) {
},
"filter out old entries": {
logs: []string{
fmt.Sprintf(`{"message":"old2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(-2*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"old1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(-1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"now", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(2*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"old2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(-2*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"old1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(-1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"now", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(2*time.Second).Format(timeStampFormat)),
},
pluginID: "some.plugin.id",
since: now,
expectedLogs: []string{
fmt.Sprintf(`{"message":"new1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, time.Now().Add(2*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new1", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(1*time.Second).Format(timeStampFormat)),
fmt.Sprintf(`{"message":"new2", "plugin_id": "some.plugin.id", "timestamp": "%s"}`, now.Add(2*time.Second).Format(timeStampFormat)),
},
expectedErr: false,
},
Expand Down
93 changes: 69 additions & 24 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ import (
)

const (
defaultMeetingTopic = "Zoom Meeting"
zoomOAuthUserStateLength = 4
settingDataError = "something went wrong while getting settings data"
zoomSettingsCommandMessage = "You can set a default value for this in your user settings via `/zoom settings` command."
askForMeetingType = "Which meeting ID would you like to use for creating this meeting?"
pathWebhook = "/webhook"
pathStartMeeting = "/api/v1/meetings"
pathConnectUser = "/oauth2/connect"
pathCompleteUserOAuth = "/oauth2/complete"
pathDeauthorizeUser = "/deauthorization"
pathUpdatePMI = "/api/v1/updatePMI"
pathAskPMI = "/api/v1/askPMI"
yes = "Yes"
no = "No"
ask = "Ask"
actionForContext = "action"
userIDForContext = "userID"
channelIDForContext = "channelID"
rootIDForContext = "rootID"
usePersonalMeetingID = "Use Personal Meeting ID"
useAUniqueMeetingID = "Use a Unique Meeting ID"
MattermostUserIDHeader = "Mattermost-User-ID"
defaultMeetingTopic = "Zoom Meeting"
zoomOAuthUserStateLength = 4
settingDataError = "something went wrong while getting settings data"
zoomSettingsCommandMessage = "You can set a default value for this in your user settings via `/zoom settings` command."
askForMeetingType = "Which meeting ID would you like to use for creating this meeting?"
pathWebhook = "/webhook"
pathStartMeeting = "/api/v1/meetings"
pathConnectUser = "/oauth2/connect"
pathCompleteUserOAuth = "/oauth2/complete"
pathDeauthorizeUser = "/deauthorization"
pathUpdatePMI = "/api/v1/updatePMI"
pathAskPMI = "/api/v1/askPMI"
yes = "Yes"
no = "No"
ask = "Ask"
actionForContext = "action"
userIDForContext = "userID"
channelIDForContext = "channelID"
rootIDForContext = "rootID"
usePersonalMeetingID = "Use Personal Meeting ID"
useAUniqueMeetingID = "Use a Unique Meeting ID"
MattermostUserIDHeader = "Mattermost-User-ID"
WebsocketEventMeetingStarted = "meeting_started"
)

type startMeetingRequest struct {
Expand Down Expand Up @@ -101,6 +102,30 @@ func (p *Plugin) submitFormPMIForMeeting(w http.ResponseWriter, r *http.Request)
Text: fmt.Sprintf("You have selected `%s` to start the meeting.", action),
}

userPMISettingPref, err := p.getPMISettingData(userID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if userPMISettingPref == "" {
val := trueString
meetingIDType := "personal"
if action == useAUniqueMeetingID {
val = falseString
meetingIDType = "unique"
}

if err := p.updateUserPersonalSettings(val, userID); err != nil {
p.API.LogWarn("failed to update preferences for the user", "Error", err.Error())
return
}

slackAttachment = model.SlackAttachment{
Text: fmt.Sprintf("All future meetings will use `%s` meeting ID. Type `/zoom settings` to change your meeting ID preference", meetingIDType),
}
}

post := &model.Post{
ChannelId: channelID,
UserId: p.botUserID,
Expand Down Expand Up @@ -331,7 +356,7 @@ func (p *Plugin) completeUserOAuthToZoom(w http.ResponseWriter, r *http.Request)
p.trackConnect(userID)

if justConnect {
p.postEphemeral(userID, channelID, "", "Successfully connected to Zoom \nType `/zoom settings` to change your meeting ID preference")
p.postEphemeral(userID, channelID, "", "Successfully connected to Zoom")
} else {
meeting, err := client.CreateMeeting(zoomUser, defaultMeetingTopic)
if err != nil {
Expand Down Expand Up @@ -410,14 +435,34 @@ func (p *Plugin) postMeeting(creator *model.User, meetingID int, channelID strin
if appErr = p.storeMeetingPostID(meetingID, createdPost.Id); appErr != nil {
p.API.LogDebug("failed to store post id", "error", appErr)
}

p.client.Frontend.PublishWebSocketEvent(
WebsocketEventMeetingStarted,
map[string]interface{}{
"meeting_url": meetingURL,
},
&model.WebsocketBroadcast{UserId: creator.Id},
)

return nil
}

func (p *Plugin) askPreferenceForMeeting(userID, channelID, rootID string) {
apiEndPoint := fmt.Sprintf("/plugins/%s%s", manifest.Id, pathAskPMI)

userPMISettingPref, err := p.getPMISettingData(userID)
if err != nil {
p.API.LogDebug("failed to get user PMI setting value", "userID", userID, "error", err)
return
}

pretext := zoomSettingsCommandMessage
if userPMISettingPref == "" {
pretext = ""
}

slackAttachment := model.SlackAttachment{
Pretext: zoomSettingsCommandMessage,
Pretext: pretext,
Title: askForMeetingType,
Actions: []*model.PostAction{
{
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PostTypeZoom from './components/post_type_zoom';
import {startMeeting} from './actions';
import Client from './client';
import {getPluginURL, getServerRoute} from './selectors';
import {handleMeetingStarted} from './websocket/index.ts';

class Plugin {
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -43,6 +44,11 @@ class Plugin {
);
}

registry.registerWebSocketEventHandler(
`custom_${manifest.id}_meeting_started`,
handleMeetingStarted,
);

registry.registerPostTypeComponent('custom_zoom', PostTypeZoom);
Client.setServerRoute(getServerRoute(store.getState()));
}
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/websocket/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function handleMeetingStarted(msg: {data: {meeting_url: string}}) {
window.open(msg.data.meeting_url);
}

0 comments on commit 3206b7c

Please sign in to comment.