Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratek committed Apr 3, 2024
1 parent 59218c6 commit 96b3eea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/main/kotlin/com/sourcegraph/cody/chat/AgentChatSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private constructor(
text,
displayText,
)
addMessageAtIndex(humanMessage, index = messages.count(), shouldUpdateTime = true)
addMessageAtIndex(humanMessage, index = messages.count())

val responsePlaceholder =
ChatMessage(
Expand Down Expand Up @@ -220,11 +220,7 @@ private constructor(
}

@RequiresEdt
private fun addMessageAtIndex(
message: ChatMessage,
index: Int,
shouldUpdateTime: Boolean = false
) {
private fun addMessageAtIndex(message: ChatMessage, index: Int) {
val messageToUpdate = messages.getOrNull(index)
if (messageToUpdate != null) {
messages[index] = message
Expand All @@ -233,7 +229,7 @@ private constructor(
}

chatPanel.addOrUpdateMessage(message, index)
HistoryService.getInstance(project).updateChatMessages(internalId, messages, shouldUpdateTime)
HistoryService.getInstance(project).updateChatMessages(internalId, messages)
}

@RequiresEdt
Expand All @@ -257,6 +253,11 @@ private constructor(

ChatMessage(speaker = parsed, message.text)
}
this.messages.addAll(chatMessages)
chatMessages.forEachIndexed { index, chatMessage ->
chatPanel.addOrUpdateMessage(chatMessage, index)
}

val newConnectionId =
restoreChatSession(agent, chatMessages, chatModelProviderFromState, state.internalId!!)
connectionId.getAndSet(newConnectionId)
Expand Down Expand Up @@ -304,8 +305,7 @@ private constructor(
speaker = Speaker.HUMAN,
text = commandId.displayName,
),
index = chatSession.messages.count(),
shouldUpdateTime = true)
index = chatSession.messages.count())
chatSession.addMessageAtIndex(
message =
ChatMessage(
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/com/sourcegraph/cody/history/HistoryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ class HistoryService(private val project: Project) :
}

@Synchronized
fun updateChatMessages(
internalId: String,
chatMessages: List<ChatMessage>,
shouldUpdateTime: Boolean
) {
fun updateChatMessages(internalId: String, chatMessages: List<ChatMessage>) {
val found = getOrCreateChat(internalId)
found.messages = chatMessages.map(::convertToMessageState).toMutableList()
if (shouldUpdateTime) {
if (found.messages.size < chatMessages.size) {
found.setUpdatedTimeAt(LocalDateTime.now())
}
found.messages = chatMessages.map(::convertToMessageState).toMutableList()
synchronized(listeners) { listeners.forEach { it(found) } }
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/CodyBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ UpgradeToCodyProNotification.title.upgrade=You've used up your autocompletes for
UpgradeToCodyProNotification.title.explain=Thank you for using Cody so heavily today!
UpgradeToCodyProNotification.content.upgrade=\
<html>\
You''ve used all autocomplete suggestions for the month. \
You've used all autocomplete suggestions for the month. \
Upgrade to Cody Pro for unlimited autocompletes, chats, and commands.<br><br>\
(Already upgraded to Pro? Restart your IDE for changes to take effect)\
</html>
Expand Down

0 comments on commit 96b3eea

Please sign in to comment.