Permalink
Browse files

Support a timeline consisting of a tweet specified by its ID.

* twittering-mode.el: Support a timeline consisting of a tweet
specified by its ID.
(twittering-retrieve-single-tweet-sentinel): support the retrieval
via `twittering-call-api' with the command `retrieve-timeline'.
(twittering-timeline-spec-to-string): support the single timeline
spec.
(twittering-extract-timeline-spec): likewise.
(twittering-timeline-spec-primary-p): likewise.
(twittering-current-timeline-data): likewise.
(twittering-call-api): invoke the `retrieve-single-tweet' command
if the `retrieve-timeline' command is specified with a single
timeline spec.
* test/test-twittering-mode.el: Add a test for the single timeline
spec.
* README.markdown: Add an explanation for the single timeline
spec.
  • Loading branch information...
1 parent 5c0e3bd commit 50de3fcfc994b0c3d40955de006137112f0ae369 @cvmat cvmat committed May 6, 2012
Showing with 85 additions and 7 deletions.
  1. +17 −0 ChangeLog
  2. +4 −0 NEWS
  3. +4 −0 NEWS.ja
  4. +2 −0 README.markdown
  5. +10 −0 test/test-twittering-mode.el
  6. +48 −7 twittering-mode.el
View
@@ -16,6 +16,23 @@
(twittering-call-api): fix the docstring for the command
`retrieve-single-tweet'.
+ * twittering-mode.el: Support a `single tweet' timeline, which
+ consists of a tweet specified by its ID.
+ (twittering-retrieve-single-tweet-sentinel): support the retrieval
+ via `twittering-call-api' with the command `retrieve-timeline'.
+ (twittering-timeline-spec-to-string): support a `single tweet'
+ timeline spec.
+ (twittering-extract-timeline-spec): likewise.
+ (twittering-timeline-spec-primary-p): likewise.
+ (twittering-current-timeline-data): likewise.
+ (twittering-call-api): invoke the `retrieve-single-tweet' command
+ if the `retrieve-timeline' command is specified with a single
+ tweet timeline spec.
+ * test/test-twittering-mode.el: Add a test for a `single tweet'
+ timeline spec.
+ * README.markdown: Add an explanation for a `single tweet'
+ timeline spec.
+
2012-04-02 Tadashi MATSUO <tad@mymail.twin.jp>
* README.markdown: Fix the order of tags.
View
4 NEWS
@@ -226,6 +226,10 @@
current frame. You can also use the function
`twittering-pop-to-buffer-in-current-window', which splits the
current window.
+* Support for `single tweet' timelines.
+ ":single/ID" is added as a new timeline spec. The timeline consists
+ of a tweet specified by ID. You can read a very old tweet by using
+ the timeline spec.
### Bug fixes
* Fix of displaying a message of authorization.
View
@@ -221,6 +221,10 @@
のを分割することで編集バッファ用のウィンドウを確保します。他にも、関
数`twittering-pop-to-buffer-in-current-window'を指定することもできま
す。この関数は現在のウィンドウを分割してウィンドウを確保します。
+* single tweet timelineに対応
+ 新しく":single/ID"というtimelineに対応しました。このtimelineはIDで
+ 指定されたtweetのみからなるtimelineです。非常に古いtweet等にアクセス
+ するのに利用できます。
### バグ修正
* 認証成功・失敗についてのメッセージが表示されるよう修正
View
@@ -177,6 +177,8 @@ The valid timeline specs follows:
Retweets sent to *USER*'s home timeline.
- `:retweets_of_me` :
Your tweets that have been retweeted by others.
+- Single
+ - `:single/ID` : A tweet specified by *ID*.
- Search
- `:search/QUERY-STRING/` :
Tweets matching *QUERY-STRING*. In *QUERY-STRING*, */* (slash) and
@@ -333,6 +333,16 @@
'(list "USER" "non-ASCIIリスト")
'(list "USER" "non-ASCIIリスト"))
'(t t))
+
+ (test-assert-equal
+ (test-restore-timeline-spec
+ ;; An example from
+ ;; https://dev.twitter.com/docs/api/1/get/statuses/home_timeline ,
+ ;; which is posted by cindy li.
+ ":single/18700887835"
+ '(single "18700887835")
+ '(single "18700887835"))
+ '(t t))
)
(defcase timeline-spec-dependence nil nil
View
@@ -2415,9 +2415,19 @@ If BUFFER is nil, the current buffer is used instead."
(when status
(twittering-add-statuses-to-timeline-data `(,status) '(:single))
(let ((buffer (cdr (assq 'buffer connection-info)))
+ (spec (cdr (assq 'timeline-spec connection-info)))
(prop
(cdr (assq 'property-to-be-redisplayed connection-info))))
- (when (and buffer prop (buffer-live-p buffer))
+ (cond
+ (spec
+ ;; The process has been invoked via `twittering-call-api' with
+ ;; the command `retrieve-timeline', not the command
+ ;; `retrieve-single-tweet'.
+ (let ((new-statuses `(,status))
+ (buffer (twittering-get-buffer-from-spec spec)))
+ (when (and new-statuses buffer)
+ (twittering-render-timeline buffer new-statuses t))))
+ ((and buffer prop (buffer-live-p buffer))
(twittering-redisplay-status-on-each-buffer buffer prop)
(with-current-buffer buffer
(save-excursion
@@ -2429,7 +2439,7 @@ If BUFFER is nil, the current buffer is used instead."
;; Remove the property required no longer.
(remove-text-properties beg end `(,prop nil))
(goto-char beg)
- (twittering-render-replied-statuses))))))))))
+ (twittering-render-replied-statuses)))))))))))
(cond
((string= status-code "403")
(format "You are not authorized to see this tweet (ID %s)." id))
@@ -3742,8 +3752,10 @@ Before calling this, you have to configure `twittering-bitly-login' and
;;; - (retweeted_to_user USER): retweets posted to the user.
;;; - (retweets_of_me):
;;; tweets of the authenticated user that have been retweeted by others.
+;;; - (single ID): the single tweet specified by ID.
;;;
;;; - (search STRING): the result of searching with query STRING.
+;;;
;;; - (exclude-if FUNC SPEC):
;;; the same timeline as SPEC, except that it does not include tweets
;;; that FUNC returns non-nil for.
@@ -3780,6 +3792,8 @@ Before calling this, you have to configure `twittering-bitly-login' and
;;; RETWEETED_TO_ME ::= ":retweeted_to_me"
;;; RETWEETED_TO_USER ::= ":retweeted_to_user/" USER
;;; RETWEETS_OF_ME ::= ":retweets_of_me"
+;;; SINGLE ::= ":single/" ID
+;;; ID ::= /[0-9]+/
;;;
;;; SEARCH ::= ":search/" QUERY_STRING "/"
;;; QUERY_STRING ::= any string, where "/" is escaped by a backslash.
@@ -3829,6 +3843,7 @@ If SHORTEN is non-nil, the abbreviated expression will be used."
((eq type 'retweeted_to_me) ":retweeted_to_me")
((eq type 'retweeted_to_user) (concat ":retweeted_to_user/" (car value)))
((eq type 'retweets_of_me) ":retweets_of_me")
+ ((eq type 'single) (concat ":single/" (car value)))
((eq type 'search)
(let ((query (car value)))
(concat ":search/"
@@ -3921,6 +3936,10 @@ Return cons of the spec and the rest string."
(let ((user (match-string 1 str))
(rest (substring str (match-end 0))))
`((retweeted_to_user ,user) . ,rest)))
+ ((string-match "^:single/\\([0-9]+\\)" str)
+ (let ((id (match-string 1 str))
+ (rest (substring str (match-end 0))))
+ `((single ,id) . ,rest)))
((string= type "search")
(if (string-match "^:search/\\(\\(.*?[^\\]\\)??\\(\\\\\\\\\\)*\\)??/"
str)
@@ -4060,7 +4079,8 @@ Return nil if SPEC-STR is invalid as a timeline spec."
search
retweeted_by_me retweeted_by_user
retweeted_to_me retweeted_to_user
- retweets_of_me))
+ retweets_of_me
+ single))
(type (car spec)))
(memq type primary-spec-types)))
@@ -4254,6 +4274,12 @@ referring the former ID."
(cond
((null spec)
nil)
+ ((eq type 'single)
+ (let* ((id (cadr spec))
+ (status (twittering-find-status id)))
+ (if status
+ `(,status)
+ nil)))
((memq type '(exclude-if exclude-re merge))
(let ((primary-base-specs
(twittering-get-primary-base-timeline-specs spec)))
@@ -4946,10 +4972,25 @@ get-service-configuration -- Get the configuration of the server.
(sentinel (cdr (assq 'sentinel args-alist)))
(clean-up-sentinel (cdr (assq 'clean-up-sentinel args-alist)))
(additional-info `(,@additional-info (format . ,format))))
- (if (and host method)
- (twittering-http-get host method parameters format-str
- additional-info sentinel clean-up-sentinel)
- (error "Invalid timeline spec"))))
+ (cond
+ ((eq spec-type 'single)
+ (let ((id (cadr spec))
+ (sentinel (or sentinel
+ 'twittering-retrieve-single-tweet-sentinel)))
+ (if (twittering-find-status id)
+ ;; If the status has already retrieved, do nothing.
+ nil
+ (twittering-call-api 'retrieve-single-tweet
+ `((id . ,id)
+ (format . ,format)
+ (sentinel . ,sentinel)
+ (clean-up-sentinel . ,clean-up-sentinel))
+ additional-info))))
+ ((and host method)
+ (twittering-http-get host method parameters format-str
+ additional-info sentinel clean-up-sentinel))
+ (t
+ (error "Invalid timeline spec")))))
((eq command 'retrieve-single-tweet)
(let* ((id (cdr (assq 'id args-alist)))
(user-screen-name (cdr (assq 'username args-alist)))

0 comments on commit 50de3fc

Please sign in to comment.