aboutsummaryrefslogtreecommitdiff
path: root/lib/msgstore.go
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-07-03 16:10:16 -0400
committerBen Burwell <ben@benburwell.com>2019-07-04 22:03:04 -0400
commit91529df0fecc68d5b0fdbb682529ee545884e7c5 (patch)
tree45b64884521d2df84dc057c99919f03240600344 /lib/msgstore.go
parentf9f523ad59491eda08003ce2ccc6d57d7f19ea1e (diff)
Factor UI models out of the worker message package
Before, the information needed to display different parts of the UI was tightly coupled to the specific messages being sent back and forth to the backend worker. Separating out a models package allows us to be more specific about exactly what a backend is able to and required to provide for the UI.
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r--lib/msgstore.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 09cf31f..19f328d 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -6,6 +6,7 @@ import (
"github.com/emersion/go-imap"
+ "git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/worker/types"
)
@@ -13,7 +14,7 @@ import (
type MessageStore struct {
Deleted map[uint32]interface{}
DirInfo types.DirectoryInfo
- Messages map[uint32]*types.MessageInfo
+ Messages map[uint32]*models.MessageInfo
// Ordered list of known UIDs
Uids []uint32
@@ -106,11 +107,11 @@ func (store *MessageStore) FetchBodyPart(
if !ok {
return
}
- cb(msg.Reader)
+ cb(msg.Part.Reader)
})
}
-func merge(to *types.MessageInfo, from *types.MessageInfo) {
+func merge(to *models.MessageInfo, from *models.MessageInfo) {
if from.BodyStructure != nil {
to.BodyStructure = from.BodyStructure
}
@@ -135,7 +136,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
store.worker.PostAction(&types.FetchDirectoryContents{}, nil)
update = true
case *types.DirectoryContents:
- newMap := make(map[uint32]*types.MessageInfo)
+ newMap := make(map[uint32]*models.MessageInfo)
for _, uid := range msg.Uids {
if msg, ok := store.Messages[uid]; ok {
newMap[uid] = msg
@@ -147,14 +148,14 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
store.Uids = msg.Uids
update = true
case *types.MessageInfo:
- if existing, ok := store.Messages[msg.Uid]; ok && existing != nil {
- merge(existing, msg)
+ if existing, ok := store.Messages[msg.Info.Uid]; ok && existing != nil {
+ merge(existing, msg.Info)
} else {
- store.Messages[msg.Uid] = msg
+ store.Messages[msg.Info.Uid] = msg.Info
}
- if _, ok := store.pendingHeaders[msg.Uid]; msg.Envelope != nil && ok {
- delete(store.pendingHeaders, msg.Uid)
- if cbs, ok := store.headerCallbacks[msg.Uid]; ok {
+ if _, ok := store.pendingHeaders[msg.Info.Uid]; msg.Info.Envelope != nil && ok {
+ delete(store.pendingHeaders, msg.Info.Uid)
+ if cbs, ok := store.headerCallbacks[msg.Info.Uid]; ok {
for _, cb := range cbs {
cb(msg)
}
@@ -162,11 +163,11 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
}
update = true
case *types.FullMessage:
- if _, ok := store.pendingBodies[msg.Uid]; ok {
- delete(store.pendingBodies, msg.Uid)
- if cbs, ok := store.bodyCallbacks[msg.Uid]; ok {
+ if _, ok := store.pendingBodies[msg.Content.Uid]; ok {
+ delete(store.pendingBodies, msg.Content.Uid)
+ if cbs, ok := store.bodyCallbacks[msg.Content.Uid]; ok {
for _, cb := range cbs {
- cb(msg.Reader)
+ cb(msg.Content.Reader)
}
}
}
@@ -283,7 +284,7 @@ func (store *MessageStore) Read(uids []uint32, read bool,
}, cb)
}
-func (store *MessageStore) Selected() *types.MessageInfo {
+func (store *MessageStore) Selected() *models.MessageInfo {
return store.Messages[store.Uids[len(store.Uids)-store.selected-1]]
}