Disable notificaiton for new list
This commit is contained in:
@ -109,16 +109,24 @@ func (g *GList) ClearChecked() {
|
||||
persistReqC <- g
|
||||
}
|
||||
|
||||
type SendMethod string
|
||||
|
||||
var (
|
||||
NEWLIST SendMethod = "sendMessage"
|
||||
EDITLIST SendMethod = "editMessageText"
|
||||
)
|
||||
|
||||
type button struct {
|
||||
Text string `json:"text"`
|
||||
CallbackData string `json:"callback_data"`
|
||||
}
|
||||
|
||||
type newListReq struct {
|
||||
ChatID int `json:"chat_id"`
|
||||
MessageID *int `json:"message_id,omitempty"`
|
||||
Text string `json:"text"`
|
||||
ReplyMarkup struct {
|
||||
ChatID int `json:"chat_id"`
|
||||
MessageID *int `json:"message_id,omitempty"`
|
||||
Text string `json:"text"`
|
||||
DisableNotification *bool `json:"disable_notification,omitempty"`
|
||||
ReplyMarkup struct {
|
||||
InlineKeyboard [][]button `json:"inline_keyboard"`
|
||||
} `json:"reply_markup"`
|
||||
}
|
||||
@ -147,8 +155,12 @@ func makeButtons(items []Entry) [][]button {
|
||||
return buttons
|
||||
}
|
||||
|
||||
func (g *GList) GenSendListReq() ([]byte, error) {
|
||||
func (g *GList) GenSendListReq(method SendMethod) ([]byte, error) {
|
||||
req := newListReq{ChatID: g.ChatID, MessageID: g.MessageID, Text: "List:"}
|
||||
if method == NEWLIST {
|
||||
disableNotification := true
|
||||
req.DisableNotification = &disableNotification
|
||||
}
|
||||
itemButtons := makeButtons(g.Items)
|
||||
controlButtons := []button{{"clear checked", "clear"}}
|
||||
req.ReplyMarkup.InlineKeyboard = append(itemButtons, controlButtons)
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
|
||||
func TestGList(t *testing.T) {
|
||||
g := NewGList(4342, "foo")
|
||||
data, err := g.GenSendListReq()
|
||||
data, err := g.GenSendListReq(NEWLIST)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := `{"chat_id":4342,"text":"List:","reply_markup":{"inline_keyboard":[[{"text":"foo","callback_data":"foo"}],[{"text":"clear checked","callback_data":"clear"}]]}}`
|
||||
expected := `{"chat_id":4342,"text":"List:","disable_notification":true,"reply_markup":{"inline_keyboard":[[{"text":"foo","callback_data":"foo"}],[{"text":"clear checked","callback_data":"clear"}]]}}`
|
||||
if expected != string(data) {
|
||||
t.Fatalf("expected: %s\n got:%s\n", expected, string(data))
|
||||
}
|
||||
|
Reference in New Issue
Block a user