MCPcopy Index your code
hub / github.com/coder/coder / RenameChatTitle

Method RenameChatTitle

coderd/x/chatd/chatd.go:3075–3103  ·  view source on GitHub ↗

RenameChatTitle persists a user-supplied chat title.

(
	ctx context.Context,
	chat database.Chat,
	newTitle string,
)

Source from the content-addressed store, hash-verified

3073
3074// RenameChatTitle persists a user-supplied chat title.
3075func (p *Server) RenameChatTitle(
3076 ctx context.Context,
3077 chat database.Chat,
3078 newTitle string,
3079) (updated database.Chat, wrote bool, err error) {
3080 //nolint:gocritic // Lock release needs chatd-scoped writes.
3081 chatdCtx := dbauthz.AsChatd(ctx)
3082 if err := p.acquireManualTitleLock(ctx, chat.ID); err != nil {
3083 return database.Chat{}, false, err
3084 }
3085 defer p.releaseManualTitleLock(chatdCtx, chat.ID)
3086
3087 currentChat, err := p.db.GetChatByID(ctx, chat.ID)
3088 if err != nil {
3089 return database.Chat{}, false, xerrors.Errorf("get chat for rename: %w", err)
3090 }
3091 if newTitle == currentChat.Title {
3092 return currentChat, false, nil
3093 }
3094
3095 updatedChat, err := p.db.UpdateChatTitleByID(ctx, database.UpdateChatTitleByIDParams{
3096 ID: chat.ID,
3097 Title: newTitle,
3098 })
3099 if err != nil {
3100 return database.Chat{}, false, xerrors.Errorf("update chat title: %w", err)
3101 }
3102 return updatedChat, true, nil
3103}
3104
3105// PublishTitleChange broadcasts a title_change event for the given chat.
3106func (p *Server) PublishTitleChange(chat database.Chat) {

Callers 2

TestRenameChatTitleFunction · 0.95
applyChatTitleUpdateMethod · 0.80

Calls 6

AsChatdFunction · 0.92
GetChatByIDMethod · 0.65
UpdateChatTitleByIDMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

TestRenameChatTitleFunction · 0.76