diff options
| -rw-r--r-- | changelog.txt | 1 | ||||
| -rw-r--r-- | main.go | 22 |
2 files changed, 9 insertions, 14 deletions
diff --git a/changelog.txt b/changelog.txt index d92fc67..717439d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,4 +2,5 @@ changelog === next ++ removed TelegramResponse from the honkMap + make gethonks retry 5 times before giving up
\ No newline at end of file @@ -98,7 +98,7 @@ func (h *Honk) Check() error { if !ok { return fmt.Errorf("cannot reply to nonexisting telebonk") } - h.replyToID = hi.t.Result.MessageID + h.replyToID = hi.messID default: return fmt.Errorf("unsupported honk type: %s", h.What) } @@ -118,19 +118,19 @@ func (h *Honk) Check() error { func (h *Honk) Decide() honkAction { hi, ok := honkMap[h.XID] if ok { - if hi.t == nil || hi.h.Date.Equal(h.Date) { - h.save(hi.t) // is this wrong? + if hi.messID == 0 || hi.Date.Equal(h.Date) { + h.save(hi.messID) return honkIgnore } - h.messID = hi.t.Result.MessageID return honkEdit } return honkSend } // save records a Honk to a honkMap -func (h *Honk) save(t *TelegramResponse) { - honkMap[h.XID] = honkInfo{h: h, t: t} +func (h *Honk) save(messID int) { + h.messID = messID + honkMap[h.XID] = h } // forget removes a Honk from a honkMap @@ -313,12 +313,6 @@ const ( tgSendDocument = "sendDocument" ) -// A honkInfo stores data for honk that is sent to Telegram. -type honkInfo struct { - h *Honk - t *TelegramResponse -} - // getHonks receives and unmarshals some honks from a Honk instance. func getHonks(after int) ([]*Honk, error) { query := url.Values{} @@ -403,7 +397,7 @@ func init() { } var client = http.DefaultClient -var honkMap = make(map[string]honkInfo) // FIXME: not safe for use by multiple goroutines! +var honkMap = make(map[string]*Honk) // FIXME: not safe for use by multiple goroutines! var now = time.Now() func main() { @@ -442,7 +436,7 @@ func main() { continue } // remember only the first mess' response - honk.save(resp) + honk.save(resp.Result.MessageID) for _, mess := range messes[1:] { if _, err := mess.Send(); err != nil { log.Print(err) // error |
