/// <summary> /// Replace or remove a message from the channel. /// </summary> /// <param name="echo">The local echo message (client-side).</param> /// <param name="final">The response message, or null if the message became invalid.</param> public void ReplaceMessage(LocalEchoMessage echo, Message final) { if (!pendingMessages.Remove(echo)) { throw new InvalidOperationException("Attempted to remove echo that wasn't present"); } Messages.Remove(echo); if (final == null) { MessageRemoved?.Invoke(echo); return; } if (Messages.Contains(final)) { // message already inserted, so let's throw away this update. // we may want to handle this better in the future, but for the time being api requests are single-threaded so order is assumed. MessageRemoved?.Invoke(echo); return; } Messages.Add(final); PendingMessageResolved?.Invoke(echo, final); }
/// <summary> /// Replace or remove a message from the channel. /// </summary> /// <param name="echo">The local echo message (client-side).</param> /// <param name="final">The response message, or null if the message became invalid.</param> public void ReplaceMessage(LocalEchoMessage echo, Message final) { if (!pendingMessages.Remove(echo)) { throw new InvalidOperationException("Attempted to remove echo that wasn't present"); } Messages.Remove(echo); if (final == null) { MessageRemoved?.Invoke(echo); return; } if (Messages.Contains(final)) { throw new InvalidOperationException("Attempted to add the same message again"); } Messages.Add(final); PendingMessageResolved?.Invoke(echo, final); }