Test passed: messages received in order

This commit is contained in:
Levi Neely 2026-02-17 14:47:25 +01:00
parent fa127f1d44
commit 3f3b5e9f69
2 changed files with 13 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package mailbox
import (
"encoding/json"
"fmt"
"time"
)
@ -59,11 +60,5 @@ func FromJSON(data []byte) (*Message, error) {
}
func generateID() string {
// Simple ID generation - reuse existing ID generation logic
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
b := make([]byte, 8)
for i := range b {
b[i] = chars[time.Now().UnixNano()%int64(len(chars))]
}
return "msg-" + string(b)
return fmt.Sprintf("msg-%d", time.Now().Unix())
}

View File

@ -14,6 +14,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"sync"
@ -816,6 +817,11 @@ func (s *Server) readDir(path string, offset uint64, count uint32) []byte {
messages = mailMgr.GetCompleted("user")
}
// Sort messages by ID (which is now timestamp-based)
sort.Slice(messages, func(i, j int) bool {
return messages[i].ID < messages[j].ID
})
for _, msg := range messages {
data, _ := msg.ToJSON()
dirs = append(dirs, plan9.Dir{
@ -891,6 +897,11 @@ func (s *Server) readDir(path string, offset uint64, count uint32) []byte {
messages = mailMgr.GetCompleted(sessID)
}
// Sort messages by ID (which is now timestamp-based)
sort.Slice(messages, func(i, j int) bool {
return messages[i].ID < messages[j].ID
})
for _, msg := range messages {
data, _ := msg.ToJSON()
dirs = append(dirs, plan9.Dir{