Skip to content

Commit dc68413

Browse files
authored
Merge branch 'develop' into fix/auth-and-rendering-bugs
2 parents 9ce07cd + e1a4d84 commit dc68413

29 files changed

+1466
-310
lines changed

packages/api/src/EmbeddedChatApi.ts

Lines changed: 69 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ export default class EmbeddedChatApi {
414414

415415
if (suggestedUsername.success) {
416416
const response2 = await fetch(`${this.host}/api/v1/users.update`, {
417-
body: `{"userId": "${userid}", "data": { "username": "${suggestedUsername.result}" }}`,
417+
body: JSON.stringify({
418+
userId: userid,
419+
data: { username: suggestedUsername.result },
420+
}),
418421
headers: {
419422
"Content-Type": "application/json",
420423
"X-Auth-Token": authToken,
@@ -439,7 +442,10 @@ export default class EmbeddedChatApi {
439442
try {
440443
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
441444
const response = await fetch(`${this.host}/api/v1/users.update`, {
442-
body: `{"userId": "${userid}", "data": { "username": "${newUserName}" }}`,
445+
body: JSON.stringify({
446+
userId: userid,
447+
data: { username: newUserName },
448+
}),
443449
headers: {
444450
"Content-Type": "application/json",
445451
"X-Auth-Token": authToken,
@@ -487,34 +493,7 @@ export default class EmbeddedChatApi {
487493

488494
async getRoomInfo() {
489495
try {
490-
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
491-
const response = await fetch(
492-
`${this.host}/api/v1/method.call/rooms%3Aget`,
493-
{
494-
body: JSON.stringify({
495-
message: JSON.stringify({
496-
msg: "method",
497-
id: null,
498-
method: "rooms/get",
499-
params: [],
500-
}),
501-
}),
502-
headers: {
503-
"Content-Type": "application/json",
504-
"X-Auth-Token": authToken,
505-
"X-User-Id": userId,
506-
},
507-
method: "POST",
508-
}
509-
);
510-
511-
const result = await response.json();
512-
513-
if (result.success && result.message) {
514-
const parsedMessage = JSON.parse(result.message);
515-
return parsedMessage;
516-
}
517-
return null;
496+
return await this.channelInfo();
518497
} catch (err) {
519498
console.error(err);
520499
}
@@ -691,36 +670,14 @@ export default class EmbeddedChatApi {
691670

692671
async getUserRoles() {
693672
try {
694-
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
695-
const response = await fetch(
696-
`${this.host}/api/v1/method.call/getUserRoles`,
697-
{
698-
body: JSON.stringify({
699-
message: JSON.stringify({
700-
msg: "method",
701-
id: null,
702-
method: "getUserRoles",
703-
params: [],
704-
}),
705-
}),
706-
headers: {
707-
"Content-Type": "application/json",
708-
"X-Auth-Token": authToken,
709-
"X-User-Id": userId,
710-
},
711-
method: "POST",
712-
}
713-
);
714-
715-
const result = await response.json();
716-
717-
if (result.success && result.message) {
718-
const parsedMessage = JSON.parse(result.message);
719-
return parsedMessage;
673+
const response = await this.getUsersInRole("admin");
674+
if (response && response.success) {
675+
return { result: response.users };
720676
}
721-
return null;
677+
return { result: [] };
722678
} catch (err) {
723679
console.error(err);
680+
return { result: [] };
724681
}
725682
}
726683

@@ -776,7 +733,7 @@ export default class EmbeddedChatApi {
776733
try {
777734
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
778735
const response = await fetch(`${this.host}/api/v1/chat.delete`, {
779-
body: `{"roomId": "${this.rid}", "msgId": "${msgId}"}`,
736+
body: JSON.stringify({ roomId: this.rid, msgId }),
780737
headers: {
781738
"Content-Type": "application/json",
782739
"X-Auth-Token": authToken,
@@ -794,7 +751,7 @@ export default class EmbeddedChatApi {
794751
try {
795752
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
796753
const response = await fetch(`${this.host}/api/v1/chat.update`, {
797-
body: `{"roomId": "${this.rid}", "msgId": "${msgId}","text" : "${text}" }`,
754+
body: JSON.stringify({ roomId: this.rid, msgId, text }),
798755
headers: {
799756
"Content-Type": "application/json",
800757
"X-Auth-Token": authToken,
@@ -854,7 +811,7 @@ export default class EmbeddedChatApi {
854811
try {
855812
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
856813
const response = await fetch(`${this.host}/api/v1/chat.starMessage`, {
857-
body: `{"messageId": "${mid}"}`,
814+
body: JSON.stringify({ messageId: mid }),
858815
headers: {
859816
"Content-Type": "application/json",
860817
"X-Auth-Token": authToken,
@@ -872,7 +829,7 @@ export default class EmbeddedChatApi {
872829
try {
873830
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
874831
const response = await fetch(`${this.host}/api/v1/chat.unStarMessage`, {
875-
body: `{"messageId": "${mid}"}`,
832+
body: JSON.stringify({ messageId: mid }),
876833
headers: {
877834
"Content-Type": "application/json",
878835
"X-Auth-Token": authToken,
@@ -950,7 +907,7 @@ export default class EmbeddedChatApi {
950907
try {
951908
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
952909
const response = await fetch(`${this.host}/api/v1/chat.pinMessage`, {
953-
body: `{"messageId": "${mid}"}`,
910+
body: JSON.stringify({ messageId: mid }),
954911
headers: {
955912
"Content-Type": "application/json",
956913
"X-Auth-Token": authToken,
@@ -970,7 +927,7 @@ export default class EmbeddedChatApi {
970927
try {
971928
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
972929
const response = await fetch(`${this.host}/api/v1/chat.unPinMessage`, {
973-
body: `{"messageId": "${mid}"}`,
930+
body: JSON.stringify({ messageId: mid }),
974931
headers: {
975932
"Content-Type": "application/json",
976933
"X-Auth-Token": authToken,
@@ -988,7 +945,11 @@ export default class EmbeddedChatApi {
988945
try {
989946
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
990947
const response = await fetch(`${this.host}/api/v1/chat.react`, {
991-
body: `{"messageId": "${messageId}", "emoji": "${emoji}", "shouldReact": ${shouldReact}}`,
948+
body: JSON.stringify({
949+
messageId,
950+
emoji,
951+
shouldReact,
952+
}),
992953
headers: {
993954
"Content-Type": "application/json",
994955
"X-Auth-Token": authToken,
@@ -1006,7 +967,7 @@ export default class EmbeddedChatApi {
1006967
try {
1007968
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
1008969
const response = await fetch(`${this.host}/api/v1/chat.reportMessage`, {
1009-
body: `{"messageId": "${messageId}", "description": "${description}"}`,
970+
body: JSON.stringify({ messageId, description }),
1010971
headers: {
1011972
"Content-Type": "application/json",
1012973
"X-Auth-Token": authToken,
@@ -1046,26 +1007,53 @@ export default class EmbeddedChatApi {
10461007
) {
10471008
try {
10481009
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
1049-
const form = new FormData();
1050-
if (threadId) {
1051-
form.append("tmid", threadId);
1010+
if (!userId || !authToken) {
1011+
console.error("sendAttachment: User not authenticated");
1012+
return;
10521013
}
1014+
1015+
const form = new FormData();
10531016
form.append("file", file, fileName);
1054-
form.append(
1055-
"description",
1056-
fileDescription.length !== 0 ? fileDescription : ""
1017+
1018+
const uploadResponse = await fetch(
1019+
`${this.host}/api/v1/rooms.media/${this.rid}`,
1020+
{
1021+
method: "POST",
1022+
body: form,
1023+
headers: {
1024+
"X-Auth-Token": authToken,
1025+
"X-User-Id": userId,
1026+
},
1027+
}
10571028
);
1058-
const response = fetch(`${this.host}/api/v1/rooms.upload/${this.rid}`, {
1059-
method: "POST",
1060-
body: form,
1061-
headers: {
1062-
"X-Auth-Token": authToken,
1063-
"X-User-Id": userId,
1064-
},
1065-
}).then((r) => r.json());
1066-
return response;
1029+
1030+
const uploadResult = await uploadResponse.json();
1031+
1032+
if (!uploadResult.success || !uploadResult.file?._id) {
1033+
console.error("sendAttachment: Upload failed", uploadResult);
1034+
return uploadResult;
1035+
}
1036+
1037+
const confirmResponse = await fetch(
1038+
`${this.host}/api/v1/rooms.mediaConfirm/${this.rid}/${uploadResult.file._id}`,
1039+
{
1040+
method: "POST",
1041+
headers: {
1042+
"Content-Type": "application/json",
1043+
"X-Auth-Token": authToken,
1044+
"X-User-Id": userId,
1045+
},
1046+
body: JSON.stringify(
1047+
threadId
1048+
? { msg: "", description: fileDescription || "", tmid: threadId }
1049+
: { msg: "", description: fileDescription || "" }
1050+
),
1051+
}
1052+
);
1053+
1054+
return await confirmResponse.json();
10671055
} catch (err) {
1068-
console.log(err);
1056+
console.error("sendAttachment error:", err);
10691057
}
10701058
}
10711059

packages/auth/src/loginWithRocketChatOAuth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ width=800,height=600,left=-1000,top=-1000,rel=opener`;
4545
return new Promise<any>((resolve) => {
4646
if (popup) {
4747
const onMessage = async (e: MessageEvent) => {
48+
if (e.origin !== new URL(config.api.baseUrl).origin) {
49+
return;
50+
}
4851
if (e.data.type === "rc-oauth-callback") {
4952
const { accessToken, expiresIn, serviceName } = e.data.credentials;
5053
const response = await config.api.post("/api/v1/login", {

packages/layout_editor/src/components/SurfaceMenu/SurfaceItem.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const SurfaceItem = ({
1818
onRemove,
1919
type,
2020
cursor = 'grab',
21-
tooltipPosition = 'bottom',
21+
tooltipPosition = 'top',
2222
size,
2323
}) => {
2424
const { attributes, listeners, setNodeRef, transform, isDragging } =

packages/react/src/hooks/useDropBox.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ const useDropBox = () => {
1515
setData(e.dataTransfer.files[0]);
1616
};
1717

18+
const handlePaste = (file) => {
19+
toggle();
20+
setData(file);
21+
};
22+
1823
return {
1924
data,
2025
handleDrag,
2126
handleDragDrop,
27+
handlePaste,
2228
};
2329
};
2430

packages/react/src/hooks/useMediaRecorder.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,29 @@ export function useMediaRecorder({ constraints, onStop, videoRef }) {
2828
const stream = await getStream(constraints, true);
2929
chunks.current = [];
3030
const _recorder = new MediaRecorder(stream);
31-
_recorder.start();
32-
setRecorder(_recorder);
33-
_recorder.addEventListener('dataavailable', (event) => {
31+
32+
const handleDataAvailable = (event) => {
3433
chunks.current.push(event.data);
35-
});
36-
_recorder.addEventListener('stop', () => {
34+
};
35+
36+
const handleStop = () => {
3737
onStop && onStop(chunks.current);
38-
});
38+
_recorder.removeEventListener('dataavailable', handleDataAvailable);
39+
_recorder.removeEventListener('stop', handleStop);
40+
};
41+
42+
_recorder.addEventListener('dataavailable', handleDataAvailable);
43+
_recorder.addEventListener('stop', handleStop);
44+
45+
_recorder.start();
46+
setRecorder(_recorder);
3947
}
4048

4149
async function stop() {
4250
if (recorder) {
43-
recorder.stop();
51+
if (recorder.state !== 'inactive') {
52+
recorder.stop();
53+
}
4454
(await getStream()).getTracks().forEach((track) => track.stop());
4555
}
4656
}
@@ -77,17 +87,23 @@ export function useNewMediaRecorder({ constraints, videoRef, onStop }) {
7787

7888
chunks.current = [];
7989
const _recorder = new MediaRecorder(stream);
80-
_recorder.start();
81-
setRecorder(_recorder);
8290

83-
_recorder.addEventListener('dataavailable', (event) => {
91+
const handleDataAvailable = (event) => {
8492
chunks.current.push(event.data);
85-
});
93+
};
8694

87-
_recorder.addEventListener('stop', () => {
95+
const handleStop = () => {
8896
setRecordingData(new Blob(chunks.current, { type: 'video/mp4' }));
8997
onStop && onStop(chunks.current);
90-
});
98+
_recorder.removeEventListener('dataavailable', handleDataAvailable);
99+
_recorder.removeEventListener('stop', handleStop);
100+
};
101+
102+
_recorder.addEventListener('dataavailable', handleDataAvailable);
103+
_recorder.addEventListener('stop', handleStop);
104+
105+
_recorder.start();
106+
setRecorder(_recorder);
91107
}
92108

93109
async function stopRecording() {

packages/react/src/hooks/useRCAuth.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ export const useRCAuth = () => {
6363
}
6464
}
6565
} catch (e) {
66-
console.error('A error occurred while setting up user', e);
66+
console.error('An error occurred while setting up user', e);
67+
dispatchToastMessage({
68+
type: 'error',
69+
message:
70+
'Unable to connect to server. Please check your connection and try again.',
71+
});
6772
}
6873
};
6974

0 commit comments

Comments
 (0)