nandi/frqpublic Fork 0
c0121fead9e4d8106da374c9f69746212f02914c
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Share the chats screen, and the four things under it 1f55e68 · on c0121fead9e4d8106da374c9f69746212f02914c · nandi · 7d ago
rooms.cljc · 35 lines · 1.4 KBText Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns frq.rooms
  "What the conversation list is, derived from the cells it is held in.

  Pure, and so shared: `channel-list` is a filter and a sort over
  `frq.cells/channels` and the search box, `dm?` is a question about a name,
  `last-preview` reads the last message of a buffer. `frq.state` re-defs all
  three, so the thousand lines below them did not move."
  (:require [clojure.string :as str]
            [frq.cells :as cells]))

(defn dm?
  "Whether a buffer is a conversation with a person rather than a room. Every
  channel name starts with `#`; what does not is somebody's nick."
  [name]
  (and (seq name) (not (str/starts-with? name "#"))))

(defn last-preview [buffer]
  (if-let [m (last (:messages buffer))]
    (str (:from m) ": " (:text m))
    "No messages yet"))

(defn channel-list
  "Buffers most recently opened first, filtered by the search box.

  A conversation list is read from the top, and the one you were just in is the
  one you are most likely to want again. Buffers never opened — a DM that
  arrived, a channel someone mentioned — sort under those, by name, rather than
  jumping the queue."
  []
  (let [q (str/lower-case (str/trim @cells/search))]
    (->> (vals @cells/channels)
         (filter #(or (str/blank? q)
                      (str/includes? (str/lower-case (:name %)) q)))
         (sort-by (juxt #(- (:accessed % 0)) :name))
         vec)))