Skip to content

Commit

Permalink
Refresh chat list fully when blocking/unblocking
Browse files Browse the repository at this point in the history
  • Loading branch information
thomotron committed Jan 22, 2023
1 parent 885097d commit 04bb062
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions Client/Source/GUI/Compound Widgets/ChatMessageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ChatMessageList()
// TODO: Unsubscribe from the event when being destroyed (not that it will be until Phinix shuts down)
Client.Instance.OnChatMessageReceived += ChatMessageReceivedEventHandler;
Client.Instance.OnUserDisplayNameChanged += UserChangedEventHandler;
Client.Instance.OnBlockedUsersChanged += BlockedUsersChangedEventHandler;
Client.Instance.OnBlockedUsersChanged += (s, e) => ReplaceWithBuffer();
Client.Instance.OnChatSync += (s, e) => ReplaceWithBuffer();
Client.Instance.OnDisconnect += (s, e) => Clear();
Client.Instance.OnChatMessageLimitChanged += (s, e) => ReplaceWithBuffer();
Expand Down Expand Up @@ -190,8 +190,8 @@ public void ReplaceWithBuffer()
{
Clear();

// Append the buffered messages to the list
messages.AddRange(Client.Instance.GetChatMessages().TakeLast(Client.Instance.ChatMessageLimit));
// Append the buffered messages to the list, filtering out any blocked users and trimming it to the limit
messages.AddRange(Client.Instance.GetChatMessages().Where(m => !Client.Instance.BlockedUsers.Contains(m.SenderUuid)).TakeLast(Client.Instance.ChatMessageLimit));
messagesChanged = true;
}
}
Expand Down Expand Up @@ -223,26 +223,6 @@ private void UserChangedEventHandler(object sender, UserDisplayNameChangedEventA
}
}

private void BlockedUsersChangedEventHandler(object sender, BlockedUsersChangedEventArgs args)
{
lock (messagesLock)
{
if (args.IsBlocked)
{
// Remove all their messages from the list
messages.RemoveAll(m => m.User.Uuid == args.Uuid);
}
else
{
// Pull in the chat buffer to repopulate messages from the now-unblocked user
// TODO: Make this less expensive
ReplaceWithBuffer();
}

messagesChanged = true;
}
}

private void recalculateMessageRects(Rect inRect)
{
// Clear the existing cache
Expand Down

0 comments on commit 04bb062

Please sign in to comment.