GODT-1499: Remove message from DB once is not on server any more

This commit is contained in:
Jakub
2022-01-18 18:23:00 +01:00
committed by Jakub Cuth
parent a3d2df9d38
commit 8e0693ab03
9 changed files with 107 additions and 5 deletions

View File

@ -234,3 +234,19 @@ func (ctl *Controller) LockEvents(string) {}
// UnlockEvents doesn't needs to be implemented for fakeAPI.
func (ctl *Controller) UnlockEvents(string) {}
func (ctl *Controller) RemoveUserMessageWithoutEvent(username string, messageID string) error {
msgs, ok := ctl.messagesByUsername[username]
if !ok {
return nil
}
for i, message := range msgs {
if message.ID == messageID {
ctl.messagesByUsername[username] = append(msgs[:i], msgs[i+1:]...)
return nil
}
}
return errors.New("message not found")
}

View File

@ -37,7 +37,7 @@ func (api *FakePMAPI) GetMessage(_ context.Context, apiID string) (*pmapi.Messag
if msg := api.getMessage(apiID); msg != nil {
return msg, nil
}
return nil, fmt.Errorf("message %s not found", apiID)
return nil, pmapi.ErrUnprocessableEntity{OriginalError: fmt.Errorf("message %s not found", apiID)}
}
// ListMessages does not implement following filters: