Updates
This commit is contained in:
parent
a4d6910037
commit
2e88277401
|
@ -27,7 +27,7 @@
|
|||
default = updateDeps;
|
||||
updateDeps = pkgs.mkShell {
|
||||
buildInputs = with helpers.packages."${system}";
|
||||
[ updateClojureDeps ];
|
||||
[ (updateClojureDeps { }) ];
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(:require [bebot.model :refer [id user-id new-post to-model mentions-user? channel-last-view from-model created-at]]
|
||||
[bebot.api.client :as client]
|
||||
[bebot.api.channel :as chan]
|
||||
[fudo-clojure.result :refer [let-result exception-failure success failure map-success dispatch-result]]
|
||||
[fudo-clojure.result :as res :refer [let-result exception-failure success failure map-success dispatch-result unwrap]]
|
||||
[clojure.core.async :as async :refer [go-loop chan timeout >! <!]])
|
||||
(:import net.bis5.mattermost.client4.MattermostClient
|
||||
net.bis5.mattermost.model.ChannelView))
|
||||
|
@ -13,14 +13,11 @@
|
|||
msg (.getMessage err)
|
||||
status-code (.getStatusCode err)
|
||||
full-msg (str "[" status-code "] " msg)]
|
||||
;; A silly hack to catch the stack trace at this point
|
||||
(try
|
||||
(throw (ex-info full-msg
|
||||
{:status-code status-code
|
||||
:error err}))
|
||||
(catch clojure.lang.ExceptionInfo e
|
||||
(exception-failure e))))
|
||||
(success (to-model (.readEntity resp)))))
|
||||
(throw (ex-info full-msg
|
||||
{:status-code status-code
|
||||
:error err
|
||||
:message msg})))
|
||||
(to-model (.readEntity resp))))
|
||||
|
||||
(defn- to-millis [instant]
|
||||
(.toEpochMilli instant))
|
||||
|
@ -40,11 +37,9 @@
|
|||
{:keys [poll-delay buffer-size]
|
||||
:or {poll-delay 30 buffer-size 10}}]
|
||||
(let [out-chan (chan buffer-size)]
|
||||
(go-loop [result (coll-gen)]
|
||||
(dispatch-result result
|
||||
([os] (doseq [o (sort-by-create-date os)]
|
||||
(>! out-chan (success o))))
|
||||
([e] (>! out-chan (exception-failure e))))
|
||||
(go-loop [os (coll-gen)]
|
||||
(doseq [o (sort-by-create-date os)]
|
||||
(>! out-chan o))
|
||||
(<! (timeout (* poll-delay 1000)))
|
||||
(recur (coll-gen)))
|
||||
out-chan))
|
||||
|
@ -60,29 +55,32 @@
|
|||
(last-read [_] @last-viewed)
|
||||
|
||||
(get-new-posts! [self]
|
||||
(let-result [msgs (chan/peek-new-posts! self)
|
||||
read-instant (client/mark-read! client (id channel))]
|
||||
(do (swap! last-viewed (fn [_] read-instant))
|
||||
(success (remove-posts-by me msgs)))))
|
||||
(let [msgs (chan/peek-new-posts! self)
|
||||
read-instant (client/mark-read! client (id channel))]
|
||||
(swap! last-viewed (fn [_] read-instant))
|
||||
(remove-posts-by me msgs)))
|
||||
|
||||
(peek-new-posts! [self]
|
||||
(chan/get-posts-since! self @last-viewed))
|
||||
|
||||
(get-posts-since! [_ instant]
|
||||
(let-result [msgs (client/get-posts-since! client (id channel) instant)]
|
||||
(success (remove-posts-by me msgs))))
|
||||
(->> (client/get-posts-since! client (id channel) instant)
|
||||
(remove-posts-by me)))
|
||||
|
||||
(get-new-mentions! [self]
|
||||
(map-success (chan/get-new-posts! self)
|
||||
(partial filter (mentions-user? me))))
|
||||
(->> self
|
||||
(chan/get-new-posts!)
|
||||
(filter (mentions-user? me))))
|
||||
|
||||
(peek-new-mentions! [self]
|
||||
(map-success (chan/peek-new-posts! self)
|
||||
(partial filter (mentions-user? me))))
|
||||
(->> self
|
||||
(chan/peek-new-posts!)
|
||||
(filter (mentions-user? me))))
|
||||
|
||||
(get-mentions-since! [self instant]
|
||||
(map-success (chan/get-posts-since! self instant)
|
||||
(partial filter (mentions-user? me))))
|
||||
(->> self
|
||||
(chan/get-posts-since! instant)
|
||||
(filter (mentions-user? me))))
|
||||
|
||||
(post-channel! [self]
|
||||
(yield-to-channel (fn [] (chan/get-new-posts! self)) :poll-delay 5))
|
||||
|
@ -105,21 +103,21 @@
|
|||
(to-result (.getUserByUsername client username nil)))
|
||||
|
||||
(open-channel! [self chan-id]
|
||||
(let-result [chan (client/get-channel! self chan-id)
|
||||
read-instant (client/mark-read! self chan-id)]
|
||||
(success (->BebotChannel self chan (atom read-instant) me))))
|
||||
(let [chan (client/get-channel! self chan-id)
|
||||
read-instant (client/mark-read! self chan-id)]
|
||||
(->BebotChannel self chan (atom read-instant) me)))
|
||||
|
||||
(open-direct-channel! [self user-id]
|
||||
(let-result [chan (to-result (.createDirectChannel client (id me) user-id))]
|
||||
(success (client/open-channel! self (id chan)))))
|
||||
(let [chan (to-result (.createDirectChannel client (id me) user-id))]
|
||||
(client/open-channel! self (id chan))))
|
||||
|
||||
(mark-read! [_ chan-id]
|
||||
(let [chan-view (ChannelView. chan-id)]
|
||||
(let-result [views (to-result (.viewChannel client (id me) chan-view))]
|
||||
(if-let [view-time (channel-last-view views chan-id)]
|
||||
(success view-time)
|
||||
(failure (str "unable to mark read, not found: " chan-id)
|
||||
{:channel-views views})))))
|
||||
(let [chan-view (ChannelView. chan-id)
|
||||
views (to-result (.viewChannel client (id me) chan-view))]
|
||||
(if-let [view-time (channel-last-view views chan-id)]
|
||||
view-time
|
||||
(throw (ex-info (str "unable to mark read, not found: " chan-id)
|
||||
{:channel-views views})))))
|
||||
|
||||
(get-post! [_ post-id]
|
||||
(to-result (.getPost client post-id nil)))
|
||||
|
@ -135,11 +133,13 @@
|
|||
(get-me! [_]
|
||||
(to-result (.getMe client nil)))
|
||||
(initialize! [self]
|
||||
(map-success (client/get-me! self) (fn [me] (->BebotClient client me)))))
|
||||
(->> self
|
||||
(client/get-me!)
|
||||
(->BebotClient client))))
|
||||
|
||||
(defn create-connection [url access-token]
|
||||
(->BebotClientStub (doto (MattermostClient. url)
|
||||
(.setAccessToken access-token))))
|
||||
|
||||
(defn connect [url access-token]
|
||||
(client/initialize! (create-connection url access-token)))
|
||||
(client/initialize! (create-connection url access-token)))
|
||||
|
|
Loading…
Reference in New Issue