Skip to content

Commit

Permalink
[mattermostGH-300]: Fixed the JS error while posting meeting link to …
Browse files Browse the repository at this point in the history
…thread view (mattermost#307)

* [MI-3560]: Fixed the JS error while posting meeting link to thread issue mattermost#300 (#7)

* [MI-3560]: Fixed the issue mattermost#300

* [MI-3560]: Removed extra packages

* [MI-3560]: Reverted the changes of package-lock.json

* [MM-00]: Review fixes.

---------

Co-authored-by: Abhishek Verma <abhishek.verma@brightscout.com>
  • Loading branch information
Kshitij-Katiyar and avas27JTG authored Oct 27, 2023
1 parent cd9bb0b commit f50692b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
3 changes: 2 additions & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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,
Expand All @@ -55,6 +55,7 @@ export function startMeeting(channelId, force = false, topic = '') {
type: PostTypes.RECEIVED_NEW_POST,
data: post,
channelId,
rootId,
});

return {error};
Expand Down
29 changes: 27 additions & 2 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand All @@ -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,
});
};
13 changes: 11 additions & 2 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down

0 comments on commit f50692b

Please sign in to comment.