52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
|
|
// Code scaffolded by goctl. Safe to edit.
|
||
|
|
// goctl 1.10.1
|
||
|
|
|
||
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"img_infinite_canvas/internal/svc"
|
||
|
|
"img_infinite_canvas/internal/types"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CandaChatHistoryLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCandaChatHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CandaChatHistoryLogic {
|
||
|
|
return &CandaChatHistoryLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CandaChatHistoryLogic) CandaChatHistory(req *types.CandaChatHistoryRequest) (resp *types.CandaChatHistoryResponse, err error) {
|
||
|
|
replay, err := l.svcCtx.DesignService.ReplayHistory(l.ctx, req.ProjectId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items := make([]types.CandaChatHistoryItem, 0, len(replay.Messages))
|
||
|
|
for _, message := range replay.Messages {
|
||
|
|
threadID := message.ThreadID
|
||
|
|
if threadID == "" {
|
||
|
|
threadID = req.ThreadId
|
||
|
|
}
|
||
|
|
if req.ThreadId != "" && threadID != req.ThreadId {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
items = append(items, toCandaChatHistoryItem(message, req.ProjectId, threadID))
|
||
|
|
}
|
||
|
|
|
||
|
|
return &types.CandaChatHistoryResponse{
|
||
|
|
Code: 0,
|
||
|
|
Message: "Successfully got history view for " + req.ThreadId,
|
||
|
|
Data: items,
|
||
|
|
}, nil
|
||
|
|
}
|