Compare commits
2 Commits
main
...
add-thread
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49f1aa79c0 | ||
|
|
7fc1c962b7 |
@ -7,6 +7,7 @@
|
||||
- Chat: spaces, messages, threads, and DM commands (Workspace only). (#84) — thanks @salmonumbrella.
|
||||
- People: profile lookup, directory search, and relations commands. (#84) — thanks @salmonumbrella.
|
||||
- Calendar: show event timezone and local times; add --weekday output. (#92) — thanks @salmonumbrella.
|
||||
- Gmail: show thread message count in search output. (#99) — thanks @jeanregisser.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@ -83,11 +83,12 @@ func TestExecute_GmailSearch_JSON(t *testing.T) {
|
||||
|
||||
var parsed struct {
|
||||
Threads []struct {
|
||||
ID string `json:"id"`
|
||||
Date string `json:"date"`
|
||||
From string `json:"from"`
|
||||
Subject string `json:"subject"`
|
||||
Labels []string `json:"labels"`
|
||||
ID string `json:"id"`
|
||||
Date string `json:"date"`
|
||||
From string `json:"from"`
|
||||
Subject string `json:"subject"`
|
||||
Labels []string `json:"labels"`
|
||||
MessageCount int `json:"messageCount"`
|
||||
} `json:"threads"`
|
||||
NextPageToken string `json:"nextPageToken"`
|
||||
}
|
||||
@ -100,6 +101,9 @@ func TestExecute_GmailSearch_JSON(t *testing.T) {
|
||||
if parsed.Threads[0].ID != "t1" || parsed.Threads[0].Subject != "Hello" {
|
||||
t.Fatalf("unexpected thread: %#v", parsed.Threads[0])
|
||||
}
|
||||
if parsed.Threads[0].MessageCount != 1 {
|
||||
t.Fatalf("unexpected messageCount: %d", parsed.Threads[0].MessageCount)
|
||||
}
|
||||
if parsed.Threads[0].Date != "2006-01-02 22:04" {
|
||||
t.Fatalf("unexpected date: %q", parsed.Threads[0].Date)
|
||||
}
|
||||
|
||||
@ -121,9 +121,13 @@ func (c *GmailSearchCmd) Run(ctx context.Context, flags *RootFlags) error {
|
||||
w, flush := tableWriter(ctx)
|
||||
defer flush()
|
||||
|
||||
fmt.Fprintln(w, "ID\tDATE\tFROM\tSUBJECT\tLABELS")
|
||||
fmt.Fprintln(w, "ID\tDATE\tFROM\tSUBJECT\tLABELS\tTHREAD")
|
||||
for _, it := range items {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", it.ID, it.Date, it.From, it.Subject, strings.Join(it.Labels, ","))
|
||||
threadInfo := "-"
|
||||
if it.MessageCount > 1 {
|
||||
threadInfo = fmt.Sprintf("[%d msgs]", it.MessageCount)
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", it.ID, it.Date, it.From, it.Subject, strings.Join(it.Labels, ","), threadInfo)
|
||||
}
|
||||
printNextPageHint(u, resp.NextPageToken)
|
||||
return nil
|
||||
@ -316,11 +320,12 @@ func isUnsubscribeLink(raw string) bool {
|
||||
|
||||
// threadItem holds parsed thread metadata for display/JSON output
|
||||
type threadItem struct {
|
||||
ID string `json:"id"`
|
||||
Date string `json:"date,omitempty"`
|
||||
From string `json:"from,omitempty"`
|
||||
Subject string `json:"subject,omitempty"`
|
||||
Labels []string `json:"labels,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Date string `json:"date,omitempty"`
|
||||
From string `json:"from,omitempty"`
|
||||
Subject string `json:"subject,omitempty"`
|
||||
Labels []string `json:"labels,omitempty"`
|
||||
MessageCount int `json:"messageCount,omitempty"` // Number of messages in the thread
|
||||
}
|
||||
|
||||
// fetchThreadDetails fetches thread metadata concurrently with bounded parallelism.
|
||||
@ -372,7 +377,7 @@ func fetchThreadDetails(ctx context.Context, svc *gmail.Service, threads []*gmai
|
||||
return
|
||||
}
|
||||
|
||||
item := threadItem{ID: threadID}
|
||||
item := threadItem{ID: threadID, MessageCount: len(thread.Messages)}
|
||||
if first := firstMessage(thread); first != nil {
|
||||
item.From = sanitizeTab(headerValue(first.Payload, "From"))
|
||||
item.Subject = sanitizeTab(headerValue(first.Payload, "Subject"))
|
||||
@ -413,7 +418,7 @@ func fetchThreadDetails(ctx context.Context, svc *gmail.Service, threads []*gmai
|
||||
for r := range results {
|
||||
if r.err != nil {
|
||||
hasErr = true
|
||||
ordered[r.index] = threadItem{ID: "", Date: "", From: "", Subject: "", Labels: nil}
|
||||
ordered[r.index] = threadItem{ID: "", Date: "", From: "", Subject: "", Labels: nil, MessageCount: 0}
|
||||
continue
|
||||
}
|
||||
ordered[r.index] = r.item
|
||||
|
||||
Loading…
Reference in New Issue
Block a user