-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
43 additions
and
1,607 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
|
||
import { callWithErrorHandling } from '../../../client/lib/utils/callWithErrorHandling'; | ||
import { ChatMessage } from '../../models/client'; | ||
import { withDebouncing } from '../../../lib/utils/highOrderFunctions'; | ||
|
||
export const findParentMessage = (() => { | ||
const waiting: string[] = []; | ||
let resolve: (resolved: IMessage[] | PromiseLike<IMessage[]>) => void; | ||
let pending = new Promise<IMessage[]>((r) => { | ||
resolve = r; | ||
}); | ||
|
||
const getMessages = withDebouncing({ wait: 500 })(async function () { | ||
const _tmp = [...waiting]; | ||
waiting.length = 0; | ||
resolve(callWithErrorHandling('getMessages', _tmp)); | ||
pending = new Promise<IMessage[]>((r) => { | ||
resolve = r; | ||
}); | ||
}); | ||
|
||
const get = async (tmid: IMessage['_id']) => { | ||
getMessages(); | ||
const messages = await pending; | ||
return messages.find(({ _id }) => _id === tmid); | ||
}; | ||
|
||
return async (tmid: IMessage['_id']) => { | ||
const message = ChatMessage.findOne({ _id: tmid }); | ||
|
||
if (message) { | ||
return message; | ||
} | ||
|
||
if (waiting.indexOf(tmid) === -1) { | ||
waiting.push(tmid); | ||
} | ||
return get(tmid); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.