Handle case when all items checked and cleared
This commit is contained in:
parent
70b4b9b847
commit
ea082ccc89
@ -96,7 +96,7 @@ func makeButtons(items []Entry) [][]button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GList) GenSendListReq() ([]byte, error) {
|
func (g *GList) GenSendListReq() ([]byte, error) {
|
||||||
req := newListReq{ChatID: g.ChatID, MessageID: g.MessageID, Text: "ok"}
|
req := newListReq{ChatID: g.ChatID, MessageID: g.MessageID, Text: "List:"}
|
||||||
itemButtons := makeButtons(g.Items)
|
itemButtons := makeButtons(g.Items)
|
||||||
controlButtons := []button{{"clear checked", "clear"}}
|
controlButtons := []button{{"clear checked", "clear"}}
|
||||||
req.ReplyMarkup.InlineKeyboard = append(itemButtons, controlButtons)
|
req.ReplyMarkup.InlineKeyboard = append(itemButtons, controlButtons)
|
||||||
|
5
main.go
5
main.go
@ -101,12 +101,17 @@ func handleButtonClick(gl *glist.GList, messageID int, text string) {
|
|||||||
gl.MessageID = &messageID
|
gl.MessageID = &messageID
|
||||||
if text == "clear" {
|
if text == "clear" {
|
||||||
gl.ClearChecked()
|
gl.ClearChecked()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
gl.Toggle(text)
|
gl.Toggle(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(gl.Items) == 0 {
|
||||||
|
deleteMessage(gl.ChatID, messageID)
|
||||||
|
} else {
|
||||||
sendList(gl, "editMessageText")
|
sendList(gl, "editMessageText")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func sendList(gl *glist.GList, method string) {
|
func sendList(gl *glist.GList, method string) {
|
||||||
url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", apiToken, method)
|
url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", apiToken, method)
|
||||||
|
Loading…
Reference in New Issue
Block a user