summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSacha Chua <sacha@sachachua.com>2022-12-11 10:04:24 -0500
committerSacha Chua <sacha@sachachua.com>2022-12-11 10:04:24 -0500
commit4d5a703c3e889d213408a902d726a080579b2a22 (patch)
tree7e00d76108b4a917c925ac78a85457f9333fc501
parentc1a32ad031d6a5fc7dc644fcfc442c3c9a6e107c (diff)
downloademacsconf-el-4d5a703c3e889d213408a902d726a080579b2a22.tar.xz
emacsconf-el-4d5a703c3e889d213408a902d726a080579b2a22.zip
email groups filtered by logbook
Diffstat (limited to '')
-rw-r--r--emacsconf-mail.el74
-rw-r--r--emacsconf.el40
2 files changed, 99 insertions, 15 deletions
diff --git a/emacsconf-mail.el b/emacsconf-mail.el
index 6b3ebb7..88dca51 100644
--- a/emacsconf-mail.el
+++ b/emacsconf-mail.el
@@ -24,12 +24,16 @@
;;; Code:
+(defun emacsconf-mail-groups (&optional info)
+ (setq info (emacsconf-filter-talks (or info (emacsconf-get-talk-info))))
+ (seq-group-by (lambda (o) (plist-get o :email)) info))
+
(defun emacsconf-mail-complete-email-group (&optional info)
"Return (email . (talk talk))."
(setq info (emacsconf-filter-talks (or info (emacsconf-get-talk-info))))
- (save-window-excursion
- (let* ((grouped (seq-group-by (lambda (o) (plist-get o :email)) info))
- (slug (emacsconf-get-slug-from-string (emacsconf-complete-talk)))
+ (save-window-excursion
+ (let* ((grouped (emacsconf-mail-groups info))
+ (slug (emacsconf-get-slug-from-string (emacsconf-complete-talk info)))
(email (plist-get (seq-find (lambda (o) (string= (plist-get o :slug) slug)) info) :email)))
(assoc email grouped))))
@@ -46,7 +50,7 @@
(cons "Cc" (emacsconf-replace-plist-in-string attrs (plist-get template :cc)))))))
(message-sort-headers)
(message-goto-body)
- (save-excursion (insert (emacsconf-replace-plist-in-string attrs (plist-get template :body)))
+ (save-excursion (insert (string-trim (emacsconf-replace-plist-in-string attrs (plist-get template :body))))
(goto-char (point-min))
(emacsconf-mail-merge-wrap)))
@@ -71,6 +75,25 @@
(mail-func (plist-get template :function)))
(funcall mail-func (emacsconf-complete-volunteer) template)))
+(defun emacsconf-mail-template-to-first-group ()
+ "Draft the current template for the first group on the list."
+ (interactive)
+ (let* ((template (if (org-entry-get (point) "EMAIL_ID")
+ (emacsconf-mail-merge-get-template-from-subtree)
+ (emacsconf-mail-merge-get-template
+ (completing-read "Template: " (org-property-values "EMAIL_ID")))))
+ (mail-func (plist-get template :function))
+ (filtered-talks (emacsconf-mail-filter-talks-by-template template))
+ (group (car (emacsconf-mail-groups (emacsconf-mail-filter-talks-by-template template)))))
+ (if filtered-talks
+ (progn
+ (funcall mail-func group template)
+ (when (plist-get template :log-note)
+ (mapc (lambda (talk)
+ (emacsconf-mail-log-message-when-sent talk (plist-get template :log-note)))
+ (cdr group))))
+ (message "All done!"))))
+
(defun emacsconf-mail-template-to-group ()
"Prompt for a speaker and e-mail current template to them."
(interactive)
@@ -78,8 +101,31 @@
(emacsconf-mail-merge-get-template-from-subtree)
(emacsconf-mail-merge-get-template
(completing-read "Template: " (org-property-values "EMAIL_ID")))))
- (mail-func (plist-get template :function)))
- (funcall mail-func (emacsconf-mail-complete-email-group) template)))
+ (mail-func (plist-get template :function))
+ (filtered-talks (emacsconf-mail-filter-talks-by-template template))
+ (group (emacsconf-mail-complete-email-group
+ filtered-talks)))
+ (if filtered-talks
+ (progn
+ (funcall mail-func group template)
+ (when (plist-get template :log-note)
+ (mapc (lambda (talk)
+ (emacsconf-mail-log-message-when-sent talk (plist-get template :log-note)))
+ (cdr group))))
+ (message "All done!"))))
+
+(defun emacsconf-mail-filter-talks-by-template (template)
+ (let ((list (emacsconf-prepare-for-display (emacsconf-filter-talks (emacsconf-get-talk-info)))))
+ (when list
+ (setq list (emacsconf-filter-talks-by-slugs (plist-get template :slugs) list)))
+ (when list
+ (setq list (emacsconf-filter-talks-by-logbook (plist-get template :log-note) list)))
+ (when list
+ (setq list
+ (seq-filter
+ (lambda (o) (plist-get o :email))
+ list)))
+ list))
(defun emacsconf-mail-template-to-all-groups ()
"Uses the current template to draft messages to all the speakers.
@@ -89,16 +135,15 @@ Group by e-mail."
(emacsconf-mail-merge-get-template-from-subtree)
(emacsconf-mail-merge-get-template
(completing-read "Template: " (org-property-values "EMAIL_ID")))))
- (info (seq-filter (lambda (o)
- (if (plist-get template :slugs)
- (member (plist-get o :slug)
- (split-string (plist-get template :slugs) " "))
- t))
- (emacsconf-prepare-for-display (emacsconf-filter-talks (emacsconf-get-talk-info)))))
+ (info (emacsconf-mail-filter-talks-by-template template))
(grouped (emacsconf-mail-group-by-email info))
(mail-func (plist-get template :function)))
(mapc (lambda (group)
- (funcall mail-func group template))
+ (funcall mail-func group template)
+ (when (plist-get template :log-note)
+ (mapc (lambda (talk)
+ (emacsconf-mail-log-message-when-sent talk (plist-get template :log-note)))
+ (cdr group))))
grouped)))
(defun emacsconf-mail-log-message-when-sent (o message)
@@ -174,7 +219,8 @@ Group by e-mail."
(org-end-of-meta-data) (point))
(org-end-of-subtree)))
:function (when (org-entry-get-with-inheritance "FUNCTION")
- (intern (org-entry-get-with-inheritance "FUNCTION")))))
+ (intern (org-entry-get-with-inheritance "FUNCTION")))
+ :log-note (org-entry-get-with-inheritance "LOG_NOTE")))
(defun emacsconf-mail-merge-get-template (id)
"Return the information for the e-mail template with EMAIL_ID set to ID."
diff --git a/emacsconf.el b/emacsconf.el
index 7157efd..d09167b 100644
--- a/emacsconf.el
+++ b/emacsconf.el
@@ -578,10 +578,28 @@
(subseq states (seq-position
states "PLAYING")))))
+;; https://stackoverflow.com/questions/55855621/org-mode-getting-logbook-notes
+(defun emacsconf-get-logbook-notes ()
+ (save-excursion
+ (unless (org-at-heading-p)
+ (outline-previous-heading))
+ (when (re-search-forward ":LOGBOOK:" (save-excursion
+ (outline-next-heading)
+ (point))
+ t)
+ (let* ((elt (org-element-property-drawer-parser nil))
+ (beg (org-element-property :contents-begin elt))
+ (end (org-element-property :contents-end elt)))
+ (buffer-substring-no-properties beg end)))))
+
+(defun emacsconf-get-talk-logbook (o)
+ (plist-put o :logbook (emacsconf-get-logbook-notes)))
+
(defvar emacsconf-talk-info-functions
'(emacsconf-get-talk-info-from-properties
emacsconf-get-talk-categories
emacsconf-get-talk-abstract-from-subtree
+ emacsconf-get-talk-logbook
emacsconf-add-talk-status
emacsconf-add-checkin-time
emacsconf-add-timezone-conversions
@@ -1141,6 +1159,24 @@
(when (stringp track) (setq track (emacsconf-get-track track)))
(seq-filter (lambda (o) (string= (plist-get o :track) (plist-get track :name))) info))
+(defun emacsconf-filter-talks-by-slugs (slugs &optional info)
+ (setq info (or info (emacsconf-get-talk-info)))
+ (if slugs
+ (seq-filter (lambda (o)
+ (member (plist-get o :slug)
+ slugs))
+ info)
+ info))
+
+(defun emacsconf-filter-talks-by-logbook (text &optional info)
+ (setq info (or info (emacsconf-get-talk-info)))
+ (if text
+ (seq-remove (lambda (o)
+ (and (plist-get o :logbook)
+ (string-match (regexp-quote text) (plist-get o :logbook))))
+ info)
+ info))
+
(defvar emacsconf-shifts
(list (list :id "sat-am-gen" :track "General" :start "2022-12-03T08:00:00-0500" :end "2022-12-03T12:00:00-0500" :host "zaeph" :streamer "sachac" :checkin "corwin" :irc "dto" :pad "publicvoit" :coord "sachac") (list :id "sat-pm-gen" :track "General" :start "2022-12-03T13:00:00-0500" :end "2022-12-03T18:00:00-0500" :host "zaeph" :streamer "sachac" :checkin "FlowyCoder" :irc "bandali" :pad "publicvoit" :coord "sachac") (list :id "sat-am-dev" :track "Development" :start "2022-12-03T08:00:00-0500" :end "2022-12-03T12:00:00-0500" :host "bandali" :streamer "sachac" :checkin "corwin" :irc "dto" :coord "sachac") (list :id "sat-pm-dev" :track "Development" :start "2022-12-03T13:00:00-0500" :end "2022-12-03T18:00:00-0500" :host "bandali" :streamer "sachac" :checkin "FlowyCoder" :irc "bandali" :coord "sachac") (list :id "sun-am-gen" :track "General" :start "2022-12-04T08:00:00-0500" :end "2022-12-04T12:00:00-0500" :host "zaeph" :streamer "sachac" :checkin "corwin" :irc "dto" :pad "publicvoit" :coord "sachac") (list :id "sun-pm-gen" :track "General" :start "2022-12-04T13:00:00-0500" :end "2022-12-04T18:00:00-0500" :host "zaeph" :streamer "jman" :checkin "FlowyCoder" :irc "bandali" :pad "publicvoit" :coord "sachac") (list :id "sun-am-dev" :track "Development" :start "2022-12-04T08:00:00-0500" :end "2022-12-04T12:00:00-0500" :host "bandali" :streamer "sachac" :checkin "corwin" :irc "dto" :coord "sachac") (list :id "sun-pm-dev" :track "Development" :start "2022-12-04T13:00:00-0500" :end "2022-12-04T18:00:00-0500" :host "bandali" :streamer "sachac" :checkin "FlowyCoder" :irc "bandali" :coord "sachac")))
@@ -1276,7 +1312,9 @@ Filter by TRACK if given. Use INFO as the list of talks."
(re-search-forward (concat "\\<" (regexp-quote input)) nil t)
(goto-char (match-beginning 0))))
(insert "\n")
- (when (< (- (line-end-position) (point)) fill-column)
+ (when (< (+ (- (line-end-position) (point))
+ (save-excursion (- (line-end-position) (line-beginning-position)))
+ 1) fill-column)
(save-excursion
(goto-char (line-end-position))
(insert " ")