diff --git a/src/components/files.js b/src/components/files.js index 70bfdd2..02d1587 100644 --- a/src/components/files.js +++ b/src/components/files.js @@ -203,6 +203,69 @@ export async function uploadRecordFile({ return response; } +export async function uploadMessageFile({ + secretKey, + fileUri, + file, + base64, + fileType, + fileName, + channelId, +}) { + if (base64) { + const response = await server.loadJson( + `${Config.apiUrl}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.FILES.UPLOAD}`, + { + method: 'POST', + headers: { + 'X-CM-ProjectId': Config.projectId, + Authorization: `Bearer ${secretKey || Config.secretKey}`, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify({ + channelId, + base64File: {data: base64, contentType: fileType, fileName}, + }), + } + ); + + return response; + } + + const formData = new FormData(); + if (channelId != null && channelId !== undefined) { + formData.append('channelId', channelId); + } + + if (fileUri) { + const finalFilename = + fileName || fileUri.substring(fileUri.lastIndexOf('/') + 1); + + formData.append('file', { + uri: fileUri, + name: finalFilename, + type: fileType, + }); + } else { + formData.append('file', file); + } + + const response = await server.loadJson( + `${Config.apiUrl}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.FILES.UPLOAD}`, + { + method: 'POST', + headers: { + 'X-CM-ProjectId': Config.projectId, + Authorization: `Bearer ${secretKey || Config.secretKey}`, + }, + body: formData, + } + ); + + return response; +} + export function getFilePath(directory, fileName) { return `${Config.baseFilePath}/${directory}/${fileName}`; } diff --git a/src/components/sse.js b/src/components/sse.js index 43cf532..80ad621 100644 --- a/src/components/sse.js +++ b/src/components/sse.js @@ -54,6 +54,7 @@ export async function getGroups({ sort, includeChannels, includeUsers, + includeNotSeenCount, }) { const request = { pageSize: pageSize || Config.tablePageSize, @@ -62,6 +63,7 @@ export async function getGroups({ sort: objectOrStringToString(sort), includeChannels, includeUsers, + includeNotSeenCount, }; const requestUrl = `${ Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.GET_GROUPS @@ -83,6 +85,38 @@ export async function getGroups({ return response; } +export async function getGroup({ + secretKey, + id, + includeChannels, + includeUsers, + includeNotSeenCount, +}) { + const request = { + includeChannels, + includeUsers, + includeNotSeenCount, + }; + const requestUrl = `${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.GET_GROUP( + id + )}?${toQueryString(request)}`; + + const response = await server.loadJson( + `${Config.eventsApiUrl}${requestUrl}`, + { + method: 'GET', + headers: { + 'X-CM-ProjectId': Config.projectId, + Authorization: `Bearer ${secretKey || Config.secretKey}`, + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: null, + } + ); + return response; +} + export async function createChannel({secretKey, groupId, title, meta, users}) { const response = await server.loadJson( `${ @@ -163,7 +197,13 @@ export async function getChannels({ return response; } -export async function sendMessage({secretKey, channelId, message, meta}) { +export async function sendMessage({ + secretKey, + channelId, + message, + meta, + fileIds, +}) { const response = await server.loadJson( `${Config.eventsApiUrl}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.SEND_MESSAGE}`, { @@ -178,6 +218,28 @@ export async function sendMessage({secretKey, channelId, message, meta}) { channelId, message, meta, + fileIds, + }), + } + ); + + return response; +} + +export async function readMessages({secretKey, channelId, ids}) { + const response = await server.loadJson( + `${Config.eventsApiUrl}${Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.READ_MESSAGES}`, + { + method: 'POST', + headers: { + 'X-CM-ProjectId': Config.projectId, + Authorization: `Bearer ${secretKey || Config.secretKey}`, + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + channelId, + ids, }), } ); diff --git a/src/routes.js b/src/routes.js index 4e785d7..0e3fd1e 100644 --- a/src/routes.js +++ b/src/routes.js @@ -77,6 +77,7 @@ export const CONFIG = { CREATE_GROUP: '/v2/notifications/server-events/groups', DELETE_GROUP: (id) => `/v2/notifications/server-events/groups/${id}`, GET_GROUPS: '/v2/notifications/server-events/groups', + GET_GROUP: (id) => `/v2/notifications/server-events/groups/${id}`, CREATE_CHANNEL: (groupId) => `/v2/notifications/server-events/groups/${groupId}/channels`, DELETE_CHANNEL: (groupId, id) => @@ -85,12 +86,16 @@ export const CONFIG = { `/v2/notifications/server-events/groups/${groupId}/channels`, GET_MESSAGES: '/v2/notifications/server-events/messages', SEND_MESSAGE: '/v2/notifications/server-events/messages', + READ_MESSAGES: '/v2/notifications/server-events/messages/read', AUTHORIZE_CONNECTION: '/v2/notifications/server-events/connections/initialize', OPEN_CONNECTION: '/v2/notifications/server-events/connections/open', HEARTBEAT_CONNECTION: '/v2/notifications/server-events/connections/health', CLOSE_CONNECTION: '/v2/notifications/server-events/connections/close', + FILES: { + UPLOAD: '/v2/notifications/server-events/messages/files', + }, }, }, MEMBERSHIP: {