feat(core): broadcast_only flag for searchGlobal

This commit is contained in:
alina 🌸 2024-05-05 20:56:52 +03:00
parent 00da6736e6
commit e8a09ec270
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 9 additions and 1 deletions

View file

@ -33,7 +33,7 @@ export async function* iterSearchGlobal(
): AsyncIterableIterator<Message> { ): AsyncIterableIterator<Message> {
if (!params) params = {} if (!params) params = {}
const { query = '', filter = SearchFilters.Empty, limit = Infinity, chunkSize = 100 } = params const { query = '', filter = SearchFilters.Empty, limit = Infinity, chunkSize = 100, onlyChannels } = params
const minDate = normalizeDate(params.minDate) ?? 0 const minDate = normalizeDate(params.minDate) ?? 0
const maxDate = normalizeDate(params.maxDate) ?? 0 const maxDate = normalizeDate(params.maxDate) ?? 0
@ -49,6 +49,7 @@ export async function* iterSearchGlobal(
minDate, minDate,
maxDate, maxDate,
offset, offset,
onlyChannels,
}) })
if (!res.length) return if (!res.length) return

View file

@ -63,6 +63,11 @@ export async function searchGlobal(
* Only return messages older than this date * Only return messages older than this date
*/ */
maxDate?: Date | number maxDate?: Date | number
/**
* Whether to only search across broadcast channels
*/
onlyChannels?: boolean
}, },
): Promise<ArrayPaginated<Message, SearchGlobalOffset>> { ): Promise<ArrayPaginated<Message, SearchGlobalOffset>> {
if (!params) params = {} if (!params) params = {}
@ -72,6 +77,7 @@ export async function searchGlobal(
filter = SearchFilters.Empty, filter = SearchFilters.Empty,
limit = 100, limit = 100,
offset: { rate: offsetRate, peer: offsetPeer, id: offsetId } = defaultOffset, offset: { rate: offsetRate, peer: offsetPeer, id: offsetId } = defaultOffset,
onlyChannels,
} = params } = params
const minDate = normalizeDate(params.minDate) ?? 0 const minDate = normalizeDate(params.minDate) ?? 0
@ -87,6 +93,7 @@ export async function searchGlobal(
offsetRate, offsetRate,
offsetPeer, offsetPeer,
limit, limit,
broadcastsOnly: onlyChannels,
}) })
assertTypeIsNot('searchGlobal', res, 'messages.messagesNotModified') assertTypeIsNot('searchGlobal', res, 'messages.messagesNotModified')