mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
add loadHistory method
This commit is contained in:
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user