Skip to content
Merged
Show file tree
Hide file tree
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
63 changes: 63 additions & 0 deletions src/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
64 changes: 63 additions & 1 deletion src/components/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function getGroups({
sort,
includeChannels,
includeUsers,
includeNotSeenCount,
}) {
const request = {
pageSize: pageSize || Config.tablePageSize,
Expand All @@ -62,6 +63,7 @@ export async function getGroups({
sort: objectOrStringToString(sort),
includeChannels,
includeUsers,
includeNotSeenCount,
};
const requestUrl = `${
Endpoints.PROJECT.NOTIFICATIONS.SERVER_EVENTS.GET_GROUPS
Expand All @@ -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(
`${
Expand Down Expand Up @@ -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}`,
{
Expand All @@ -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,
}),
}
);
Expand Down
5 changes: 5 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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: {
Expand Down