[NELO-1102] feat(im): add thread-based session mode for IM channels

Add session_mode ("user" | "thread") to IM channel config. In thread
mode, each message thread gets its own session, enabling multi-user
collaboration within the same thread context.

Backend:
- Add SessionMode type constants and validation
- Add ThreadID field to IncomingMessage and ChannelSession
- Split resolveSession into resolveUserSession/resolveThreadSession
- Update makeUserKey to include threadID only in thread mode
- Extract ThreadID in Slack, Mattermost, Feishu, Telegram adapters
- Add message_thread_id to Telegram SendReply/StartStream for Forums
- DB migration 000028: session_mode column + thread_id column + index

Frontend:
- Add session_mode radio group to IMChannelPanel dialog
- Auto-reset session_mode when switching to non-thread platform
- Show thread badge on channel card for thread-mode channels
- Add i18n keys for en-US, ko-KR, zh-CN, ru-RU
This commit is contained in:
ochan.kwon
2026-03-27 20:49:10 +09:00
committed by lyingbug
parent 930a953f41
commit 2d5782992e
22 changed files with 1015 additions and 22 deletions
+1
View File
@@ -70,6 +70,7 @@ func parseIncomingMessage(user, channel, text, ts string, chatType im.ChatType,
ChatType: chatType,
Content: strings.TrimSpace(content),
MessageID: ts,
ThreadID: ts,
}
if len(files) > 0 {
+70
View File
@@ -0,0 +1,70 @@
package slack
import (
"testing"
"github.com/Tencent/WeKnora/internal/im"
slacklib "github.com/slack-go/slack"
)
func TestParseIncomingMessage_ThreadID(t *testing.T) {
tests := []struct {
name string
ts string
wantThreadID string
wantMessageID string
}{
{
name: "top-level message uses own timestamp",
ts: "1234567890.123456",
wantThreadID: "1234567890.123456",
wantMessageID: "1234567890.123456",
},
{
name: "threaded reply uses thread_ts",
ts: "1234567890.000001",
wantThreadID: "1234567890.000001",
wantMessageID: "1234567890.000001",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msg := parseIncomingMessage("U123", "C456", "hello", tt.ts, im.ChatTypeGroup, nil)
if msg.ThreadID != tt.wantThreadID {
t.Errorf("ThreadID = %q, want %q", msg.ThreadID, tt.wantThreadID)
}
if msg.MessageID != tt.wantMessageID {
t.Errorf("MessageID = %q, want %q", msg.MessageID, tt.wantMessageID)
}
})
}
}
func TestParseIncomingMessage_ThreadID_WithFiles(t *testing.T) {
files := []slacklib.File{
{ID: "F123", Name: "test.pdf", Size: 1024, Mimetype: "application/pdf"},
}
msg := parseIncomingMessage("U123", "C456", "", "1234567890.999", im.ChatTypeDirect, files)
if msg.ThreadID != "1234567890.999" {
t.Errorf("ThreadID = %q, want %q", msg.ThreadID, "1234567890.999")
}
if msg.MessageType != im.MessageTypeFile {
t.Errorf("MessageType = %q, want %q", msg.MessageType, im.MessageTypeFile)
}
}
func TestParseIncomingMessage_MentionStripping(t *testing.T) {
// Ensure mention stripping doesn't affect ThreadID
msg := parseIncomingMessage("U123", "C456", "<@U999> hello world", "ts-123", im.ChatTypeGroup, nil)
if msg.ThreadID != "ts-123" {
t.Errorf("ThreadID = %q, want %q", msg.ThreadID, "ts-123")
}
if msg.Content != "hello world" {
t.Errorf("Content = %q, want %q", msg.Content, "hello world")
}
}