Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update updatedAtTime only on sending a message instead of receiving it (fixes #1248) #1278

Merged
merged 6 commits into from
Apr 5, 2024

Conversation

mkondratek
Copy link
Contributor

@mkondratek mkondratek commented Apr 3, 2024

Fixes #1248.

Test plan

See the issue for specific steps.

  1. Having two chats in the Chat History panel.
  2. Restart IDE.
  3. Go to Chat History panel and restore the older one.
  4. Go to Chat History

Expected:
The restored chat remains as the last one in the list (it is not bumped to the top).

@mkondratek mkondratek self-assigned this Apr 3, 2024
@mkondratek mkondratek changed the title Rename HistoryTree.kt to ChatHistoryPanel.kt Update updatedAtTime only on sending a message instead of receiving it (fixes #1248) Apr 3, 2024
@@ -41,7 +41,7 @@ import javax.swing.tree.DefaultTreeModel
import javax.swing.tree.TreePath
import javax.swing.tree.TreeSelectionModel

class HistoryTree(
class ChatHistoryPanel(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTOE: I piggyback this change.

This class is a panel actually, it extends SimpleToolWindowPanel.

val found = getOrCreateChat(internalId)
found.messages = chatMessages.map(::convertToMessageState).toMutableList()
if (chatMessages.lastOrNull()?.speaker == Speaker.HUMAN) {
if (shouldUpdateTime) {
Copy link
Contributor

@pkukielka pkukielka Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get all that changes, and they are correct, but I do not find that variable passing particularly clean.
I was thinking if we can simplify it somehow and I get one idea:
Shouldn't we update only, if found.messages count increased compared to what already is in the history? What would be one-line local check in this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sounds good!

@@ -253,6 +253,7 @@ private constructor(

ChatMessage(speaker = parsed, message.text)
}
this.messages.addAll(chatMessages)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed and reasonable too. Let's add all these message in advance. addMessageAtIndex will not even execute in receiveMessage as we check the condition: sessionMessage != incomingMessage.

@mkondratek mkondratek force-pushed the mkondratek/chore/rename-to-chat-history-panel branch from f06dd71 to 96b3eea Compare April 3, 2024 17:01
@@ -140,7 +140,9 @@ class HistoryTree(
}
} else {
val currentPeriodText = DurationGroupFormatter.format(chat.getUpdatedTimeAt())
val currentPeriod = root.periods().find { it.periodText == currentPeriodText } ?: return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bug 🐛

@mkondratek mkondratek force-pushed the mkondratek/chore/rename-to-chat-history-panel branch from 24fbc1a to 65ac961 Compare April 3, 2024 21:20
Copy link
Contributor

@pkukielka pkukielka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mkondratek mkondratek merged commit 167f970 into main Apr 5, 2024
5 checks passed
@mkondratek mkondratek deleted the mkondratek/chore/rename-to-chat-history-panel branch April 5, 2024 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JetBrains: Opening a chat from chat history triggers same chat and it is showing as recently asked
2 participants