feat(sessions): add keyword search, user-scoped pinning, and IM source visibility
Sessions today are a flat list ordered by updated_at. Two gaps showed up in practice: - Users cannot find specific chats as the list grows beyond a screen. - IM-created sessions (WeCom/Feishu/Slack/...) are indistinguishable: every title was "IM-<platform>" or "IM-<platform>-<username>" and the list API hid the underlying im_channel_sessions mapping, so admins had no way to tell which Feishu group a session came from. Backend - Migration 000039 adds sessions.user_id (owner), is_pinned, pinned_at plus a composite index for the list query. Existing rows keep user_id NULL and stay visible at the tenant level for backward compatibility. - CreateSession now writes the caller's user_id from auth context. - GET /sessions accepts keyword / source / agent_id. When any filter is set, the response switches to enriched items that LEFT JOIN im_channel_sessions and expose im_platform / im_chat_id / im_thread_id / im_user_id / im_agent_id / im_channel_id. No filters => legacy shape, existing clients unaffected. - Ordering: is_pinned DESC, pinned_at DESC NULLS LAST, updated_at DESC. - POST/DELETE /sessions/:id/pin for user-scoped pin/unpin. - IM session titles: "[platform] <user|chat|thread>" with short ID suffixes so group/DM/thread sessions are visually distinct without needing a round-trip to fetch a display name from the IM adapter. Frontend - Search input debounced at 300ms drives the keyword filter. - Pinned chats render in a dedicated group above the time-based groups, with a pin icon and a pin/unpin entry in the per-chat dropdown. - IM chats get a short [platform] badge in the list. - Pin toggle is optimistic and guards against double-clicks. - zh/en/ko/ru i18n keys added for the new strings.
This commit is contained in:
@@ -169,6 +169,47 @@ func (s *sessionService) GetPagedSessionsByTenant(ctx context.Context,
|
||||
return types.NewPageResult(total, pagination, sessions), nil
|
||||
}
|
||||
|
||||
// ListSessions returns a page of sessions with search/source filters, scoped to
|
||||
// the current tenant (and user when the caller is an authenticated user).
|
||||
func (s *sessionService) ListSessions(
|
||||
ctx context.Context, query *types.SessionListQuery,
|
||||
) (*types.PageResult, error) {
|
||||
if query == nil {
|
||||
query = &types.SessionListQuery{}
|
||||
}
|
||||
query.TenantID = types.MustTenantIDFromContext(ctx)
|
||||
if uid, ok := types.UserIDFromContext(ctx); ok {
|
||||
query.UserID = uid
|
||||
}
|
||||
|
||||
items, total, err := s.sessionRepo.QueryPaged(ctx, query)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||
"tenant_id": query.TenantID,
|
||||
"user_id": query.UserID,
|
||||
"keyword": query.Keyword,
|
||||
"source": query.Source,
|
||||
"agent_id": query.AgentID,
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pagination := &types.Pagination{Page: query.Page, PageSize: query.PageSize}
|
||||
return types.NewPageResult(total, pagination, items), nil
|
||||
}
|
||||
|
||||
// SetSessionPinned pins or unpins a session for the current user scope.
|
||||
func (s *sessionService) SetSessionPinned(
|
||||
ctx context.Context, sessionID string, pinned bool,
|
||||
) error {
|
||||
if sessionID == "" {
|
||||
return errors.New("session id is required")
|
||||
}
|
||||
tenantID := types.MustTenantIDFromContext(ctx)
|
||||
userID, _ := types.UserIDFromContext(ctx)
|
||||
return s.sessionRepo.SetPinned(ctx, tenantID, userID, sessionID, pinned)
|
||||
}
|
||||
|
||||
// UpdateSession updates an existing session's properties
|
||||
func (s *sessionService) UpdateSession(ctx context.Context, session *types.Session) error {
|
||||
// Validate session ID
|
||||
|
||||
Reference in New Issue
Block a user