diff options
Diffstat (limited to 'internal/ipc/ipc.go')
| -rw-r--r-- | internal/ipc/ipc.go | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/internal/ipc/ipc.go b/internal/ipc/ipc.go index 5dac21f..c2be080 100644 --- a/internal/ipc/ipc.go +++ b/internal/ipc/ipc.go @@ -18,7 +18,7 @@ import ( // Request is sent by a client to the daemon. type Request struct { - Type string `json:"type"` // "list", "get", "subscribe", "repeat", "intrude", "rules_list", "rules_save", "rules_delete", or "rules_toggle" + Type string `json:"type"` // "list", "get", "subscribe", "repeat", "intrude", "rules_list", "rules_save", "rules_delete", "rules_toggle", "delete_entry", or "clear_history" Limit int `json:"limit,omitempty"` BeforeID int64 `json:"before_id,omitempty"` ID int64 `json:"id,omitempty"` @@ -55,13 +55,14 @@ type Request struct { RuleID int64 `json:"rule_id,omitempty"` RuleEnabled bool `json:"rule_enabled,omitempty"` - // For "set_flagged": ID identifies the history entry. + // For "set_flagged" and "delete_entry": ID identifies the history + // entry. "clear_history" needs no fields at all. Flagged bool `json:"flagged,omitempty"` } // Response is sent by the daemon to a client. type Response struct { - Type string `json:"type"` // "list", "get", "new", "repeat", "rules", "intrude_result", "intrude_done", "status", "flagged", or "error" + Type string `json:"type"` // "list", "get", "new", "repeat", "rules", "intrude_result", "intrude_done", "status", "flagged", "deleted", "cleared", or "error" Entries []store.Summary `json:"entries,omitempty"` // for "list" Detail *EntryDetail `json:"detail,omitempty"` // for "get" and "repeat" New *store.Summary `json:"new,omitempty"` // for "new" (subscribe push) @@ -158,6 +159,40 @@ func (c *Client) SetFlagged(id int64, flagged bool) error { return nil } +// DeleteEntry removes a single history entry. +func (c *Client) DeleteEntry(id int64) error { + c.mu.Lock() + defer c.mu.Unlock() + if err := c.enc.Encode(Request{Type: "delete_entry", ID: id}); err != nil { + return err + } + var resp Response + if err := c.dec.Decode(&resp); err != nil { + return err + } + if resp.Type == "error" { + return errors.New(resp.Error) + } + return nil +} + +// ClearHistory removes every history entry. Rules are untouched. +func (c *Client) ClearHistory() error { + c.mu.Lock() + defer c.mu.Unlock() + if err := c.enc.Encode(Request{Type: "clear_history"}); err != nil { + return err + } + var resp Response + if err := c.dec.Decode(&resp); err != nil { + return err + } + if resp.Type == "error" { + return errors.New(resp.Error) + } + return nil +} + // Status returns basic daemon info for a status bar. func (c *Client) Status() (*StatusMsg, error) { c.mu.Lock() |