Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/rooms.info?roomId=${this.rid}`,
`${this.host}/api/v1/rooms.info?roomId=${encodeURIComponent(this.rid)}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -569,15 +569,17 @@ export default class EmbeddedChatApi {
const roomType = isChannelPrivate ? "groups" : "channels";
const endp = anonymousMode ? "anonymousread" : "messages";
const query = options?.query
? `&query=${JSON.stringify(options.query)}`
? `&query=${encodeURIComponent(JSON.stringify(options.query))}`
: "";
const field = options?.field
? `&field=${JSON.stringify(options.field)}`
? `&field=${encodeURIComponent(JSON.stringify(options.field))}`
: "";
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const messages = await fetch(
`${this.host}/api/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}`,
`${this.host}/api/v1/${roomType}.${endp}?roomId=${encodeURIComponent(
this.rid
)}${query}${field}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -609,16 +611,18 @@ export default class EmbeddedChatApi {
const roomType = isChannelPrivate ? "groups" : "channels";
const endp = anonymousMode ? "anonymousread" : "messages";
const query = options?.query
? `&query=${JSON.stringify(options.query)}`
? `&query=${encodeURIComponent(JSON.stringify(options.query))}`
: "";
const field = options?.field
? `&field=${JSON.stringify(options.field)}`
? `&field=${encodeURIComponent(JSON.stringify(options.field))}`
: "";
const offset = options?.offset ? options.offset : 0;
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const messages = await fetch(
`${this.host}/api/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}&offset=${offset}`,
`${this.host}/api/v1/${roomType}.${endp}?roomId=${encodeURIComponent(
this.rid
)}${query}${field}&offset=${offset}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -638,7 +642,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const messages = await fetch(
`${this.host}/api/v1/chat.getThreadMessages?tmid=${tmid}`,
`${this.host}/api/v1/chat.getThreadMessages?tmid=${encodeURIComponent(
tmid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -659,7 +665,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const roles = await fetch(
`${this.host}/api/v1/${roomType}.roles?roomId=${this.rid}`,
`${this.host}/api/v1/${roomType}.roles?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -679,7 +687,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const roles = await fetch(
`${this.host}/api/v1/roles.getUsersInRole?role=${role}`,
`${this.host}/api/v1/roles.getUsersInRole?role=${encodeURIComponent(
role
)}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -820,8 +830,12 @@ export default class EmbeddedChatApi {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const url =
typeGroup === ""
? `${this.host}/api/v1/${roomType}.files?roomId=${this.rid}`
: `${this.host}/api/v1/${roomType}.files?roomId=${this.rid}&typeGroup=${typeGroup}`;
? `${this.host}/api/v1/${roomType}.files?roomId=${encodeURIComponent(
this.rid
)}`
: `${this.host}/api/v1/${roomType}.files?roomId=${encodeURIComponent(
this.rid
)}&typeGroup=${encodeURIComponent(typeGroup)}`;
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Expand All @@ -840,7 +854,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/rooms.images?roomId=${this.rid}`,
`${this.host}/api/v1/rooms.images?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -896,7 +912,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/chat.getStarredMessages?roomId=${this.rid}`,
`${this.host}/api/v1/chat.getStarredMessages?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -916,7 +934,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/chat.getPinnedMessages?roomId=${this.rid}`,
`${this.host}/api/v1/chat.getPinnedMessages?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -936,7 +956,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/chat.getMentionedMessages?roomId=${this.rid}`,
`${this.host}/api/v1/chat.getMentionedMessages?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -1101,7 +1123,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/${roomType}.members?roomId=${this.rid}`,
`${this.host}/api/v1/${roomType}.members?roomId=${encodeURIComponent(
this.rid
)}`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -1121,7 +1145,9 @@ export default class EmbeddedChatApi {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/chat.search?roomId=${this.rid}&searchText=${text}`,
`${this.host}/api/v1/chat.search?roomId=${encodeURIComponent(
this.rid
)}&searchText=${encodeURIComponent(text)}`,
{
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -1233,7 +1259,9 @@ export default class EmbeddedChatApi {
async getUserStatus(reqUserId: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/users.getStatus?userId=${reqUserId}`,
`${this.host}/api/v1/users.getStatus?userId=${encodeURIComponent(
reqUserId
)}`,
{
method: "GET",
headers: {
Expand All @@ -1250,7 +1278,7 @@ export default class EmbeddedChatApi {
async userInfo(reqUserId: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/users.info?userId=${reqUserId}`,
`${this.host}/api/v1/users.info?userId=${encodeURIComponent(reqUserId)}`,
{
method: "GET",
headers: {
Expand All @@ -1267,7 +1295,7 @@ export default class EmbeddedChatApi {
async userData(username: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/users.info?username=${username}`,
`${this.host}/api/v1/users.info?username=${encodeURIComponent(username)}`,
{
method: "GET",
headers: {
Expand Down