aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-21 11:31:04 +0100
committerRobin Jarry <robin@jarry.cc>2023-01-04 22:57:31 +0100
commit5677f93ff8e0f212be112a110fcfe09663c84f98 (patch)
tree9f47f430b312d1f0dc1acdd3735cfd76ad21e0f0 /lib
parent36fded03e762da97edde61559c8bf60d5749d6a2 (diff)
downloadaerc-5677f93ff8e0f212be112a110fcfe09663c84f98.tar.gz
model: change flags array to bitmask
Using a list of integers is not optimal. Use a bit mask instead. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/emlview.go4
-rw-r--r--lib/format/format.go63
-rw-r--r--lib/msgstore.go15
3 files changed, 29 insertions, 53 deletions
diff --git a/lib/emlview.go b/lib/emlview.go
index e0dcb436..ab3ce87e 100644
--- a/lib/emlview.go
+++ b/lib/emlview.go
@@ -27,8 +27,8 @@ func (fm *EmlMessage) Labels() ([]string, error) {
return nil, nil
}
-func (fm *EmlMessage) ModelFlags() ([]models.Flag, error) {
- return []models.Flag{models.SeenFlag}, nil
+func (fm *EmlMessage) ModelFlags() (models.Flags, error) {
+ return models.SeenFlag, nil
}
// NewEmlMessageView provides a MessageView for a full message that is not
diff --git a/lib/format/format.go b/lib/format/format.go
index 346702c6..3f00fe18 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -294,53 +294,36 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
}
case 'Z':
// calculate all flags
- readReplyFlag := ""
- delFlag := ""
- flaggedFlag := ""
- markedFlag := ""
- hasattachment := ""
- seen := false
- recent := false
- answered := false
- for _, flag := range ctx.MsgInfo.Flags {
- switch flag {
- case models.SeenFlag:
- seen = true
- case models.RecentFlag:
- recent = true
- case models.AnsweredFlag:
- answered = true
- }
- if flag == models.DeletedFlag {
- delFlag = "D"
- // TODO: check if attachments
- }
- if flag == models.FlaggedFlag {
- flaggedFlag = "!"
- }
- // TODO: check gpg stuff
- }
- if seen {
- if answered {
- readReplyFlag = "r" // message has been replied to
- }
- } else {
- if recent {
- readReplyFlag = "N" // message is new
- } else {
- readReplyFlag = "O" // message is old
- }
+ flags := ctx.MsgInfo.Flags
+ f := ""
+
+ switch {
+ case flags.Has(models.SeenFlag | models.AnsweredFlag):
+ f += "r" // message has been replied to
+ case flags.Has(models.SeenFlag):
+ break
+ case flags.Has(models.RecentFlag):
+ f += "N" // message is new
+ default:
+ f += "O" // message is old
}
- if ctx.MsgIsMarked {
- markedFlag = "*"
+ if flags.Has(models.DeletedFlag) {
+ f += "D"
}
for _, bS := range ctx.MsgInfo.BodyStructure.Parts {
if strings.ToLower(bS.Disposition) == "attachment" {
- hasattachment = iconAttachment
+ f += iconAttachment
+ break
}
}
+ if flags.Has(models.FlaggedFlag) {
+ f += "!"
+ }
+ if ctx.MsgIsMarked {
+ f += "*"
+ }
retval = append(retval, '4', 's')
- args = append(args, readReplyFlag+delFlag+flaggedFlag+markedFlag+hasattachment)
+ args = append(args, f)
// Move the below cases to proper alphabetical positions once
// implemented
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 8b2d0419..d2851db2 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -269,15 +269,8 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
store.Unlock()
store.fetchFlags()
}
- seen := false
- recent := false
- for _, flag := range msg.Info.Flags {
- if flag == models.RecentFlag {
- recent = true
- } else if flag == models.SeenFlag {
- seen = true
- }
- }
+ seen := msg.Info.Flags.Has(models.RecentFlag)
+ recent := msg.Info.Flags.Has(models.SeenFlag)
if !seen && recent {
store.triggerNewEmail(msg.Info)
}
@@ -563,12 +556,12 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
})
}
-func (store *MessageStore) Flag(uids []uint32, flag models.Flag,
+func (store *MessageStore) Flag(uids []uint32, flags models.Flags,
enable bool, cb func(msg types.WorkerMessage),
) {
store.worker.PostAction(&types.FlagMessages{
Enable: enable,
- Flag: flag,
+ Flags: flags,
Uids: uids,
}, cb)
}