Skip to content

Commit 85202ac

Browse files
committed
Merge remote-tracking branch 'origin/emoji-reactions' into main
2 parents f637c1a + 41a4da2 commit 85202ac

File tree

11 files changed

+22978
-1971
lines changed

11 files changed

+22978
-1971
lines changed

bin/update_emoji_json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
wget https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json -O resources/emojis.json

profiles/dev/user.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
(ns user
22
(:require [reloaded.repl :as reloaded]))
33

4+
(alter-var-root #'*print-namespace-maps* (constantly false))
5+
;; (set! *print-namespace-maps* false)
6+
47
(defmacro jit [sym]
58
`(or (resolve '~sym)
69
(do

repl/reactions.clj

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
(ns repl.reactions
2+
(:require [clojurians-log.application :as app]
3+
[clojure.java.io :as io]
4+
[clojurians-log.slack-api :as slack]
5+
[clojurians-log.db.queries :as q]
6+
[clojurians-log.db.import :as import]
7+
[clojurians-log.data :as data]
8+
[clj-slack.emoji :as slack-emoji]
9+
[clojure.java.io :as io]
10+
[clojurians-log.datomic :as d]
11+
[clojure.tools.reader.edn :as edn]
12+
[clojure.string :as str]
13+
[clojure.core.async :as async :refer [>!! <! >! go-loop go <!!]]
14+
[clojure.data.json :as json])
15+
(:use [clojurians-log.repl]))
16+
17+
(d/q '[:find (pull ?m [* {:reaction/_message [{:reaction/emoji [:emoji/shortcode :emoji/url]}]}])
18+
:where
19+
;; [?u :user/name "borkdude"]
20+
;; [?m :message/day "2018-02-08"]
21+
[?m :message/channel ?chan]
22+
[?chan :channel/name "announcements"]]
23+
(db))
24+
25+
(q/channel-day-messages (db) "aleph" "2018-02-08")
26+
27+
(d/q '[:find (pull ?r [*]) (pull ?m [*])
28+
:where
29+
[?u :user/name "borkdude"]
30+
[?m :message/day "2018-02-08"]
31+
[?m :message/channel ?chan]
32+
[?chan :channel/name "aleph"]
33+
[?r :reaction/message ?m]]
34+
(db))
35+
36+
(d/q '[:find ?m ?r
37+
:where
38+
[?r :reaction/message ?m]]
39+
(db))
40+
41+
(d/q '[:find (pull ?r [*])
42+
:where
43+
[?r :reaction/type]]
44+
(db))
45+
46+
;; find a message by key
47+
(d/q '[:find (pull ?m [*])
48+
:where
49+
[?m :message/key "C0E1SN0NM--1604347443.149900"]]
50+
(db))
51+
52+
53+
(comment
54+
;; add some emojis
55+
(d/transact (conn) [{:emoji/shortcode "+1" :emoji/url "url1"}])
56+
(d/transact (conn) [{:emoji/shortcode "joy" :emoji/url "url1"}])
57+
(d/q '[:find (pull ?e [*]) :where [?e :emoji/shortcode]] (db))
58+
(d/q '[:find (pull ?e [*]) :where [?e :emoji/shortcode "sheepy"]] (db))
59+
60+
;; add default emojis
61+
(def default-emojis
62+
(with-open [r (io/reader (io/resource "emojis.json"))]
63+
(let [emoji-list (-> (json/read r :key-fn keyword) :emojis)]
64+
(map #(hash-map :emoji/shortcode (:name %)) emoji-list))))
65+
66+
(def emlist (with-open [r (io/reader (io/resource "emojis.json"))]
67+
(let [emoji-list (-> (json/read r :key-fn keyword))]
68+
emoji-list)))
69+
70+
71+
(into {} (map (comp first #(for [alias (:aliases %)] [alias (:emoji %)])) emlist))
72+
73+
(d/transact (conn) default-emojis)
74+
(d/q '[:find (pull ?e [*]) :where [?e :emoji/shortcode]] (db))
75+
76+
(def emcoll (slack-emoji/list {:api-url "https://slack.com/api"
77+
;; TODO: get rid of this global config access
78+
:token ""}))
79+
80+
(doseq [emojis (partition-all 1000 (:emoji emcoll))]
81+
@(d/transact (conn) (mapv import/emoji->tx emojis)))
82+
83+
(load-demo-data! "../clojurians-log-demo-data2")
84+
)
85+
86+
(comment
87+
(d/q '[:find ?eid :in $ ?eid :where [?eid]] (db) 17592186091857))
88+
89+
(comment
90+
(d/transact (conn) [{:db/id 17592186091852 :emoji/shortcode "joy" :emoji/url "url1"}])
91+
92+
(d/transact (conn) [{:db/ident :emoji/shortcode
93+
:db/index true}])
94+
95+
(d/transact (conn) [{:db/ident :emoji/shortcode
96+
:db/unique :db.unique/identity}])
97+
98+
(d/transact (conn) [{:reaction/type "reaction_added"
99+
:reaction/emoji [:emoji/shortcode "+1"]
100+
:reaction/ts "1001"
101+
:reaction/user [:user/name "plexus"]
102+
:reaction/message [:message/key "C0G922PCH--1518108773.000057"]}])
103+
104+
(d/q '[:find (pull ?m [*])
105+
:where
106+
[?m :message/key "C0G922PCH--1518108773.000057"]]
107+
(db)))
108+
109+

resources/emojis.json

Lines changed: 22653 additions & 1810 deletions
Large diffs are not rendered by default.

src/clojurians_log/db/import.clj

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{:pre [(string? ts) (string? channel)]}
1919
(str channel "--" ts))
2020

21-
(defmulti event->tx :subtype)
21+
(defmulti event->tx (juxt :type :subtype))
2222

2323
(defmethod event->tx :default [_]
2424
;; return nil by default, this will let us skip events we don't (yet) care
@@ -44,20 +44,20 @@
4444
:thread-inst (jt/to-java-date thread-inst)
4545
:day (time-util/format-inst-day thread-inst)}))))))
4646

47-
(defmethod event->tx nil [message]
47+
(defmethod event->tx ["message" nil] [message]
4848
(message->tx message))
4949

50-
(defmethod event->tx "message_deleted" [{:keys [deleted_ts channel] :as message}]
50+
(defmethod event->tx ["message" "message_deleted"] [{:keys [deleted_ts channel] :as message}]
5151
[(if d/cloud?
5252
:db/retractEntity
5353
:db.fn/retractEntity) [:message/key (message-key {:channel channel :ts deleted_ts})]])
5454

55-
(defmethod event->tx "message_changed" [{:keys [message channel]}]
55+
(defmethod event->tx ["message" "message_changed"] [{:keys [message channel]}]
5656
(event->tx (assoc message :channel channel)))
5757

5858
;; Thread replies which are copied to the channel. For now we only include them
5959
;; in the thread.
60-
(defmethod event->tx "thread_broadcast" [message]
60+
(defmethod event->tx ["message" "thread_broadcast"] [message]
6161
(message->tx message))
6262

6363
(defn user->tx [{:keys [id name real_name is_admin is_owner profile]}]
@@ -94,6 +94,19 @@
9494
#:emoji {:shortcode (name shortcode)
9595
:url url})
9696

97+
(defmethod event->tx ["reaction_added" nil] [{:keys [user item reaction item_user event_ts ts]}]
98+
{:reaction/type "reaction_added"
99+
:reaction/emoji {:emoji/shortcode reaction}
100+
:reaction/ts ts
101+
:reaction/user [:user/slack-id user]
102+
:reaction/message {:message/key (message-key item)}})
103+
104+
(defmethod event->tx ["reaction_removed" nil] [{:keys [user item reaction item_user event_ts ts]}]
105+
;; Placeholder just to show that we're getting some data.
106+
;; TODO: return Datomic transaction data to retract a reaction entity
107+
(println "-" reaction)
108+
nil)
109+
97110
(defn lines-reducible [^BufferedReader rdr]
98111
(reify clojure.lang.IReduceInit
99112
(reduce [this f init]

src/clojurians_log/db/queries.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
[:message/text
5353
:message/ts
5454
:message/thread-ts
55+
{:reaction/_message [:reaction/user
56+
:reaction/type {:reaction/emoji [*]}]}
5557
{:message/user [:user/name
5658
:user/slack-id
5759
:user-profile/real-name

0 commit comments

Comments
 (0)