Skip to content

Commit 4d1e24e

Browse files
authored
Merge branch 'develop' into ClipboardPaste
2 parents 4f0811b + d18e390 commit 4d1e24e

41 files changed

Lines changed: 1967 additions & 441 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/api/rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import dts from 'rollup-plugin-dts'
22
import esbuild from 'rollup-plugin-esbuild'
3-
import packageJson from './package.json' assert { type: 'json' };
43
import path from 'path';
4+
import { createRequire } from 'module';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
const require = createRequire(import.meta.url);
10+
const packageJson = require(path.resolve(__dirname, './package.json'));
511

612
const name = packageJson.main.replace(/\.js$/, '');
713

packages/api/src/EmbeddedChatApi.ts

Lines changed: 77 additions & 66 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
}
@@ -632,7 +611,7 @@ export default class EmbeddedChatApi {
632611
try {
633612
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
634613
const messages = await fetch(
635-
`${this.host}/api/v1/chat.getThreadMessages?roomId=${this.rid}&tmid=${tmid}`,
614+
`${this.host}/api/v1/chat.getThreadMessages?tmid=${tmid}`,
636615
{
637616
headers: {
638617
"Content-Type": "application/json",
@@ -693,22 +672,14 @@ export default class EmbeddedChatApi {
693672
try {
694673
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
695674
const response = await fetch(
696-
`${this.host}/api/v1/method.call/getUserRoles`,
675+
`${this.host}/api/v1/roles.getUsersInPublicRoles`,
697676
{
698-
body: JSON.stringify({
699-
message: JSON.stringify({
700-
msg: "method",
701-
id: null,
702-
method: "getUserRoles",
703-
params: [],
704-
}),
705-
}),
706677
headers: {
707678
"Content-Type": "application/json",
708679
"X-Auth-Token": authToken,
709680
"X-User-Id": userId,
710681
},
711-
method: "POST",
682+
method: "GET",
712683
}
713684
);
714685

@@ -776,7 +747,7 @@ export default class EmbeddedChatApi {
776747
try {
777748
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
778749
const response = await fetch(`${this.host}/api/v1/chat.delete`, {
779-
body: `{"roomId": "${this.rid}", "msgId": "${msgId}"}`,
750+
body: JSON.stringify({ roomId: this.rid, msgId }),
780751
headers: {
781752
"Content-Type": "application/json",
782753
"X-Auth-Token": authToken,
@@ -794,7 +765,7 @@ export default class EmbeddedChatApi {
794765
try {
795766
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
796767
const response = await fetch(`${this.host}/api/v1/chat.update`, {
797-
body: `{"roomId": "${this.rid}", "msgId": "${msgId}","text" : "${text}" }`,
768+
body: JSON.stringify({ roomId: this.rid, msgId, text }),
798769
headers: {
799770
"Content-Type": "application/json",
800771
"X-Auth-Token": authToken,
@@ -854,7 +825,7 @@ export default class EmbeddedChatApi {
854825
try {
855826
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
856827
const response = await fetch(`${this.host}/api/v1/chat.starMessage`, {
857-
body: `{"messageId": "${mid}"}`,
828+
body: JSON.stringify({ messageId: mid }),
858829
headers: {
859830
"Content-Type": "application/json",
860831
"X-Auth-Token": authToken,
@@ -872,7 +843,7 @@ export default class EmbeddedChatApi {
872843
try {
873844
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
874845
const response = await fetch(`${this.host}/api/v1/chat.unStarMessage`, {
875-
body: `{"messageId": "${mid}"}`,
846+
body: JSON.stringify({ messageId: mid }),
876847
headers: {
877848
"Content-Type": "application/json",
878849
"X-Auth-Token": authToken,
@@ -950,7 +921,7 @@ export default class EmbeddedChatApi {
950921
try {
951922
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
952923
const response = await fetch(`${this.host}/api/v1/chat.pinMessage`, {
953-
body: `{"messageId": "${mid}"}`,
924+
body: JSON.stringify({ messageId: mid }),
954925
headers: {
955926
"Content-Type": "application/json",
956927
"X-Auth-Token": authToken,
@@ -970,7 +941,7 @@ export default class EmbeddedChatApi {
970941
try {
971942
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
972943
const response = await fetch(`${this.host}/api/v1/chat.unPinMessage`, {
973-
body: `{"messageId": "${mid}"}`,
944+
body: JSON.stringify({ messageId: mid }),
974945
headers: {
975946
"Content-Type": "application/json",
976947
"X-Auth-Token": authToken,
@@ -988,7 +959,11 @@ export default class EmbeddedChatApi {
988959
try {
989960
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
990961
const response = await fetch(`${this.host}/api/v1/chat.react`, {
991-
body: `{"messageId": "${messageId}", "emoji": "${emoji}", "shouldReact": ${shouldReact}}`,
962+
body: JSON.stringify({
963+
messageId,
964+
emoji,
965+
shouldReact,
966+
}),
992967
headers: {
993968
"Content-Type": "application/json",
994969
"X-Auth-Token": authToken,
@@ -1006,7 +981,7 @@ export default class EmbeddedChatApi {
1006981
try {
1007982
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
1008983
const response = await fetch(`${this.host}/api/v1/chat.reportMessage`, {
1009-
body: `{"messageId": "${messageId}", "description": "${description}"}`,
984+
body: JSON.stringify({ messageId, description }),
1010985
headers: {
1011986
"Content-Type": "application/json",
1012987
"X-Auth-Token": authToken,
@@ -1046,26 +1021,53 @@ export default class EmbeddedChatApi {
10461021
) {
10471022
try {
10481023
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
1049-
const form = new FormData();
1050-
if (threadId) {
1051-
form.append("tmid", threadId);
1024+
if (!userId || !authToken) {
1025+
console.error("sendAttachment: User not authenticated");
1026+
return;
10521027
}
1028+
1029+
const form = new FormData();
10531030
form.append("file", file, fileName);
1054-
form.append(
1055-
"description",
1056-
fileDescription.length !== 0 ? fileDescription : ""
1031+
1032+
const uploadResponse = await fetch(
1033+
`${this.host}/api/v1/rooms.media/${this.rid}`,
1034+
{
1035+
method: "POST",
1036+
body: form,
1037+
headers: {
1038+
"X-Auth-Token": authToken,
1039+
"X-User-Id": userId,
1040+
},
1041+
}
10571042
);
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;
1043+
1044+
const uploadResult = await uploadResponse.json();
1045+
1046+
if (!uploadResult.success || !uploadResult.file?._id) {
1047+
console.error("sendAttachment: Upload failed", uploadResult);
1048+
return uploadResult;
1049+
}
1050+
1051+
const confirmResponse = await fetch(
1052+
`${this.host}/api/v1/rooms.mediaConfirm/${this.rid}/${uploadResult.file._id}`,
1053+
{
1054+
method: "POST",
1055+
headers: {
1056+
"Content-Type": "application/json",
1057+
"X-Auth-Token": authToken,
1058+
"X-User-Id": userId,
1059+
},
1060+
body: JSON.stringify(
1061+
threadId
1062+
? { msg: "", description: fileDescription || "", tmid: threadId }
1063+
: { msg: "", description: fileDescription || "" }
1064+
),
1065+
}
1066+
);
1067+
1068+
return await confirmResponse.json();
10671069
} catch (err) {
1068-
console.log(err);
1070+
console.error("sendAttachment error:", err);
10691071
}
10701072
}
10711073

@@ -1191,7 +1193,15 @@ export default class EmbeddedChatApi {
11911193
return data;
11921194
}
11931195

1194-
async execCommand({ command, params }: { command: string; params: string }) {
1196+
async execCommand({
1197+
command,
1198+
params,
1199+
tmid,
1200+
}: {
1201+
command: string;
1202+
params: string;
1203+
tmid?: string;
1204+
}) {
11951205
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
11961206
const response = await fetch(`${this.host}/api/v1/commands.run`, {
11971207
headers: {
@@ -1203,6 +1213,7 @@ export default class EmbeddedChatApi {
12031213
body: JSON.stringify({
12041214
command,
12051215
params,
1216+
tmid,
12061217
roomId: this.rid,
12071218
triggerId: Math.random().toString(32).slice(2, 20),
12081219
}),

packages/auth/rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import dts from 'rollup-plugin-dts'
22
import esbuild from 'rollup-plugin-esbuild'
33
import path from 'path';
4-
import packageJson from './package.json' assert { type: 'json' };
4+
import { createRequire } from 'module';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
const require = createRequire(import.meta.url);
10+
const packageJson = require(path.resolve(__dirname, './package.json'));
511

612
const name = packageJson.main.replace(/\.js$/, '');
713

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 } =

0 commit comments

Comments
 (0)