Add: (ement--initial-transaction-id)

See <https://github.com/alphapapa/ement.el/issues/36>.
This commit is contained in:
Adam Porter 2021-09-28 07:41:59 +00:00
parent 7dccb0b1a0
commit 2763bd6837

View file

@ -179,8 +179,7 @@ the port, e.g.
(uri-prefix (or uri-prefix (ement--hostname-uri server-name)))
(user (make-ement-user :id user-id :username username :room-display-names (make-hash-table)))
(server (make-ement-server :name server-name :uri-prefix uri-prefix))
;; A new session with a new token should be able to start over with a transaction ID of 0.
(transaction-id 0))
(transaction-id (ement--initial-transaction-id)))
(make-ement-session :user user :server server :transaction-id transaction-id
:events (make-hash-table :test #'equal))))
(password-login
@ -291,6 +290,15 @@ THEN and ELSE are passed to `ement-api', which see."
;;;; Functions
(defun ement--initial-transaction-id ()
"Return an initial transaction ID for a new session."
;; We generate a somewhat-random initial transaction ID to avoid potential conflicts in
;; case, e.g. using Pantalaimon causes a transaction ID conflict. See
;; <https://github.com/alphapapa/ement.el/issues/36>.
(cl-parse-integer
(secure-hash 'sha256 (prin1-to-string (list (current-time) (system-name))))
:end 8 :radix 16))
(defsubst ement--sync-messages-p (session)
"Return non-nil if sync-related messages should be shown for SESSION."
;; For now, this seems like the best way.