feat(client): custom filtering for getDialogs
This commit is contained in:
parent
bfcea5a80d
commit
a4f6c42bf5
2 changed files with 37 additions and 0 deletions
|
@ -916,6 +916,15 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* By default fetches from "All" folder
|
* By default fetches from "All" folder
|
||||||
*/
|
*/
|
||||||
folder?: string | number | tl.RawDialogFilter
|
folder?: string | number | tl.RawDialogFilter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional filtering for the dialogs.
|
||||||
|
*
|
||||||
|
* If `folder` is not provided, this filter is used instead.
|
||||||
|
* If `folder` is provided, fields from this object are used
|
||||||
|
* to override filters inside the folder.
|
||||||
|
*/
|
||||||
|
filter?: Partial<Omit<tl.RawDialogFilter, '_' | 'id' | 'title'>>
|
||||||
}): AsyncIterableIterator<Dialog>
|
}): AsyncIterableIterator<Dialog>
|
||||||
/**
|
/**
|
||||||
* Get list of folders.
|
* Get list of folders.
|
||||||
|
|
|
@ -108,6 +108,15 @@ export async function* getDialogs(
|
||||||
* By default fetches from "All" folder
|
* By default fetches from "All" folder
|
||||||
*/
|
*/
|
||||||
folder?: string | number | tl.RawDialogFilter
|
folder?: string | number | tl.RawDialogFilter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional filtering for the dialogs.
|
||||||
|
*
|
||||||
|
* If `folder` is not provided, this filter is used instead.
|
||||||
|
* If `folder` is provided, fields from this object are used
|
||||||
|
* to override filters inside the folder.
|
||||||
|
*/
|
||||||
|
filter?: Partial<Omit<tl.RawDialogFilter, '_' | 'id' | 'title'>>
|
||||||
}
|
}
|
||||||
): AsyncIterableIterator<Dialog> {
|
): AsyncIterableIterator<Dialog> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
@ -130,6 +139,25 @@ export async function* getDialogs(
|
||||||
filters = params.folder
|
filters = params.folder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.filter) {
|
||||||
|
if (filters) {
|
||||||
|
filters = {
|
||||||
|
...filters,
|
||||||
|
...params.filter
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filters = {
|
||||||
|
_: 'dialogFilter',
|
||||||
|
id: 0,
|
||||||
|
title: '',
|
||||||
|
pinnedPeers: [],
|
||||||
|
includePeers: [],
|
||||||
|
excludePeers: [],
|
||||||
|
...params.filter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const fetchPinnedDialogsFromFolder = async (): Promise<tl.messages.RawPeerDialogs | null> => {
|
const fetchPinnedDialogsFromFolder = async (): Promise<tl.messages.RawPeerDialogs | null> => {
|
||||||
if (!filters || !filters.pinnedPeers.length) return null
|
if (!filters || !filters.pinnedPeers.length) return null
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
Loading…
Reference in a new issue