[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
+12
View File
@@ -205,6 +205,8 @@ type feishuEvent struct {
type feishuMessage struct {
MessageID string `json:"message_id"`
RootID string `json:"root_id"`
ParentID string `json:"parent_id"`
MessageType string `json:"message_type"`
ChatType string `json:"chat_type"`
ChatID string `json:"chat_id"`
@@ -263,6 +265,12 @@ func (a *Adapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, error) {
}
msg := eventBody.Event.Message
// Compute thread ID: use root_id for threaded replies, or message_id for top-level messages.
threadID := msg.RootID
if threadID == "" {
threadID = msg.MessageID
}
// Determine chat type
chatType := im.ChatTypeDirect
chatID := ""
@@ -308,6 +316,7 @@ func (a *Adapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, error) {
ChatType: chatType,
Content: strings.TrimSpace(content),
MessageID: msg.MessageID,
ThreadID: threadID,
}, nil
case "file":
@@ -328,6 +337,7 @@ func (a *Adapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, error) {
ChatID: chatID,
ChatType: chatType,
MessageID: msg.MessageID,
ThreadID: threadID,
FileKey: fileContent.FileKey,
FileName: fileContent.FileName,
}, nil
@@ -349,6 +359,7 @@ func (a *Adapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, error) {
ChatID: chatID,
ChatType: chatType,
MessageID: msg.MessageID,
ThreadID: threadID,
FileKey: imageContent.ImageKey,
FileName: imageContent.ImageKey + ".png",
}, nil
@@ -411,6 +422,7 @@ func (a *Adapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, error) {
ChatType: chatType,
Content: content,
MessageID: msg.MessageID,
ThreadID: threadID,
}, nil
default:
+53
View File
@@ -0,0 +1,53 @@
package feishu
import "testing"
func TestFeishuThreadID_ThreadedReply(t *testing.T) {
// Simulate: message is a reply in a thread (root_id is set)
msg := &feishuMessage{
MessageID: "msg-reply-1",
RootID: "msg-root-1",
ParentID: "msg-parent-1",
}
threadID := msg.RootID
if threadID == "" {
threadID = msg.MessageID
}
if threadID != "msg-root-1" {
t.Errorf("threadID = %q, want %q", threadID, "msg-root-1")
}
}
func TestFeishuThreadID_TopLevelMessage(t *testing.T) {
// Simulate: top-level message (root_id is empty)
msg := &feishuMessage{
MessageID: "msg-top-1",
RootID: "",
ParentID: "",
}
threadID := msg.RootID
if threadID == "" {
threadID = msg.MessageID
}
if threadID != "msg-top-1" {
t.Errorf("threadID = %q, want %q (should use MessageID as fallback)", threadID, "msg-top-1")
}
}
func TestFeishuMessageStruct_JSONFields(t *testing.T) {
// Verify the struct fields exist and have correct zero values
msg := feishuMessage{}
if msg.RootID != "" {
t.Errorf("RootID zero value = %q, want empty", msg.RootID)
}
if msg.ParentID != "" {
t.Errorf("ParentID zero value = %q, want empty", msg.ParentID)
}
if msg.MessageID != "" {
t.Errorf("MessageID zero value = %q, want empty", msg.MessageID)
}
}