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
74 changes: 37 additions & 37 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export default class EmbeddedChatApi {

async updateUserNameThroughSuggestion(userid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/users.getUsernameSuggestion`,
{
Expand Down Expand Up @@ -440,7 +440,7 @@ export default class EmbeddedChatApi {

if (usernameRegExp.test(newUserName)) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/users.update`, {
body: JSON.stringify({
userId: userid,
Expand Down Expand Up @@ -473,7 +473,7 @@ export default class EmbeddedChatApi {

async channelInfo() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/rooms.info?roomId=${this.rid}`,
{
Expand All @@ -493,7 +493,7 @@ export default class EmbeddedChatApi {

async getRoomInfo() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/method.call/rooms%3Aget`,
{
Expand Down Expand Up @@ -528,7 +528,7 @@ export default class EmbeddedChatApi {

async permissionInfo() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/permissions.listAll`, {
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -575,7 +575,7 @@ export default class EmbeddedChatApi {
? `&field=${JSON.stringify(options.field)}`
: "";
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const messages = await fetch(
`${this.host}/api/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}`,
{
Expand Down Expand Up @@ -616,7 +616,7 @@ export default class EmbeddedChatApi {
: "";
const offset = options?.offset ? options.offset : 0;
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const messages = await fetch(
`${this.host}/api/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}&offset=${offset}`,
{
Expand All @@ -636,7 +636,7 @@ export default class EmbeddedChatApi {

async getThreadMessages(tmid: string, isChannelPrivate = false) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const messages = await fetch(
`${this.host}/api/v1/chat.getThreadMessages?tmid=${tmid}`,
{
Expand All @@ -657,7 +657,7 @@ export default class EmbeddedChatApi {
async getChannelRoles(isChannelPrivate = false) {
const roomType = isChannelPrivate ? "groups" : "channels";
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const roles = await fetch(
`${this.host}/api/v1/${roomType}.roles?roomId=${this.rid}`,
{
Expand All @@ -677,7 +677,7 @@ export default class EmbeddedChatApi {

async getUsersInRole(role: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const roles = await fetch(
`${this.host}/api/v1/roles.getUsersInRole?role=${role}`,
{
Expand All @@ -697,7 +697,7 @@ export default class EmbeddedChatApi {

async getUserRoles() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/method.call/getUserRoles`,
{
Expand Down Expand Up @@ -762,7 +762,7 @@ export default class EmbeddedChatApi {
messageObj.tmid = threadId;
}
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.sendMessage`, {
body: JSON.stringify({ message: messageObj }),
headers: {
Expand All @@ -780,7 +780,7 @@ export default class EmbeddedChatApi {

async deleteMessage(msgId: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.delete`, {
body: JSON.stringify({ roomId: this.rid, msgId }),
headers: {
Expand All @@ -798,7 +798,7 @@ export default class EmbeddedChatApi {

async updateMessage(msgId: string, text: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.update`, {
body: JSON.stringify({ roomId: this.rid, msgId, text }),
headers: {
Expand All @@ -817,7 +817,7 @@ export default class EmbeddedChatApi {
async getAllFiles(isChannelPrivate = false, typeGroup: string) {
const roomType = isChannelPrivate ? "groups" : "channels";
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const url =
typeGroup === ""
? `${this.host}/api/v1/${roomType}.files?roomId=${this.rid}`
Expand All @@ -838,7 +838,7 @@ export default class EmbeddedChatApi {

async getAllImages() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/rooms.images?roomId=${this.rid}`,
{
Expand All @@ -858,7 +858,7 @@ export default class EmbeddedChatApi {

async starMessage(mid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.starMessage`, {
body: JSON.stringify({ messageId: mid }),
headers: {
Expand All @@ -876,7 +876,7 @@ export default class EmbeddedChatApi {

async unstarMessage(mid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.unStarMessage`, {
body: JSON.stringify({ messageId: mid }),
headers: {
Expand All @@ -894,7 +894,7 @@ export default class EmbeddedChatApi {

async getStarredMessages() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/chat.getStarredMessages?roomId=${this.rid}`,
{
Expand All @@ -914,7 +914,7 @@ export default class EmbeddedChatApi {

async getPinnedMessages() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/chat.getPinnedMessages?roomId=${this.rid}`,
{
Expand All @@ -934,7 +934,7 @@ export default class EmbeddedChatApi {

async getMentionedMessages() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/chat.getMentionedMessages?roomId=${this.rid}`,
{
Expand All @@ -954,7 +954,7 @@ export default class EmbeddedChatApi {

async pinMessage(mid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.pinMessage`, {
body: JSON.stringify({ messageId: mid }),
headers: {
Expand All @@ -974,7 +974,7 @@ export default class EmbeddedChatApi {

async unpinMessage(mid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.unPinMessage`, {
body: JSON.stringify({ messageId: mid }),
headers: {
Expand All @@ -992,7 +992,7 @@ export default class EmbeddedChatApi {

async reactToMessage(emoji: string, messageId: string, shouldReact: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.react`, {
body: JSON.stringify({
messageId,
Expand All @@ -1014,7 +1014,7 @@ export default class EmbeddedChatApi {

async reportMessage(messageId: string, description: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/chat.reportMessage`, {
body: JSON.stringify({ messageId, description }),
headers: {
Expand All @@ -1032,7 +1032,7 @@ export default class EmbeddedChatApi {

async findOrCreateInvite() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/findOrCreateInvite`, {
method: "POST",
body: JSON.stringify({ rid: this.rid, days: 1, maxUses: 10 }),
Expand All @@ -1055,7 +1055,7 @@ export default class EmbeddedChatApi {
threadId = undefined
) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const form = new FormData();
if (threadId) {
form.append("tmid", threadId);
Expand All @@ -1081,7 +1081,7 @@ export default class EmbeddedChatApi {

async me() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/me`, {
headers: {
"Content-Type": "application/json",
Expand All @@ -1099,7 +1099,7 @@ export default class EmbeddedChatApi {
async getChannelMembers(isChannelPrivate = false) {
const roomType = isChannelPrivate ? "groups" : "channels";
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/${roomType}.members?roomId=${this.rid}`,
{
Expand All @@ -1119,7 +1119,7 @@ export default class EmbeddedChatApi {

async getSearchMessages(text: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/chat.search?roomId=${this.rid}&searchText=${text}`,
{
Expand All @@ -1139,7 +1139,7 @@ export default class EmbeddedChatApi {

async getMessageLimit() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/settings/Message_MaxAllowedSize`,
{
Expand All @@ -1159,7 +1159,7 @@ export default class EmbeddedChatApi {

async handleUiKitInteraction(appId: string, userInteraction: any) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };

const triggerId = Math.random().toString(32).slice(2, 16);

Expand Down Expand Up @@ -1188,7 +1188,7 @@ export default class EmbeddedChatApi {
}

async getCommandsList() {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/commands.list`, {
headers: {
"Content-Type": "application/json",
Expand All @@ -1210,7 +1210,7 @@ export default class EmbeddedChatApi {
params: string;
tmid?: string;
}) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(`${this.host}/api/v1/commands.run`, {
headers: {
"Content-Type": "application/json",
Expand All @@ -1231,7 +1231,7 @@ export default class EmbeddedChatApi {
}

async getUserStatus(reqUserId: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/users.getStatus?userId=${reqUserId}`,
{
Expand All @@ -1248,7 +1248,7 @@ export default class EmbeddedChatApi {
}

async userInfo(reqUserId: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/users.info?userId=${reqUserId}`,
{
Expand All @@ -1265,7 +1265,7 @@ export default class EmbeddedChatApi {
}

async userData(username: string) {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const { userId, authToken } = (await this.auth.getCurrentUser()) ?? { userId: '', authToken: '' };
const response = await fetch(
`${this.host}/api/v1/users.info?username=${username}`,
{
Expand Down