aboutsummaryrefslogtreecommitdiff
path: root/sx-question.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-15 02:28:12 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-15 02:28:12 +0000
commitef241cbf39b57a24f8464d35a8616df7833101cc (patch)
tree848274e43fc9463995d377e33eebcc76b48bfbae /sx-question.el
parentc0c46f3bed3479f14065d1d28cad63217f9473bc (diff)
sx-question-read-p and mark-read actually work
Diffstat (limited to 'sx-question.el')
-rw-r--r--sx-question.el29
1 files changed, 26 insertions, 3 deletions
diff --git a/sx-question.el b/sx-question.el
index 607b3f6..76f9a67 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -67,10 +67,18 @@
;;; Question Properties
+(defvar sx-question--user-read-list nil
+ "Alist of questions read by the user.
+Each element has the form (SITE . QUESTION-LIST).
+And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).")
+
(defun sx-question--read-p (question)
"Non-nil if QUESTION has been read since last updated."
- ;; @TODO:
- (cl-evenp (random)))
+ (sx-assoc-let question
+ (let ((ql (cdr (assoc .site sx-question--user-read-list))))
+ (and ql
+ (>= (or (cdr (assoc .question_id ql)) 0)
+ .last_activity_date)))))
(defun sx-question--accepted-answer-id (question)
"Return accepted answer in QUESTION, or nil if none."
@@ -80,7 +88,22 @@
(defun sx-question--mark-read (question)
"Mark QUESTION as being read, until it is updated again."
- nil)
+ (sx-assoc-let question
+ (let ((site-cell (assoc .site sx-question--user-read-list))
+ (q-cell (cons .question_id .last_activity_date))
+ cell)
+ (cond
+ ;; First question from this site.
+ ((null site-cell)
+ (push (list .site q-cell) sx-question--user-read-list))
+ ;; Question already has an older time.
+ ((setq cell (assoc .question_id site-cell))
+ (setcdr cell .last_activity_date))
+ ;; Question wasn't present.
+ (t
+ (setcdr site-cell (cons q-cell (cdr site-cell)))))))
+ ;; Save the results.
+ (sx-cache-set 'read-questions sx-question--user-read-list))
(defun sx-question--< (property x y &optional pred)
"Non-nil if PROPERTY attribute of question X is less than that of Y.