scm: add changed-object, use if-let/when-let
Add a changed-object (to complement changed), and some rework some of the code with the new if-let/when-let macros.
This commit is contained in:
5
NEWS.org
5
NEWS.org
@ -79,8 +79,9 @@
|
||||
~fields~/~field~ (alists with metadata about database fields). See the SCM
|
||||
reference documentation for further details (1.14.3).
|
||||
|
||||
- add procedures ~date-object~ to get a message's sent-date as an SRFI-19
|
||||
object; and ~utc-offset~ to get the UTC (timezone) offset for a date.
|
||||
- add procedures ~date-object~ which is like ~date~, but returns message's
|
||||
sent-date as an SRFI-19 object; and ~utc-offset~ to get the UTC (timezone)
|
||||
offset for a date. Similarly, add ~changed-object~ to complement ~changed~
|
||||
(1.14.3)
|
||||
|
||||
* 1.12 (released on February 24, 2024)
|
||||
|
||||
@ -45,6 +45,7 @@
|
||||
utc-offset
|
||||
|
||||
changed
|
||||
changed-object
|
||||
|
||||
message-id
|
||||
path
|
||||
@ -377,17 +378,21 @@ I.e., the offset from the UTC for the time the message was sent.
|
||||
(define-method (date-object (message <message>))
|
||||
"Get an SRFI-19 date object for MESSAGE's sent date.
|
||||
This includes the date and the timezone (if known). #f if not found."
|
||||
(let ((unix-time (date message)) (offset (utc-offset message)))
|
||||
(if unix-time
|
||||
(time-utc->date (make-time 'time-utc 0 unix-time)
|
||||
(or offset 0))
|
||||
#f)))
|
||||
(when-let ((unix-time (date message)))
|
||||
(time-utc->date (make-time 'time-utc 0 unix-time)
|
||||
(or (utc-offset message) 0))))
|
||||
|
||||
(define-method (changed (message <message>))
|
||||
"Get the timestamp for the last change to MESSAGE.
|
||||
This is the number of seconds since epoch; #f if not found."
|
||||
(assoc-ref (message->alist message) 'changed))
|
||||
|
||||
(define-method (changed-object (message <message>))
|
||||
"Get an SRFI-19 date object for MESSAGE's last-change.
|
||||
No time-zone offset is defined. #f if not found."
|
||||
(when-let ((unix-time (changed message)))
|
||||
(time-utc->date (make-time 'time-utc 0 unix-time))))
|
||||
|
||||
(define-method (path (message <message>))
|
||||
"Get the file-system path for MESSAGE or #f if not found."
|
||||
(assoc-ref (message->alist message) 'path))
|
||||
@ -400,11 +405,8 @@ A symbol, either 'high, 'low or 'normal, or #f if not found."
|
||||
(define-method (language (message <message>))
|
||||
"Get the ISO-639-1 language code for the MESSAGE as a symbol, if detected.
|
||||
Return #f otherwise."
|
||||
(let ((lang (assoc-ref (message->alist message) 'language)))
|
||||
(if lang
|
||||
(string->symbol lang)
|
||||
#f)))
|
||||
;; if-let would be nice!
|
||||
(when-let ((lang (assoc-ref (message->alist message) 'language)))
|
||||
(string->symbol lang)))
|
||||
|
||||
(define-method (size (message <message>))
|
||||
"Get the size of the MESSAGE in bytes or #f if not available."
|
||||
@ -426,10 +428,9 @@ the empty list."
|
||||
"Get the oldest (first) reference for MESSAGE, or message-id if there are none.
|
||||
If neither are available, return #f.
|
||||
This is method is useful to determine the thread a message is in."
|
||||
(let ((refs (references message)))
|
||||
(if (and refs (not (null? refs)))
|
||||
(car refs)
|
||||
(message-id message))))
|
||||
(if-let* ((refs (references message)) (_ (not (null? refs))))
|
||||
(car refs)
|
||||
(message-id message)))
|
||||
|
||||
(define-method (mailing-list (message <message>))
|
||||
"Get the mailing-list id for MESSAGE or #f if not available."
|
||||
|
||||
@ -840,16 +840,21 @@ Does this message include a calendar invitation? Returns @t{#t} or @code{#f}.
|
||||
|
||||
@deffn {Scheme Procedure} changed message
|
||||
@end deffn
|
||||
@deffn {Scheme Procedure} changed-object message
|
||||
@end deffn
|
||||
Get the time of the message's last change (through @t{mu}), or @code{#f} if there
|
||||
is none. The time is expressed the data as the number of seconds since epoch,
|
||||
@t{time_t}.
|
||||
|
||||
For example:
|
||||
@lisp
|
||||
(last-change msg)
|
||||
(changed msg)
|
||||
=> 1703336567
|
||||
@end lisp
|
||||
|
||||
@code{changed-object} returns a value as a SRFI-19 date object, similar to
|
||||
@code{date-object}, but without any time-zone offset.
|
||||
|
||||
@deffn {Scheme Procedure} priority message
|
||||
@end deffn
|
||||
Get the message's priority. This is a symbol, either @t{high}, @t{normal} or
|
||||
|
||||
Reference in New Issue
Block a user