RenameChatTitle persists a user-supplied chat title.
( ctx context.Context, chat database.Chat, newTitle string, )
| 3073 | |
| 3074 | // RenameChatTitle persists a user-supplied chat title. |
| 3075 | func (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. |
| 3106 | func (p *Server) PublishTitleChange(chat database.Chat) { |