diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-08-30 16:17:58 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-08-31 17:36:26 +0200 |
commit | 965d38097cbc4d429496622670f23c492324aaf2 (patch) | |
tree | 0ed50188538093332e2b85abb56dee065ae35a21 /worker | |
parent | 2ee7c7f00e0d9895681b6a523e6f92eb93122095 (diff) | |
download | aerc-965d38097cbc4d429496622670f23c492324aaf2.tar.gz |
notmuch: refactor SetFlag
Refactor SetFlag to be more readable by handling the special case of
SeenFlag in a cleaner way. If we invert the operation ('enable') instead
of invert the oldState, we can use the same logic for any tag.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/notmuch/message.go | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index b6d7f54c..f78adeff 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -99,27 +99,20 @@ func (m *Message) SetFlag(flag models.Flags, enable bool) error { break } } + if flag == models.SeenFlag { - oldState = !oldState + // Invert the operation since notmuch uses unread tags instead + // of seen tags + enable = !enable } - // Skip if flag already in correct state. - if oldState == enable { + switch { + case oldState == enable: return nil - } - - if !enable { - if flag == models.SeenFlag { - return m.AddTag("unread") - } else { - return m.RemoveTag(tag) - } - } else { - if flag == models.SeenFlag { - return m.RemoveTag("unread") - } else { - return m.AddTag(tag) - } + case enable: + return m.AddTag(tag) + default: + return m.RemoveTag(tag) } } |