Skip to content

Commit

Permalink
Small TypingIndicator tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0maks committed Apr 3, 2023
1 parent bddb102 commit 16b53bf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Content.Client/Chat/TypingIndicator/TypingIndicatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class TypingIndicatorSystem : SharedTypingIndicatorSystem
private readonly TimeSpan _typingTimeout = TimeSpan.FromSeconds(2);
private TimeSpan _lastTextChange;
private TypingIndicatorState State;
private bool isChatBoxActive;

public override void Initialize()
{
Expand All @@ -29,17 +30,19 @@ public void ClientFocusChat()
if (!_cfg.GetCVar(CCVars.ChatShowTypingIndicator))
return;

isChatBoxActive = true;

// client typed something - show typing indicator
ClientUpdateTyping(TypingIndicatorState.Thinking);
_lastTextChange = _time.CurTime;
}

public void ClientUnFocusChat()
{
// client typed something - show typing indicator
isChatBoxActive = false;

ClientUpdateTyping(TypingIndicatorState.None);
}


public void ClientChangedChatText()
{
Expand Down Expand Up @@ -88,14 +91,17 @@ public override void Update(float frameTime)
{
base.Update(frameTime);

// check if client didn't changed chat text box for a long time
// check if client didn't changed chat text box for a long time and still chatbox is open
if (State != TypingIndicatorState.None)
{
var dif = _time.CurTime - _lastTextChange;
if (dif > _typingTimeout)
{
// client didn't typed anything for a long time - hide indicator
ClientUpdateTyping(TypingIndicatorState.None);
if(isChatBoxActive)
{
// client didn't typed anything for a long time - change state to thinking
ClientUpdateTyping(TypingIndicatorState.Thinking);
}
}
}
}
Expand Down

0 comments on commit 16b53bf

Please sign in to comment.