initial commit of message loading with paging
This commit is contained in:
parent
9b2a143a18
commit
57ca9d7380
@ -11,6 +11,7 @@ import { fetchErrorHandler } from "./FetchErrorHandler";
|
|||||||
import { EncryptionService } from "../service/EncryptionService";
|
import { EncryptionService } from "../service/EncryptionService";
|
||||||
import { SJCLEncryptionService } from "../service/SJCLEncryptionService";
|
import { SJCLEncryptionService } from "../service/SJCLEncryptionService";
|
||||||
import { ChatModel } from "./ChatModel"
|
import { ChatModel } from "./ChatModel"
|
||||||
|
import { Sprintf } from "../singleton/Sprintf";
|
||||||
export class ChatModelHelper {
|
export class ChatModelHelper {
|
||||||
private static readonly _encryptionService: EncryptionService = new SJCLEncryptionService();
|
private static readonly _encryptionService: EncryptionService = new SJCLEncryptionService();
|
||||||
|
|
||||||
@ -46,7 +47,14 @@ export class ChatModelHelper {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
headers.append('X-AUTH-TOKEN', JsonAPI.authToken);
|
headers.append('X-AUTH-TOKEN', JsonAPI.authToken);
|
||||||
const response = await fetch(`${JsonAPI.CHAT_MESSAGES_GET}/${toUser}`, {
|
// const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser);
|
||||||
|
const url = Sprintf(JsonAPI.CHAT_MESSAGE_PAGE_GET, toUser,1,5);
|
||||||
|
log.debug(url)
|
||||||
|
// const response = await fetch(`${JsonAPI.CHAT_MESSAGES_GET}/${toUser}`, {
|
||||||
|
// method: 'GET',
|
||||||
|
// headers: headers
|
||||||
|
// });
|
||||||
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,33 @@ export namespace JsonAPI {
|
|||||||
export let contactName: string | null;
|
export let contactName: string | null;
|
||||||
export let authToken: string | null = localStorage.getItem('authToken');
|
export let authToken: string | null = localStorage.getItem('authToken');
|
||||||
export const ACTIVE_USERS_GET = `/api/chat/get/active-users`;
|
export const ACTIVE_USERS_GET = `/api/chat/get/active-users`;
|
||||||
export const CHAT_MESSAGES_GET = `/api/chat/get/messages`;
|
/**
|
||||||
|
* Json API URL for retrieving all messages between two users
|
||||||
|
*
|
||||||
|
* @format /api/chat/get/messages/some-user
|
||||||
|
*
|
||||||
|
* ### With sprintf
|
||||||
|
* const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser);
|
||||||
|
*
|
||||||
|
* @param toUser
|
||||||
|
* The user whose messages wish to retrieve. The 'from user' part of the message is given by the current user logged in.
|
||||||
|
* /api/chat/get/messages/{toUser}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const CHAT_MESSAGES_GET = `/api/chat/get/messages/%s`;
|
||||||
export const MESSAGE_POST = '/api/chat/post/message';
|
export const MESSAGE_POST = '/api/chat/post/message';
|
||||||
|
/**
|
||||||
|
* Json API URL for retrieving paginated messages between two users
|
||||||
|
*
|
||||||
|
* @format /api/chat/get/messages/some-user?page=1&size=5 will give the first page with size 5
|
||||||
|
*
|
||||||
|
* ### With sprintf
|
||||||
|
* const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser);
|
||||||
|
*
|
||||||
|
* @param toUser The user whose messages wish to retrieve. The 'from user' part of the message is given by the current user logged in.
|
||||||
|
* @param page Denotes the page required
|
||||||
|
* @param denotes the size of each page
|
||||||
|
*/
|
||||||
|
export const CHAT_MESSAGE_PAGE_GET = `/api/chat/get/messages/%s?page=%d&size=%d`;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user