[NotNull] public static Task <bool> DeleteAsync(Channel destination, Message.ID messageID) { TaskCompletionSource <bool> completionSource = new TaskCompletionSource <bool> (); Request( json: "{\"method\": \"delete\", \"params\": {\"options\": {\"channel\": " + destination.ToOutgoingJSON() + ", \"message_id\": " + messageID.MessageID + "}}}", onResult: result => ValidateResult(result, kDeleteResult, ref completionSource), onError: () => completionSource.SetResult(false) ); return(completionSource.Task); }
/// <summary> /// Returns the number of reactions to the given <see cref="id"/> /// </summary> public static int CountReactions(Message.ID id) { int result = 0; s_Messages.Foreach(m => { if (m.GetReactionTargetID() == id) { ++result; } }); return(result); }
[NotNull] public static Task <bool> ReactAsync(Channel destination, Message.ID messageID, [NotNull] string reaction) { TaskCompletionSource <bool> completionSource = new TaskCompletionSource <bool> (); SanitiseMessageContents(ref reaction); Request( json: "{\"method\": \"reaction\", \"params\": {\"options\": {\"channel\": " + destination.ToOutgoingJSON() + ", \"message_id\": " + messageID.MessageID + ", \"message\": {\"body\": \"" + reaction + "\"}}}}", onResult: result => ValidateResult(result, kReactionResult, ref completionSource), onError: () => completionSource.SetResult(false) ); return(completionSource.Task); }
private static bool FindMessage(Message.ID id, out Message.Data result, bool pop) { Incoming.Message cache = s_Messages.Find(m => id == m.GetID(), pop: pop); if (null == cache) { result = default; return(false); } result = new Message.Data { Channel = Channel.Deserialized(cache.GetChannel()), Author = new User(cache.GetSender()?.GetName() ?? ""), Contents = cache.GetContent()?.GetText()?.GetBody() ?? "" }; return(true); }
private static bool FindReaction(Message.ID id, out Reaction.Data result, bool pop) { Incoming.Message cache = s_Messages.Find(m => id == m.GetID(), pop: pop); if (null == cache) { result = default; return(false); } Incoming.Reaction reaction = cache.GetContent()?.GetReaction(); result = new Reaction.Data { Channel = Channel.Deserialized(cache.GetChannel()), Author = new User(cache.GetSender()?.GetName() ?? ""), Target = cache.GetReactionTargetID(), Contents = reaction?.GetBody() ?? "" }; return(true); }
/// <summary> /// Read the logged reactions to this message into the <see cref="destination"/> array, /// at an optional <see cref="offset"/>, returning available reactions count /// </summary> public static int ReadReactions(Message.ID id, [NotNull] Reaction[] destination, int offset = 0) { int count = 0; offset = offset < 0 ? 0 : offset; s_Messages.Foreach(m => { if (m.GetReactionTargetID() != id) { return; } int index = offset + count++; if (index < destination.Length) { destination[index] = new Reaction(m.GetID()); } }); return(count); }
/// <summary> /// Remove the reaction from the log, returning whether it was found, passing its data via out if so /// </summary> public static bool TryRemoveFromLog(Message.ID id, out Reaction.Data result) => FindReaction(id, out result, pop: true);
/// <summary> /// Remove the message from the log, returning whether it was found, passing its data via out if so /// </summary> public static bool TryRemoveFromLog(Message.ID id, out Message.Data result) => FindMessage(id, out result, pop: true);
/// <summary> /// Read the message from the log, returning whether the read was successful, passing the data via out if so /// </summary> public static bool TryReadFromLog(Message.ID id, out Message.Data result) => FindMessage(id, out result, pop: false);