/// <inheritdoc/>
        public override IWolfResponse Deserialize(Type responseType, SerializedMessageData responseData)
        {
            // first deserialize the json message
            ChatHistoryResponse result = (ChatHistoryResponse)base.Deserialize(responseType, responseData);

            // then assign binary data to each of the messages
            JArray responseBody = GetResponseJson(responseData)["body"] as JArray;

            if (responseBody == null)
            {
                throw new ArgumentException("Chat history response requires to have a body property that is a JSON array", nameof(responseData));
            }
            foreach (JToken responseChatMessage in responseBody)
            {
                WolfTimestamp msgTimestamp = responseChatMessage["timestamp"].ToObject <WolfTimestamp>(SerializationHelper.DefaultSerializer);
                IChatMessage  msg          = result.Messages.First(m => m.Timestamp == msgTimestamp);
                JToken        numProp      = responseChatMessage["data"]?["num"];
                if (numProp != null)
                {
                    int binaryIndex = numProp.ToObject <int>(SerializationHelper.DefaultSerializer);
                    SerializationHelper.PopulateMessageRawData(ref msg, responseData.BinaryMessages.ElementAt(binaryIndex));
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>Creates a message instance.</summary>
 /// <param name="messageID">ID (timestamp) of the message to tip.</param>
 /// <param name="groupID">ID of the group where the message is in.</param>
 /// <param name="authorID">ID of the message author.</param>
 /// <param name="contextType">Context type of the tip.</param>
 /// <param name="tips">Tips to send.</param>
 public TipAddMessage(WolfTimestamp messageID, uint groupID, uint authorID, WolfTip.ContextType contextType, IEnumerable <WolfTip> tips)
 {
     if (tips?.Any() != true)
     {
         throw new ArgumentException("Must request at least one tip to add", nameof(tips));
     }
     this.MessageID       = messageID;
     this.MessageAuthorID = authorID;
     this.GroupID         = groupID;
     this.ContextType     = contextType;
     this.Tips            = new ReadOnlyCollection <WolfTip>((tips as IList <WolfTip>) ?? tips.ToArray());
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.Value == null)
            {
                return(null);
            }
            WolfTimestamp result = new WolfTimestamp((long)reader.Value);

            if (objectType.IsAssignableFrom(typeof(long)))
            {
                return((long)result);
            }
            if (objectType.IsAssignableFrom(typeof(DateTime)))
            {
                return((DateTime)result);
            }
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>Creates a message instance.</summary>
 /// <param name="messageID">ID (timestamp) of the message to tip.</param>
 /// <param name="groupID">ID of the group where the message is in.</param>
 /// <param name="contextType">Context type of the tip.</param>
 public TipDetailsMessage(WolfTimestamp messageID, uint groupID, WolfTip.ContextType contextType)
 {
     this.GroupID     = groupID;
     this.ContextType = contextType;
     this.MessageID   = messageID;
 }
 /// <summary>Creates a builder instance from message information.</summary>
 public Builder(WolfTimestamp timestamp, uint recipientID, bool isGroupMessage)
 {
     this.Timestamp      = timestamp;
     this.RecipientID    = recipientID;
     this.IsGroupMessage = isGroupMessage;
 }