Răsfoiți Sursa

Fix slow switching to a channel with large number of messages

Ivan Savenko 1 an în urmă
părinte
comite
5b674baa91

+ 7 - 0
client/globalLobby/GlobalLobbyClient.cpp

@@ -144,6 +144,9 @@ void GlobalLobbyClient::receiveChatHistory(const JsonNode & json)
 		if(lobbyWindowPtr && lobbyWindowPtr->isChannelOpen(channelType, channelName))
 			lobbyWindowPtr->onGameChatMessage(message.displayName, message.messageText, message.timeFormatted, channelType, channelName);
 	}
+
+	if(lobbyWindowPtr && lobbyWindowPtr->isChannelOpen(channelType, channelName))
+		lobbyWindowPtr->refreshChatText();
 }
 
 void GlobalLobbyClient::receiveChatMessage(const JsonNode & json)
@@ -163,7 +166,10 @@ void GlobalLobbyClient::receiveChatMessage(const JsonNode & json)
 
 	auto lobbyWindowPtr = lobbyWindow.lock();
 	if(lobbyWindowPtr)
+	{
 		lobbyWindowPtr->onGameChatMessage(message.displayName, message.messageText, message.timeFormatted, channelType, channelName);
+		lobbyWindowPtr->refreshChatText();
+	}
 
 	CCS->soundh->playSound(AudioPath::builtin("CHAT"));
 }
@@ -270,6 +276,7 @@ void GlobalLobbyClient::receiveInviteReceived(const JsonNode & json)
 
 		lobbyWindowPtr->onGameChatMessage("System", message, time, "player", accountID);
 		lobbyWindowPtr->onInviteReceived(gameRoomID);
+		lobbyWindowPtr->refreshChatText();
 	}
 
 	CCS->soundh->playSound(AudioPath::builtin("CHAT"));

+ 5 - 1
client/globalLobby/GlobalLobbyWindow.cpp

@@ -58,6 +58,8 @@ void GlobalLobbyWindow::doOpenChannel(const std::string & channelType, const std
 	for(const auto & entry : history)
 		onGameChatMessage(entry.displayName, entry.messageText, entry.timeFormatted, channelType, channelName);
 
+	refreshChatText();
+
 	MetaString text;
 	text.appendTextID("vcmi.lobby.header.chat." + channelType);
 	text.replaceRawString(roomDescription);
@@ -133,7 +135,9 @@ void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std:
 	chatMessageFormatted.replaceRawString(message);
 
 	chatHistory += chatMessageFormatted.toString();
-
+}
+void GlobalLobbyWindow::refreshChatText()
+{
 	widget->getGameChat()->setText(chatHistory);
 }
 

+ 1 - 0
client/globalLobby/GlobalLobbyWindow.h

@@ -44,6 +44,7 @@ public:
 	// Callbacks for network packs
 
 	void onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when, const std::string & channelType, const std::string & channelName);
+	void refreshChatText();
 	void onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts);
 	void onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms);
 	void onMatchesHistory(const std::vector<GlobalLobbyRoom> & history);