using Robust.Shared.Serialization;
using Content.Shared.Inventory;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Exceptions;
namespace Content.Shared.Chat.TypingIndicator;
///
/// Networked event from client.
/// Send to server when client started/stopped typing in chat input field.
///
[Serializable, NetSerializable]
public sealed class TypingChangedEvent : EntityEventArgs
{
public readonly bool IsTyping;
public TypingChangedEvent(bool isTyping)
{
IsTyping = isTyping;
}
}
///
/// This event will be broadcast right before displaying an entities typing indicator.
/// If _overrideIndicator is not null after the event is finished it will be used.
///
[Serializable, NetSerializable]
public sealed class BeforeShowTypingIndicatorEvent : IInventoryRelayEvent
{
public SlotFlags TargetSlots { get; } = SlotFlags.WITHOUT_POCKET;
private ProtoId? _overrideIndicator = null;
private TimeSpan? _latestEquipTime = null;
public BeforeShowTypingIndicatorEvent()
{
_overrideIndicator = null;
_latestEquipTime = null;
}
///
/// Will only update the time and indicator if the given time is more recent than
/// the stored time or if the stored time is null.
///
///
/// True if the given time is more recent than the stored time, and false otherwise.
///
public bool TryUpdateTimeAndIndicator(ProtoId? indicator, TimeSpan? equipTime)
{
if (equipTime != null && (_latestEquipTime == null || _latestEquipTime < equipTime))
{
_latestEquipTime = equipTime;
_overrideIndicator = indicator;
return true;
}
return false;
}
public ProtoId? GetMostRecentIndicator()
{
return _overrideIndicator;
}
}