add loadHistory method

This commit is contained in:
Peter Maquiran
2022-01-10 17:52:49 +01:00
parent 316803e9e0
commit cb5cbfab69
2 changed files with 39 additions and 11 deletions
@@ -5,7 +5,10 @@ import { wsCallbacksParams, msgQueue } from 'src/app/models/rochet-chat-cliente-
/**
* Use this class to interact with rocketChat realtime API
*/
class _RocketChatClientService {
@Injectable({
providedIn: 'root'
})
export class RocketChatClientService {
private hasPing = false
private firstPingFunx: Function
@@ -163,6 +166,37 @@ class _RocketChatClientService {
});
}
loadHistory(roomId, limit: number = 50) {
const conditions = this.attemptRequestQueue({...roomId, limit}, {methodName:'loadHistory'})
if(conditions == false) { return new Promise((resolve, reject) => { reject('no error')}); }
const requestId = uuidv4()
const request = {
msg: "method",
method: "loadHistory",
id: requestId,
params: [
roomId,
null,
limit,
{
"$date": 1480377601
}
]
}
this.ws.send(request, requestId)
// return new Promise((resolve, reject) => {
// this.ws.registerCallback({type:'Onmessage', requestId, runOnces: true, funx:(message)=>{
// if(message.id == requestId || message.result.id == requestId) { // same request send
// resolve(message)
// }
// }})
// });
}
subscribe(roomId : string) {
@@ -281,7 +315,7 @@ class _RocketChatClientService {
private ws = {
connected: false,
registerCallback:(params: wsCallbacksParams) =>{
registerCallback:(params: wsCallbacksParams) => {
if(!params.requestId) {
params.requestId = uuidv4()
@@ -363,7 +397,4 @@ class _RocketChatClientService {
}
}
export const RocketChatClientService = new _RocketChatClientService()
}