From 0125519e799dfb2853efe53656ab0a85b1c1bd6d Mon Sep 17 00:00:00 2001 From: yangjunzhou Date: Tue, 21 Apr 2026 16:25:44 +0800 Subject: [PATCH] feat: request thread roots for chat message list Change-Id: I3901b27e70b0e4db506ff199eb03c96fcf98671d --- .gitignore | 1 + shortcuts/im/builders_test.go | 25 ++++++++++++++++++++++++ shortcuts/im/coverage_additional_test.go | 24 +++++++++++++++-------- shortcuts/im/im_chat_messages_list.go | 11 ++++++----- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 822e8f314..90313e480 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ tests/mail/reports/ # Generated / test artifacts +.hammer/ internal/registry/meta_data.json cmd/api/download.bin app.log diff --git a/shortcuts/im/builders_test.go b/shortcuts/im/builders_test.go index cb32d78f8..d44fa0750 100644 --- a/shortcuts/im/builders_test.go +++ b/shortcuts/im/builders_test.go @@ -746,4 +746,29 @@ func TestShortcutDryRunShapes(t *testing.T) { t.Fatalf("ImChatMessageList.DryRun().Format() = %s", formatted) } }) + + t.Run("ImChatMessageList dry run includes root-only query", func(t *testing.T) { + runtime := newTestRuntimeContext(t, map[string]string{ + "chat-id": "oc_123", + "page-size": "20", + "sort": "desc", + }, nil) + formatted := ImChatMessageList.DryRun(context.Background(), runtime).Format() + if !strings.Contains(formatted, "only_thread_root_messages=true") { + t.Fatalf("ImChatMessageList.DryRun().Format() = %s, want only_thread_root_messages=true", formatted) + } + }) +} + +func TestChatMessageListOnlyThreadRootMessagesDryRun(t *testing.T) { + runtime := newTestRuntimeContext(t, map[string]string{ + "chat-id": "oc_123", + "page-size": "20", + "sort": "desc", + }, nil) + + formatted := ImChatMessageList.DryRun(context.Background(), runtime).Format() + if !strings.Contains(formatted, "only_thread_root_messages=true") { + t.Fatalf("ImChatMessageList.DryRun().Format() = %s, want only_thread_root_messages=true", formatted) + } } diff --git a/shortcuts/im/coverage_additional_test.go b/shortcuts/im/coverage_additional_test.go index 5671116b6..52c949ca7 100644 --- a/shortcuts/im/coverage_additional_test.go +++ b/shortcuts/im/coverage_additional_test.go @@ -210,14 +210,15 @@ func TestBuildChatMessageListRequest(t *testing.T) { } want := larkcore.QueryParams{ - "container_id_type": {"chat"}, - "container_id": {"oc_123"}, - "sort_type": {"ByCreateTimeAsc"}, - "page_size": {"50"}, - "card_msg_content_type": {"raw_card_content"}, - "start_time": {"1772294400"}, - "end_time": {"1772467199"}, - "page_token": {"next"}, + "container_id_type": {"chat"}, + "container_id": {"oc_123"}, + "sort_type": {"ByCreateTimeAsc"}, + "page_size": {"50"}, + "only_thread_root_messages": {"true"}, + "card_msg_content_type": {"raw_card_content"}, + "start_time": {"1772294400"}, + "end_time": {"1772467199"}, + "page_token": {"next"}, } if !reflect.DeepEqual(got, want) { t.Fatalf("buildChatMessageListRequest() = %#v, want %#v", got, want) @@ -245,6 +246,13 @@ func TestBuildChatMessageListRequest(t *testing.T) { }) } +func TestChatMessageListOnlyThreadRootMessagesParams(t *testing.T) { + got := buildChatMessageListParams("desc", "20", "oc_123") + if vals := got["only_thread_root_messages"]; !reflect.DeepEqual(vals, []string{"true"}) { + t.Fatalf("only_thread_root_messages = %#v, want true", vals) + } +} + func TestResolveChatIDForMessagesList(t *testing.T) { t.Run("chat passthrough", func(t *testing.T) { runtime := newTestRuntimeContext(t, map[string]string{ diff --git a/shortcuts/im/im_chat_messages_list.go b/shortcuts/im/im_chat_messages_list.go index 9307e6b95..bb247a9b5 100644 --- a/shortcuts/im/im_chat_messages_list.go +++ b/shortcuts/im/im_chat_messages_list.go @@ -172,11 +172,12 @@ func buildChatMessageListParams(sortFlag, pageSizeStr, chatId string) larkcore.Q pageSize = min(max(n, 1), 50) } return larkcore.QueryParams{ - "container_id_type": []string{"chat"}, - "container_id": []string{chatId}, - "sort_type": []string{sortType}, - "page_size": []string{strconv.Itoa(pageSize)}, - "card_msg_content_type": []string{"raw_card_content"}, + "container_id_type": []string{"chat"}, + "container_id": []string{chatId}, + "sort_type": []string{sortType}, + "page_size": []string{strconv.Itoa(pageSize)}, + "card_msg_content_type": []string{"raw_card_content"}, + "only_thread_root_messages": []string{"true"}, } }