delete old list correctly

This commit is contained in:
Balakrishnan Balasubramanian 2022-12-27 22:47:26 -05:00
parent ab75014a19
commit 37cad43fbf

10
main.go
View File

@ -139,6 +139,10 @@ func handleTextAdded(gl *glist.GList, text string) {
defer gl.Mutex.Unlock() defer gl.Mutex.Unlock()
if count == gl.AllMsgCounter { if count == gl.AllMsgCounter {
sendList(gl, "sendMessage") sendList(gl, "sendMessage")
if gl.MessageID != nil {
deleteMessage(gl.ChatID, *gl.MessageID)
gl.MessageID = nil
}
} }
}) })
} }
@ -146,11 +150,6 @@ func handleTextAdded(gl *glist.GList, text string) {
func handleButtonClick(gl *glist.GList, messageID int, text string) { func handleButtonClick(gl *glist.GList, messageID int, text string) {
gl.Mutex.Lock() gl.Mutex.Lock()
defer gl.Mutex.Unlock() defer gl.Mutex.Unlock()
if gl.MessageID != nil {
if messageID != *gl.MessageID {
go deleteMessage(gl.ChatID, *gl.MessageID)
}
}
gl.MessageID = &messageID gl.MessageID = &messageID
if text == "clear" { if text == "clear" {
gl.ClearChecked() gl.ClearChecked()
@ -161,6 +160,7 @@ func handleButtonClick(gl *glist.GList, messageID int, text string) {
if len(gl.Items) == 0 { if len(gl.Items) == 0 {
deleteMessage(gl.ChatID, messageID) deleteMessage(gl.ChatID, messageID)
gl.MessageID = nil
} else { } else {
sendList(gl, "editMessageText") sendList(gl, "editMessageText")
} }