import { Api } from 'telegram' ; import { Snake } from '../../client' ; import * as Updates from '../../Update' ; export interface pinMessageMoreParams { silent ? : boolean ; unpin ? : boolean ; pmOneside ? : boolean ; } export async function PinMessage ( snakeClient , chatId , messageId , more ? ) { try { let results = await snakeClient . client . invoke ( new Api . messages . UpdatePinnedMessage ( { peer : chatId , id : messageId , ... more , } ) ) ; return await generateResults ( results , snakeClient ) ; } catch ( error ) { return snakeClient . _handleError ( error , `telegram.pinMessage(${ chatId },${ messageId }${ more ? ',' + JSON . stringify ( more ) : '' })` ) ; } } async function generateResults ( results , SnakeClient ) { if ( results instanceof Api . Updates ) { results as Api . Updates ; if ( results . updates . length > 0 ) { for ( let i = 0 ; i < results . updates . length ; i ++ ) { let update = results . updates [ i ] ; if ( update instanceof Api . UpdateNewMessage ) { update as Api . UpdateNewMessage ; let res = new Updates . UpdateNewMessage ( ) ; await res . init ( update , SnakeClient ) ; return res ; } if ( update instanceof Api . UpdateNewChannelMessage ) { update as Api . UpdateNewChannelMessage ; return update ; } if ( update instanceof Api . UpdatePinnedMessages ) { update as Api . UpdatePinnedMessages ; return update ; } if ( update instanceof Api . UpdatePinnedChannelMessages ) { update as Api . UpdatePinnedChannelMessages ; return update ; } } } } }