Пример #1
0
        public void RequestGetDirectMessage(Action<TwitterDirectMessageCollection> action)
        {
            DirectMessagesOptions option = new DirectMessagesOptions();
            option.APIBaseAddress = Whisper.Properties.Settings.Default.APIBaseAddress;

            TwitterResponse<TwitterDirectMessageCollection> response = TwitterDirectMessage.DirectMessages(_tokens, option);
            if (response.Result == RequestResult.Success)
            {
                action(response.ResponseObject);
            }
        }
        /// <summary>
        /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <param name="options">The options.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="function">The function.</param>
        /// <returns>
        /// A <see cref="TwitterDirectMessageCollection"/> instance.
        /// </returns>
        public static IAsyncResult DirectMessages(OAuthTokens tokens, DirectMessagesOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterDirectMessageCollection>> function)
        {
            Func<OAuthTokens, DirectMessagesOptions, TwitterResponse<TwitterDirectMessageCollection>> methodToCall = TwitterDirectMessage.DirectMessages;

            return methodToCall.BeginInvoke(
                tokens,
                options,
                result =>
                {
                    result.AsyncWaitHandle.WaitOne(timeout);
                    try
                    {
                        function(methodToCall.EndInvoke(result).ToAsyncResponse());
                    }
                    catch (Exception ex)
                    {
                        function(new TwitterAsyncResponse<TwitterDirectMessageCollection>() { Result = RequestResult.Unknown, ExceptionThrown = ex });
                    }
                },
                null);
        }
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static TwitterResponse <TwitterDirectMessageCollection> DirectMessages(OAuthTokens tokens, DirectMessagesOptions options)
 {
     return(CommandPerformer.PerformAction(new Commands.DirectMessagesCommand(tokens, options)));
 }
Пример #4
0
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static TwitterResponse<TwitterDirectMessageCollection> DirectMessages(OAuthTokens tokens, DirectMessagesOptions options)
 {
     return CommandPerformer.PerformAction(new Commands.DirectMessagesCommand(tokens, options));
 }
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options.</param>
 /// <param name="timeout">The timeout.</param>
 /// <param name="function">The function.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static IAsyncResult DirectMessages(OAuthTokens tokens, DirectMessagesOptions options, TimeSpan timeout, Action <TwitterAsyncResponse <TwitterDirectMessageCollection> > function)
 {
     return(AsyncUtility.ExecuteAsyncMethod(tokens, options, timeout, TwitterDirectMessage.DirectMessages, function));
 }
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options. Leave null for defaults.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static async Task <TwitterResponse <TwitterDirectMessageCollection> > ReceivedAsync(OAuthTokens tokens, DirectMessagesOptions options = null)
 {
     return(await Core.CommandPerformer.PerformAction(new Commands.DirectMessagesCommand(tokens, options)));
 }
Пример #7
0
        private void UpdateDirectMessages()
        {
            Trace.Call();

            #if LOG4NET
            f_Logger.Debug("UpdateDirectMessages(): getting received direct messages from twitter...");
            #endif
            var options = new DirectMessagesOptions() {
                Proxy = f_WebProxy,
                SinceStatusId = f_LastDirectMessageReceivedStatusID,
                Count = 50
            };
            var receivedTimeline = TwitterDirectMessage.DirectMessages(
                f_OAuthTokens, options
            );
            #if LOG4NET
            f_Logger.Debug("UpdateDirectMessages(): done. New messages: " +
                (receivedTimeline == null ? 0 : receivedTimeline.Count));
            #endif

            #if LOG4NET
            f_Logger.Debug("UpdateDirectMessages(): getting sent direct messages from twitter...");
            #endif
            var sentOptions = new DirectMessagesSentOptions() {
                Proxy = f_WebProxy,
                SinceStatusId = f_LastDirectMessageSentStatusID,
                Count = 50
            };
            var sentTimeline = TwitterDirectMessage.DirectMessagesSent(
                f_OAuthTokens, sentOptions
            );
            #if LOG4NET
            f_Logger.Debug("UpdateDirectMessages(): done. New messages: " +
                (sentTimeline == null ? 0 : sentTimeline.Count));
            #endif

            var timeline = new TwitterDirectMessageCollection();
            if (receivedTimeline != null) {
                foreach (TwitterDirectMessage msg in receivedTimeline) {
                    timeline.Add(msg);
                }
            }
            if (sentTimeline != null) {
                foreach (TwitterDirectMessage msg in sentTimeline) {
                    timeline.Add(msg);
                }
            }

            if (timeline.Count == 0) {
                // nothing to do
                return;
            }

            var sortedTimeline = SortTimeline(timeline);
            foreach (TwitterDirectMessage directMsg in sortedTimeline) {
                // if this isn't the first time a receive a direct message,
                // this is a new one!
                bool highlight = receivedTimeline.Contains(directMsg) &&
                                 f_LastDirectMessageReceivedStatusID != 0;
                MessageModel msg = CreateMessage(
                    directMsg.CreatedDate,
                    directMsg.Sender,
                    directMsg.Text,
                    highlight
                );
                Session.AddMessageToChat(f_DirectMessagesChat, msg);

                // if there is a tab open for this user put the message there too
                string userId;
                if (receivedTimeline.Contains(directMsg)) {
                    // this is a received message
                    userId =  directMsg.SenderId.ToString();
                } else {
                    // this is a sent message
                    userId = directMsg.RecipientId.ToString();
                }
                ChatModel chat =  Session.GetChat(
                    userId,
                    ChatType.Person,
                    this
                );
                if (chat != null) {
                    Session.AddMessageToChat(chat, msg);
                }
            }

            if (receivedTimeline != null) {
                // first one is the newest
                foreach (TwitterDirectMessage msg in receivedTimeline) {
                    f_LastDirectMessageReceivedStatusID = msg.Id;
                    break;
                }
            }
            if (sentTimeline != null) {
                // first one is the newest
                foreach (TwitterDirectMessage msg in sentTimeline) {
                    f_LastDirectMessageSentStatusID = msg.Id;
                    break;
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options. Leave null for defaults.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static async Task<TwitterResponse<TwitterDirectMessageCollection>> ReceivedAsync(OAuthTokens tokens, DirectMessagesOptions options = null)
 {
     return await Core.CommandPerformer.PerformAction(new Commands.DirectMessagesCommand(tokens, options));
 }
 /// <summary>
 /// Returns a list of the 20 most recent direct messages sent to the authenticating user.
 /// </summary>
 /// <param name="tokens">The tokens.</param>
 /// <param name="options">The options.</param>
 /// <param name="timeout">The timeout.</param>
 /// <param name="function">The function.</param>
 /// <returns>
 /// A <see cref="TwitterDirectMessageCollection"/> instance.
 /// </returns>
 public static IAsyncResult DirectMessages(OAuthTokens tokens, DirectMessagesOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterDirectMessageCollection>> function)
 {
     return AsyncUtility.ExecuteAsyncMethod(tokens, options, timeout, TwitterDirectMessage.DirectMessages, function);
 }