From ed67225499f77cadc419a4deffb13e3cace53b5c Mon Sep 17 00:00:00 2001 From: Tadashi MATSUO Date: Mon, 1 Feb 2010 00:45:29 +0900 Subject: [PATCH] Processes are registered with timeline spec retrieved by them. * twittering-mode.el (twittering-process-info-alist): new variable for managing active process and timeline spec being retrieved by the process. (twittering-register-process): new function for registering a pair of process and timeline spec. (twittering-release-process): new function for releasing a process. (twittering-get-timeline-spec-from-process): new function for getting timeline spec retrieved by the given process. (twittering-http-get-default-sentinel): discard statuses if the retrieved spec differs from the last requested one. (twittering-get-and-render-timeline): register a pair of the requested timeline spec and process for retrieving it. --- ChangeLog | 13 +++++++++++++ twittering-mode.el | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2097e775..2479518a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,19 @@ (twittering-start-http-non-ssl-session): likewise. (twittering-get-tweets): likewise. + * twittering-mode.el (twittering-process-info-alist): new variable + for managing active process and timeline spec being retrieved by + the process. + (twittering-register-process): new function for registering a pair + of process and timeline spec. + (twittering-release-process): new function for releasing a process. + (twittering-get-timeline-spec-from-process): new function for + getting timeline spec retrieved by the given process. + (twittering-http-get-default-sentinel): discard statuses if + the retrieved spec differs from the last requested one. + (twittering-get-and-render-timeline): register a pair of the + requested timeline spec and process for retrieving it. + 2010-01-30 Tadashi MATSUO * twittering-mode.el (twittering-fill-string): use `frame-width' diff --git a/twittering-mode.el b/twittering-mode.el index 8ce716a6..16283534 100644 --- a/twittering-mode.el +++ b/twittering-mode.el @@ -146,6 +146,9 @@ then you can use \"$to_me\" as "The last successfully retrieved timeline spec string.") (defvar twittering-list-index-retrieved nil) +(defvar twittering-process-info-alist nil + "Alist of active process and timeline spec retrieved by the process.") + (defvar twittering-new-tweets-count 0 "Number of new tweets when `twittering-new-tweets-hook' is run") @@ -844,6 +847,25 @@ Return nil if STR is invalid as a timeline spec." (setq twittering-timeline-history (cons spec-string twittering-timeline-history))))))) +;;; +;;; Process info +;;; + +(defun twittering-register-process (proc spec) + (add-to-list 'twittering-process-info-alist + `(,proc ,spec))) + +(defun twittering-release-process (proc) + (let ((spec (twittering-get-timeline-spec-from-process proc))) + (setq twittering-process-info-alist + (delete `(,proc ,spec) twittering-process-info-alist)))) + +(defun twittering-get-timeline-spec-from-process (proc) + (let ((entry (assoc proc twittering-process-info-alist))) + (if entry + (elt entry 1) + nil))) + ;;; ;;; Debug mode ;;; @@ -1470,9 +1492,15 @@ Available keywords: (status-line (and header-is-valid (match-string-no-properties 1 header))) (status (and header-is-valid - (match-string-no-properties 2 header)))) + (match-string-no-properties 2 header))) + (spec (twittering-get-timeline-spec-from-process proc)) + (spec-string (twittering-timeline-spec-to-string spec)) + (requested-spec + (twittering-string-to-timeline-spec + twittering-last-requested-timeline-spec-string))) + (twittering-release-process proc) (cond - ((and header-is-valid body) + ((and header-is-valid body (equal spec requested-spec)) (case-string status (("200") @@ -2352,9 +2380,11 @@ variable `twittering-status-format'" (if (twittering-timeline-spec-primary-p spec) (let ((pair (twittering-timeline-spec-to-host-method spec))) (when pair - (let ((host (car pair)) - (method (cadr pair))) - (twittering-get-tweets host method noninteractive id)))) + (let* ((host (car pair)) + (method (cadr pair)) + (proc (twittering-get-tweets host method + noninteractive id))) + (twittering-register-process proc spec)))) (let ((type (car spec))) (error "%s has not been supported yet" type)))))