Skip to content

Commit

Permalink
Fix description caching and suggestions (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaBernstein authored Sep 15, 2022
1 parent 0d4de82 commit 8320b1d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions bot/transactionBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type Tx interface {
IsDone() bool
Debug() string
NextHint(*crud.Repo, *tb.Message) *Hint
EnrichHint(r *crud.Repo, m *tb.Message, i Input) *Hint
EnrichHint(r *crud.Repo, m *tb.Message, i *Input) *Hint
FillTemplate(currency, tag string, tzOffset int) (string, error)
CacheData() map[string]string

Expand Down Expand Up @@ -413,7 +413,7 @@ func (tx *SimpleTx) NextHint(r *crud.Repo, m *tb.Message) *Hint {
crud.LogDbf(r, TRACE, m, "During message building an error ocurred: "+err.Error())
return nil
}
return tx.EnrichHint(r, m, Input{
return tx.EnrichHint(r, m, &Input{
key: nextField.FieldName,
hint: &Hint{
Prompt: message,
Expand All @@ -423,18 +423,18 @@ func (tx *SimpleTx) NextHint(r *crud.Repo, m *tb.Message) *Hint {
})
}

func (tx *SimpleTx) EnrichHint(r *crud.Repo, m *tb.Message, i Input) *Hint {
func (tx *SimpleTx) EnrichHint(r *crud.Repo, m *tb.Message, i *Input) *Hint {
crud.LogDbf(r, TRACE, m, "Enriching hint (%s).", i.key)
if i.key == c.FIELD_DESCRIPTION {
return tx.hintDescription(r, m, i.hint)
return tx.hintDescription(r, m, i)
}
if i.key == c.FIELD_ACCOUNT {
return tx.hintAccount(r, m, i)
}
return i.hint
}

func (tx *SimpleTx) hintAccount(r *crud.Repo, m *tb.Message, i Input) *Hint {
func (tx *SimpleTx) hintAccount(r *crud.Repo, m *tb.Message, i *Input) *Hint {
accountFQSpecifier := i.field.FieldIdentifierForValue()
crud.LogDbf(r, TRACE, m, "Enriching hint: '%s'", accountFQSpecifier)
var (
Expand All @@ -450,13 +450,14 @@ func (tx *SimpleTx) hintAccount(r *crud.Repo, m *tb.Message, i Input) *Hint {
return i.hint
}

func (tx *SimpleTx) hintDescription(r *crud.Repo, m *tb.Message, h *Hint) *Hint {
res, err := r.GetCacheHints(m, c.FqCacheKey(c.FIELD_DESCRIPTION))
func (tx *SimpleTx) hintDescription(r *crud.Repo, m *tb.Message, i *Input) *Hint {
accountFQSpecifier := i.field.FieldIdentifierForValue()
res, err := r.GetCacheHints(m, accountFQSpecifier)
if err != nil {
crud.LogDbf(r, ERROR, m, "Error occurred getting cached hint (hintDescription): %s", err.Error())
}
h.KeyboardOptions = res
return h
i.hint.KeyboardOptions = res
return i.hint
}

func (tx *SimpleTx) IsDone() bool {
Expand Down

0 comments on commit 8320b1d

Please sign in to comment.