diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2011-02-22 21:42:33 -0500 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2011-02-22 21:42:33 -0500 |
| commit | 92fc288f6200ff0c8943cde89c62f675862cb1fa (patch) | |
| tree | f1b34e0451eb296b4b6931d6ed4c04a72250b636 /src/admin.clj | |
| parent | e9f3ddc2286f93ba07788dea0a1cecb24af60d03 (diff) | |
Add friendly dates to mute error
Diffstat (limited to 'src/admin.clj')
| -rw-r--r-- | src/admin.clj | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/admin.clj b/src/admin.clj index 3593072..0daf66a 100644 --- a/src/admin.clj +++ b/src/admin.clj @@ -29,11 +29,12 @@ ;; Muting -(def *mute-refresh-period-sec* 60) +(def mute-refresh-period-sec 60) (def fetch-active-mutes-query " SELECT m.*, (m.set_on + m.duration) AS expiry, + (m.set_on + m.duration) - now() AS remaining, a.nick AS admin_nick, o.nick AS nick FROM mutes m, users a, users o @@ -81,9 +82,9 @@ LIMIT 1 (defn fetch-mute [mute-id] (first (do-select [fetch-mute-query mute-id]))) -(def *active-mutes* +(def active-mutes (scheduled-agent fetch-active-mute-map - *mute-refresh-period-sec* + mute-refresh-period-sec nil)) (defn parse-pos-interval [time unit] @@ -97,7 +98,7 @@ LIMIT 1 (do-prepared! "INSERT INTO mutes (user_id, admin_id, duration, reason) VALUES (?, ?, CAST (? AS INTERVAL), ?)" [user-id admin-id duration reason]) - (update! *active-mutes*)) + (update! active-mutes)) (defn mute! [session params] (if-vip @@ -136,7 +137,7 @@ AND cancelled = false :cancel_admin_id admin-id :cancel_reason reason})) (do - (update! *active-mutes*) + (update! active-mutes) (resp-success "OK")) (resp-error "UPDATE_ERROR"))))) @@ -147,10 +148,10 @@ AND cancelled = false admin-id (session :user_id)] (cancel-mute! mute-id admin-id reason)))) -(defn format-mute [mute] +(defn format-mute-error [mute] (format (str "I'm sorry, you've been muted for %s. " - "You'll be able to post again on %s EST.") - (mute :reason) (mute :expiry))) + "You'll be able to post again in %s.") + (mute :reason) (format-friendly-interval (:remaining mute)))) (def mute-formatter {:duration format-interval :set_on format-date-first-timestamp @@ -189,7 +190,7 @@ AND cancelled = false (defn debug-page [session flash] (if-vip - (let [mutes (poll *active-mutes*) + (let [mutes (poll active-mutes) st (fetch-template "debug" session)] (.setAttribute st "flash" (:msg flash)) (.setAttribute st "mailtemps" (lookup-templates "template/mail" "welcome")) |
