diff options
-rw-r--r-- | granolin.lisp | 25 | ||||
-rw-r--r-- | package.lisp | 13 | ||||
-rw-r--r-- | utility-apps.lisp | 2 |
3 files changed, 20 insertions, 20 deletions
diff --git a/granolin.lisp b/granolin.lisp index f486e43..68534cb 100644 --- a/granolin.lisp +++ b/granolin.lisp @@ -48,18 +48,14 @@ (defmethod initialize-instance :after ((client client) &key) (validate-homserver-url client)) -(defgeneric handle-timeline-event (client room event) - (:documentation "Implemented on handlers that need to respond to timeline events.") - (:method ((client client) room event) t)) - -(defgeneric handle-room-state-event (client room event) - (:documentation "Implemented on handlers that need to respond to room state change events.") - (:method ((client client) room event) t)) - -(defgeneric handle-invitation-event (client room event) - (:documentation "Implemented on handlers that need to respond to room invitations.") +(defgeneric handle-event (client room event) + (:documentation "Implemented on handlers that need to respond to events.") (:method ((client client) room event) t)) +(defgeneric clean-up (client) + (:documentation "To be run before the client crashes or is killed.") + (:method ((client client)) + (setf (running-p client) nil))) ;;; Dynamic variables bound during response handling. Each such variable should ;;; be bound to a value during any message handler call. @@ -134,7 +130,6 @@ (event-type :|type|) (sender :|sender|)) - ;;; URI constants for interacting with the Matrix API (defparameter +login-path+ "/_matrix/client/r0/login") @@ -145,7 +140,6 @@ (defun add-auth-header (client headers) "If CLIENT has a non-nill ACCESS-TOKEN , adds the token to HEADERS, an ALIST, and returns it. Otherwise HEADERS unmodified." - (if (access-token client) (cons (cons "Authorization" (concatenate 'string "Bearer " (access-token client))) @@ -172,7 +166,6 @@ *RESPONSE-OBJECT*. When *RESPONSE-STATUS* is anything other than 200 the form in OTHERWISE is run." - `(multiple-value-bind (*response-body* *response-status* *response-headers*) (drakma:http-request (make-matrix-path ,client ,path) @@ -292,8 +285,10 @@ (defun start (client) (setf (running-p client) t) - (loop :while (running-p client) - :do (sync client))) + (unwind-protect + (loop :while (running-p client) + :do (sync client)) + (clean-up client))) (defun stop (client) (setf (running-p client) nil)) diff --git a/package.lisp b/package.lisp index 634fc57..32cd32a 100644 --- a/package.lisp +++ b/package.lisp @@ -7,9 +7,7 @@ #:txn-id #:client #:homeserver - #:handle-timeline-event - #:handle-room-state-event - #:handle-invitation-event + #:handle-event #:getob #:event-content @@ -21,9 +19,16 @@ #:state-key #:prev-content + #:timeline-event + #:room-state-event + #:invitation-event + #:send #:fetch #:login - #:sync + #:sync + + #:start + #:stop )) diff --git a/utility-apps.lisp b/utility-apps.lisp index 4f4b2db..7ea4b21 100644 --- a/utility-apps.lisp +++ b/utility-apps.lisp @@ -9,7 +9,7 @@ :documentation "An output stream to which messages are logged." ))) -(defmethod handle-timeline-event :after ((log message-log) room (event timeline-event)) +(defmethod handle-event :after ((log message-log) room (event timeline-event)) (format (output log) "~a in ~a: ~a~%" (sender event) room |