Disable notificaiton for new list
This commit is contained in:
parent
0b1d455bc5
commit
347823b0bd
@ -109,6 +109,13 @@ 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"`
|
||||
@ -118,6 +125,7 @@ type newListReq 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))
|
||||
}
|
||||
|
8
main.go
8
main.go
@ -177,7 +177,7 @@ func handleTextAdded(gl *glist.GList, text string) {
|
||||
gl.Mutex.Lock()
|
||||
defer gl.Mutex.Unlock()
|
||||
if count == gl.AllMsgCounter {
|
||||
resp := sendList(gl, "sendMessage")
|
||||
resp := sendList(gl, glist.NEWLIST)
|
||||
if resp == nil {
|
||||
return
|
||||
}
|
||||
@ -219,13 +219,13 @@ func handleButtonClick(gl *glist.GList, messageID int, text string) {
|
||||
deleteMessage(gl.ChatID, messageID)
|
||||
gl.MessageID = nil
|
||||
} else {
|
||||
sendList(gl, "editMessageText")
|
||||
sendList(gl, glist.EDITLIST)
|
||||
}
|
||||
}
|
||||
|
||||
func sendList(gl *glist.GList, method string) []byte {
|
||||
func sendList(gl *glist.GList, method glist.SendMethod) []byte {
|
||||
url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", apiToken, method)
|
||||
sendMsgReq, err := gl.GenSendListReq()
|
||||
sendMsgReq, err := gl.GenSendListReq(method)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user