fix(client): remove explicit simple/non-simple webview type, change it automatically if needed
This commit is contained in:
parent
2c54751029
commit
2c6238798f
1 changed files with 23 additions and 16 deletions
|
@ -335,22 +335,17 @@ export namespace BotKeyboard {
|
||||||
/**
|
/**
|
||||||
* Button to open webview
|
* Button to open webview
|
||||||
*
|
*
|
||||||
* Used for both inline keyboards and reply ones, but!
|
* Used for both inline keyboards and reply ones
|
||||||
*
|
|
||||||
* For inline keyboards, `simple=false`
|
|
||||||
* For reply keyboards, `simple=true`
|
|
||||||
*
|
*
|
||||||
* @param text Button label
|
* @param text Button label
|
||||||
* @param url WebView URL
|
* @param url WebView URL
|
||||||
* @param simple Whether to use simple WebView
|
|
||||||
*/
|
*/
|
||||||
export function webView(
|
export function webView(
|
||||||
text: string,
|
text: string,
|
||||||
url: string,
|
url: string
|
||||||
simple = false
|
): tl.RawKeyboardButtonWebView {
|
||||||
): tl.RawKeyboardButtonWebView | tl.RawKeyboardButtonSimpleWebView {
|
|
||||||
return {
|
return {
|
||||||
_: simple ? 'keyboardButtonSimpleWebView' : 'keyboardButtonWebView',
|
_: 'keyboardButtonWebView',
|
||||||
text,
|
text,
|
||||||
url,
|
url,
|
||||||
}
|
}
|
||||||
|
@ -415,12 +410,24 @@ export namespace BotKeyboard {
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export function _2dToRows(
|
export function _2dToRows(
|
||||||
arr: tl.TypeKeyboardButton[][]
|
arr: tl.TypeKeyboardButton[][],
|
||||||
|
inline: boolean
|
||||||
): tl.RawKeyboardButtonRow[] {
|
): tl.RawKeyboardButtonRow[] {
|
||||||
return arr.map((row) => ({
|
return arr.map((row) => {
|
||||||
_: 'keyboardButtonRow',
|
if (!inline) {
|
||||||
buttons: row,
|
// le cringe
|
||||||
}))
|
row.forEach((btn) => {
|
||||||
|
if (btn._ === 'keyboardButtonWebView') {
|
||||||
|
;(btn as any)._ = 'keyboardButtonSimpleWebView'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
_: 'keyboardButtonRow',
|
||||||
|
buttons: row,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -436,7 +443,7 @@ export namespace BotKeyboard {
|
||||||
resize: obj.resize,
|
resize: obj.resize,
|
||||||
singleUse: obj.singleUse,
|
singleUse: obj.singleUse,
|
||||||
selective: obj.selective,
|
selective: obj.selective,
|
||||||
rows: _2dToRows(obj.buttons),
|
rows: _2dToRows(obj.buttons, false),
|
||||||
}
|
}
|
||||||
case 'reply_hide':
|
case 'reply_hide':
|
||||||
return {
|
return {
|
||||||
|
@ -452,7 +459,7 @@ export namespace BotKeyboard {
|
||||||
case 'inline':
|
case 'inline':
|
||||||
return {
|
return {
|
||||||
_: 'replyInlineMarkup',
|
_: 'replyInlineMarkup',
|
||||||
rows: _2dToRows(obj.buttons),
|
rows: _2dToRows(obj.buttons, true),
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assertNever(obj)
|
assertNever(obj)
|
||||||
|
|
Loading…
Reference in a new issue