diff --git a/server/http.go b/server/http.go index 42b07135..6850ce65 100644 --- a/server/http.go +++ b/server/http.go @@ -45,6 +45,7 @@ const ( type startMeetingRequest struct { ChannelID string `json:"channel_id"` + RootID string `json:"root_id"` Personal bool `json:"personal"` Topic string `json:"topic"` MeetingID int `json:"meeting_id"` @@ -496,7 +497,7 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) { if _, err := w.Write([]byte(`{"meeting_url": ""}`)); err != nil { p.API.LogWarn("failed to write the response", "error", err.Error()) } - p.postConfirm(recentMeetingLink, req.ChannelID, req.Topic, userID, "", creatorName, provider) + p.postConfirm(recentMeetingLink, req.ChannelID, req.Topic, userID, req.RootID, creatorName, provider) return } } diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index 3d890725..5a713c3e 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -5,7 +5,7 @@ import {PostTypes} from 'mattermost-redux/action_types'; import Client from '../client'; -export function startMeeting(channelId, force = false, topic = '') { +export function startMeeting(channelId, rootId, force = false, topic = '') { return async (dispatch, getState) => { try { let meetingURL = ''; @@ -41,7 +41,7 @@ export function startMeeting(channelId, force = false, topic = '') { is_pinned: false, user_id: getState().entities.users.currentUserId, channel_id: channelId, - root_id: '', + root_id: rootId, parent_id: '', original_id: '', message: m, @@ -55,6 +55,7 @@ export function startMeeting(channelId, force = false, topic = '') { type: PostTypes.RECEIVED_NEW_POST, data: post, channelId, + rootId, }); return {error}; diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index f52aea6c..1d0ddab1 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -23,10 +23,15 @@ export default class Client { return res.meeting_url; } - forceStartMeeting = async (channelId, personal = true, topic = '', meetingId = 0) => { - const meetingUrl = await this.startMeeting(channelId, personal, topic, meetingId, true); + forceStartMeeting = async (channelId, rootId, personal = true, topic = '', meetingId = 0) => { + const meetingUrl = await this.startMeeting(channelId, rootId, personal, topic, meetingId, true); return meetingUrl; } + + getChannelIdForThread = async (baseURL, threadId) => { + const threadDetails = await doGet(`${baseURL}/api/v4/posts/${threadId}/thread`); + return threadDetails.posts[threadId].channel_id; + } } export const doPost = async (url, body, headers = {}) => { @@ -49,3 +54,23 @@ export const doPost = async (url, body, headers = {}) => { url, }); }; + +export const doGet = async (url) => { + const options = { + method: 'get', + }; + + const response = await fetch(url, Client4.getOptions(options)); + + if (response.ok) { + return response.json(); + } + + const text = await response.text(); + + throw new ClientError(Client4.url, { + message: text || '', + status_code: response.status, + url, + }); +}; diff --git a/webapp/src/index.js b/webapp/src/index.js index c126f1b2..ff70a981 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -27,8 +27,17 @@ class Plugin { const iconURL = getPluginURL(store.getState()) + '/public/app-bar-icon.png'; registry.registerAppBarComponent( iconURL, - (channel) => { - startMeeting(channel.id)(store.dispatch, store.getState); + async (channel) => { + if (channel) { + startMeeting(channel.id, '')(store.dispatch, store.getState); + } else { + const state = store.getState(); + const teamId = state?.entities.teams.currentTeamId; + const threadId = state?.views.threads.selectedThreadIdInTeam[teamId]; + const baseURL = state?.entities.general.config.SiteURL; + const channelId = await Client.getChannelIdForThread(baseURL, threadId); + startMeeting(channelId, threadId)(store.dispatch, store.getState); + } }, 'Start Zoom Meeting', );