@@ -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 } ) ,
0 commit comments