1234567891011121314151617181920212223242526272829 |
- import { Subject, takeWhile } from "rxjs";
- import { WrappedMessage } from "../../interfaces/general.interface";
- export function sortMessageBasedOnDate(array: WrappedMessage[]): WrappedMessage[] {
- console.log(`Sorting ${array.length} messages....`)
- return array.sort((a, b) => {
- return new Date(a.timeReceived).getTime() - new Date(b.timeReceived).getTime();
- });
- }
- // SO concept will be that if the message behind it is received, then
- export async function checkMessage(message: WrappedMessage, messageChecking: Subject<WrappedMessage>): Promise<any> {
- return new Promise((resolve, reject) => {
- if (message.previousMessageID) {
- messageChecking.pipe(
- takeWhile(item => message.previousMessageID === item.thisMessageID)
- ).subscribe({
- complete: () => {
- resolve('previousMessageID matched')
- // console.log(`${message.payload.header.messageID} : Previous messageID(${message.previousMessageID}) matched`)
- // console.log(`matched`)
- }
- })
- } else {
- console.log('No previous messageID. This should be the first message')
- resolve('No previous message ID. Please Proceed.')
- }
- })
- }
|