Skip to content

Commit

Permalink
Fix remove me command
Browse files Browse the repository at this point in the history
  • Loading branch information
taras-by committed Dec 31, 2019
1 parent 434151a commit ec8d4d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions store/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ func (s *Storage) DeleteAll(chatId int64) error {
return errors.Wrapf(err, "Failed to delete participants")
}

func (s *Storage) Find(key string, chatId int64) (participant Participant, err error) {
func (s *Storage) Find(p Participant) (participant Participant, err error) {
err = s.db.View(func(tx *bolt.Tx) (err error) {
var chatBkt *bolt.Bucket

if chatBkt, err = s.getChatBucket(tx, chatId); err != nil {
if chatBkt, err = s.getChatBucket(tx, p.ChatId); err != nil {
return err
}

value := chatBkt.Get([]byte(key))
value := chatBkt.Get([]byte(p.Id()))
if value == nil {
return errors.Errorf("no value for %s", key)
return errors.Errorf("no value for %s", p.Id())
}

if err := json.Unmarshal(value, &participant); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion telegram/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,16 @@ func (h *MessageHandler) addByNumber(c conversation) {

func (h *MessageHandler) removeMe(c conversation) {

participant, err := h.Storage.Find(strconv.Itoa(c.message.From.ID), c.chatId)
participant, err := h.Storage.Find(store.Participant{
User: store.User{
Id: strconv.Itoa(c.message.From.ID),
UserName: c.message.From.UserName,
FirstName: c.message.From.FirstName,
LastName: c.message.From.LastName,
Type: store.UserTelegram,
},
ChatId: c.chatId,
})
if err != nil {
participant, err = h.Storage.FindByLink("@"+c.message.From.UserName, c.chatId)
if err != nil {
Expand Down

0 comments on commit ec8d4d2

Please sign in to comment.