mirror of
https://codeberg.org/cage/tinmop/
synced 2025-03-16 12:00:04 +01:00
- added voting to polls;
- fixed poll's rendering.
This commit is contained in:
parent
cc6bbd691b
commit
4f522225a4
@ -207,6 +207,8 @@
|
||||
|
||||
(define-key "V" #'open-message-link *thread-keymap*)
|
||||
|
||||
(define-key "P" #'poll-vote *thread-keymap*)
|
||||
|
||||
(define-key "C-c u" #'update-conversations *thread-keymap*)
|
||||
|
||||
(define-key "C-c o" #'open-conversation *thread-keymap*)
|
||||
|
2
po/it.po
2
po/it.po
@ -9,7 +9,7 @@ msgstr ""
|
||||
"Project-Id-Version: tinmop 0.0.1\n"
|
||||
"Report-Msgid-Bugs-To: https://notabug.org/cage/tinmop/\n"
|
||||
"POT-Creation-Date: 2020-05-31 12:44+0200\n"
|
||||
"PO-Revision-Date: 2020-05-31 12:46+0200\n"
|
||||
"PO-Revision-Date: 2020-05-31 16:48+0200\n"
|
||||
"Last-Translator: cage <cage@invalid.org>\n"
|
||||
"Language-Team: Italian\n"
|
||||
"Language: it\n"
|
||||
|
@ -598,6 +598,16 @@ returns nil if the credentials are invalid"
|
||||
(assert (stringp id))
|
||||
(tooter:polls *client* id))
|
||||
|
||||
(defun-w-lock poll-vote (poll-id choices)
|
||||
*client-lock*
|
||||
"Vote for a poll identified by `poll-id', choices is a list of
|
||||
numerical indices identifying the option voting for"
|
||||
(assert (every (lambda (a)
|
||||
(or (numberp a)
|
||||
(parse-integer a :radix 10)))
|
||||
choices))
|
||||
(tooter:poll-vote *client* poll-id choices))
|
||||
|
||||
(defun-w-lock get-notifications (&key
|
||||
(max-id nil)
|
||||
(min-id nil)
|
||||
|
@ -254,6 +254,7 @@
|
||||
(format stream "~a " title)
|
||||
(loop for i from 0 below bar-w do
|
||||
(princ bar-char stream))
|
||||
(format stream " ~a~%" (left-padding vote (- max-bar-width bar-w)))))
|
||||
(format stream " ~a~%" (left-padding vote (+ 4 ; size of vote percent: ' nnn%'
|
||||
(- max-bar-width bar-w))))))
|
||||
(when expiredp
|
||||
(format stream "~%~a~%" (_ "The poll has expired"))))))))
|
||||
|
@ -1161,6 +1161,7 @@
|
||||
:expand-thread-event
|
||||
:report-status-event
|
||||
:add-crypto-data-event
|
||||
:poll-vote-event
|
||||
:function-event
|
||||
:dispatch-program-events
|
||||
:add-pagination-status-event
|
||||
@ -1217,6 +1218,7 @@
|
||||
:bookmark
|
||||
:unbookmark
|
||||
:polls
|
||||
:poll-vote
|
||||
:get-notifications
|
||||
:delete-notification
|
||||
:all-mentions
|
||||
@ -1965,7 +1967,8 @@
|
||||
:crypto-export-key
|
||||
:crypto-generate-key
|
||||
:show-about-window
|
||||
:reset-timeline-pagination))
|
||||
:reset-timeline-pagination
|
||||
:poll-vote))
|
||||
|
||||
(defpackage :modules
|
||||
(:use
|
||||
|
@ -193,7 +193,7 @@
|
||||
(defclass user-input-string-event (ask-user-input-string-event)
|
||||
()
|
||||
(:documentation "When user provided a string as this event is
|
||||
generated. When processed it just wlii notify the condition variable
|
||||
generated. When processed it just will notify the condition variable
|
||||
of the slots `command-window:event-to-answer' in the object
|
||||
`specials:*command-window*' so that the callee thread can restart
|
||||
the computation with the input."))
|
||||
@ -811,6 +811,22 @@
|
||||
(folder folder)) object
|
||||
(db:add-to-pagination-status status-id folder timeline)))
|
||||
|
||||
(defclass poll-vote-event (program-event)
|
||||
((poll-id
|
||||
:initform nil
|
||||
:initarg :poll-id
|
||||
:accessor poll-id)
|
||||
(choices
|
||||
:initform ()
|
||||
:initarg :choices
|
||||
:accessor choices)))
|
||||
|
||||
(defmethod process-event ((object poll-vote-event))
|
||||
(with-accessors ((poll-id poll-id)
|
||||
(choices choices)) object
|
||||
(tui:with-notify-errors
|
||||
(api-client:poll-vote poll-id choices))))
|
||||
|
||||
(defclass function-event (program-event) ())
|
||||
|
||||
(defmethod process-event ((object function-event))
|
||||
|
@ -1245,3 +1245,45 @@ This command will remove those limits so that we can just jump to the last messa
|
||||
(folder (thread-window:timeline-folder specials:*thread-window*)))
|
||||
(with-blocking-notify-procedure ((_ "Clearing pagination data"))
|
||||
(db:remove-pagination-status folder timeline))))
|
||||
|
||||
(defun poll-vote ()
|
||||
"Change timeline"
|
||||
(labels ((valid-indices-p (choices options)
|
||||
(let ((max-index (length options)))
|
||||
(every (lambda (a) (and (>= a 0)
|
||||
(< a max-index)))
|
||||
choices)))
|
||||
(on-input-complete (choices)
|
||||
(let ((choices-list (split-words choices)))
|
||||
(if (or (null choices-list)
|
||||
(notevery (lambda (a)
|
||||
(let ((idx (parse-integer a :junk-allowed t)))
|
||||
(and idx
|
||||
(>= idx 0))))
|
||||
choices-list))
|
||||
(error-message
|
||||
(_ "Invalid choices, usa a space separated list of positive integers."))
|
||||
(db-utils:with-ready-database (:connect nil)
|
||||
(when-let* ((fields (line-oriented-window:selected-row-fields
|
||||
specials:*thread-window*))
|
||||
(status-id (db:row-message-status-id fields))
|
||||
(poll (db:find-poll-bound-to-status status-id))
|
||||
(poll-id (db:row-id poll))
|
||||
(event (make-instance 'poll-vote-event
|
||||
:poll-id poll-id
|
||||
:choices choices-list))
|
||||
(actual-choices (mapcar (lambda (a)
|
||||
(parse-integer a :junk-allowed t))
|
||||
choices-list))
|
||||
(options (db:all-poll-options poll-id)))
|
||||
(if (not (valid-indices-p actual-choices options))
|
||||
(error-message
|
||||
(format nil
|
||||
(_ "Invalid choices, index choice out of range (max ~a).")
|
||||
(1- (length options))))
|
||||
(with-blocking-notify-procedure ((_ "Voting... ")
|
||||
(_ "Choice sent."))
|
||||
(push-event event)))))))))
|
||||
(ask-string-input #'on-input-complete
|
||||
:prompt
|
||||
(_ "Type the index (or space separated indices) of selected choices: "))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user