feat(core): shouldDispatch
option for methods that use dummy updates (#65)
This commit is contained in:
commit
40baa6dd5d
10 changed files with 124 additions and 25 deletions
|
@ -1531,6 +1531,12 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
/** User/channel ID whose messages to delete */
|
/** User/channel ID whose messages to delete */
|
||||||
participantId: InputPeerLike
|
participantId: InputPeerLike
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch the updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
}): Promise<void>
|
}): Promise<void>
|
||||||
/**
|
/**
|
||||||
* Edit supergroup/channel admin rights of a user.
|
* Edit supergroup/channel admin rights of a user.
|
||||||
|
@ -2668,7 +2674,17 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
* @param chat Chat or user ID, username, phone number, `"me"` or `"self"`
|
* @param chat Chat or user ID, username, phone number, `"me"` or `"self"`
|
||||||
* @param topicId ID of the topic (i.e. its top message ID)
|
* @param topicId ID of the topic (i.e. its top message ID)
|
||||||
*/
|
*/
|
||||||
deleteForumTopicHistory(chat: InputPeerLike, topicId: number | ForumTopic): Promise<void>
|
deleteForumTopicHistory(
|
||||||
|
chat: InputPeerLike,
|
||||||
|
topicId: number | ForumTopic,
|
||||||
|
params?: {
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
|
},
|
||||||
|
): Promise<void>
|
||||||
/**
|
/**
|
||||||
* Modify a topic in a forum
|
* Modify a topic in a forum
|
||||||
*
|
*
|
||||||
|
@ -3756,6 +3772,12 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
* Whether to also clear all mentions in the chat
|
* Whether to also clear all mentions in the chat
|
||||||
*/
|
*/
|
||||||
clearMentions?: boolean
|
clearMentions?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
},
|
},
|
||||||
): Promise<void>
|
): Promise<void>
|
||||||
/**
|
/**
|
||||||
|
@ -3765,7 +3787,16 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
*
|
*
|
||||||
* @param chatId Chat ID
|
* @param chatId Chat ID
|
||||||
*/
|
*/
|
||||||
readReactions(chatId: InputPeerLike): Promise<void>
|
readReactions(
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
params?: {
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
|
},
|
||||||
|
): Promise<void>
|
||||||
/**
|
/**
|
||||||
* Search for messages globally from all of your chats
|
* Search for messages globally from all of your chats
|
||||||
*
|
*
|
||||||
|
@ -4333,6 +4364,12 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
* For forums - unpin only messages from the given topic
|
* For forums - unpin only messages from the given topic
|
||||||
*/
|
*/
|
||||||
topicId?: number
|
topicId?: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
},
|
},
|
||||||
): Promise<void>
|
): Promise<void>
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,9 +15,15 @@ export async function deleteUserHistory(
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
/** User/channel ID whose messages to delete */
|
/** User/channel ID whose messages to delete */
|
||||||
participantId: InputPeerLike
|
participantId: InputPeerLike
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch the updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
},
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { chatId, participantId } = params
|
const { chatId, participantId, shouldDispatch } = params
|
||||||
|
|
||||||
const channel = await resolveChannel(client, chatId)
|
const channel = await resolveChannel(client, chatId)
|
||||||
|
|
||||||
|
@ -29,5 +35,7 @@ export async function deleteUserHistory(
|
||||||
participant: peer,
|
participant: peer,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, (channel as tl.RawInputChannel).channelId))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, (channel as tl.RawInputChannel).channelId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,16 @@ export async function deleteForumTopicHistory(
|
||||||
client: ITelegramClient,
|
client: ITelegramClient,
|
||||||
chat: InputPeerLike,
|
chat: InputPeerLike,
|
||||||
topicId: number | ForumTopic,
|
topicId: number | ForumTopic,
|
||||||
|
params?: {
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const { shouldDispatch } = params ?? {}
|
||||||
|
|
||||||
const channel = await resolveChannel(client, chat)
|
const channel = await resolveChannel(client, chat)
|
||||||
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')
|
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')
|
||||||
|
|
||||||
|
@ -24,5 +33,7 @@ export async function deleteForumTopicHistory(
|
||||||
topMsgId: typeof topicId === 'number' ? topicId : topicId.id,
|
topMsgId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, channel.channelId))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, channel.channelId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,12 @@ export interface DeleteMessagesParams {
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
revoke?: boolean
|
revoke?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +36,7 @@ export async function deleteMessagesById(
|
||||||
ids: number[],
|
ids: number[],
|
||||||
params?: DeleteMessagesParams,
|
params?: DeleteMessagesParams,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { revoke = true } = params ?? {}
|
const { revoke = true, shouldDispatch } = params ?? {}
|
||||||
|
|
||||||
const peer = await resolvePeer(client, chatId)
|
const peer = await resolvePeer(client, chatId)
|
||||||
|
|
||||||
|
@ -53,7 +59,9 @@ export async function deleteMessagesById(
|
||||||
upd = createDummyUpdate(res.pts, res.ptsCount)
|
upd = createDummyUpdate(res.pts, res.ptsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
client.handleClientUpdate(upd)
|
client.handleClientUpdate(upd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,9 +25,15 @@ export async function readHistory(
|
||||||
* Whether to also clear all mentions in the chat
|
* Whether to also clear all mentions in the chat
|
||||||
*/
|
*/
|
||||||
clearMentions?: boolean
|
clearMentions?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
},
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { maxId = 0, clearMentions } = params ?? {}
|
const { maxId = 0, clearMentions, shouldDispatch } = params ?? {}
|
||||||
|
|
||||||
const peer = await resolvePeer(client, chatId)
|
const peer = await resolvePeer(client, chatId)
|
||||||
|
|
||||||
|
@ -37,12 +43,14 @@ export async function readHistory(
|
||||||
peer,
|
peer,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
|
||||||
} else {
|
} else {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
const r = await client.call({
|
const r = await client.call({
|
||||||
|
@ -58,6 +66,9 @@ export async function readHistory(
|
||||||
peer,
|
peer,
|
||||||
maxId,
|
maxId,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,24 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
*
|
*
|
||||||
* @param chatId Chat ID
|
* @param chatId Chat ID
|
||||||
*/
|
*/
|
||||||
export async function readReactions(client: ITelegramClient, chatId: InputPeerLike): Promise<void> {
|
export async function readReactions(
|
||||||
|
client: ITelegramClient,
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
params?: {
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
|
},
|
||||||
|
): Promise<void> {
|
||||||
|
const { shouldDispatch } = params ?? {}
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'messages.readReactions',
|
_: 'messages.readReactions',
|
||||||
peer: await resolvePeer(client, chatId),
|
peer: await resolvePeer(client, chatId),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,8 @@ export interface CommonSendParams {
|
||||||
quickReply?: number | string
|
quickReply?: number | string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to dispatch the returned message
|
* Whether to dispatch the returned message to the client's update handler.
|
||||||
* to the client's update handler.
|
* Doesn't follow `disableNoDispatch`
|
||||||
*/
|
*/
|
||||||
shouldDispatch?: true
|
shouldDispatch?: true
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,9 @@ export async function sendText(
|
||||||
entities: res.entities,
|
entities: res.entities,
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this needed?
|
if (!params.shouldDispatch) {
|
||||||
// this._date = res.date
|
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
|
}
|
||||||
|
|
||||||
const peers = new PeersIndex()
|
const peers = new PeersIndex()
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,15 @@ export async function unpinAllMessages(
|
||||||
* For forums - unpin only messages from the given topic
|
* For forums - unpin only messages from the given topic
|
||||||
*/
|
*/
|
||||||
topicId?: number
|
topicId?: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to dispatch updates that will be generated by this call.
|
||||||
|
* Doesn't follow `disableNoDispatch`
|
||||||
|
*/
|
||||||
|
shouldDispatch?: true
|
||||||
},
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { topicId } = params ?? {}
|
const { topicId, shouldDispatch } = params ?? {}
|
||||||
|
|
||||||
const peer = await resolvePeer(client, chatId)
|
const peer = await resolvePeer(client, chatId)
|
||||||
|
|
||||||
|
@ -29,9 +35,11 @@ export async function unpinAllMessages(
|
||||||
topMsgId: topicId,
|
topMsgId: topicId,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!shouldDispatch) {
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
|
||||||
} else {
|
} else {
|
||||||
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ export interface UpdatesManagerParams {
|
||||||
*
|
*
|
||||||
* > **Note**: you can disable this on per-request basis by passing
|
* > **Note**: you can disable this on per-request basis by passing
|
||||||
* > `shouldDispatch: true` to the method call that accepts it.
|
* > `shouldDispatch: true` to the method call that accepts it.
|
||||||
|
* > For some methods you need to always pass `shouldDispatch: true` explicitly.
|
||||||
|
* > This is noted in the corresponding method's documentation by "Doesn't follow `disableNoDispatch`"
|
||||||
*
|
*
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue