about summary refs log tree commit diff stats
path: root/browse-slack
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-08-13 13:40:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-08-13 13:40:33 -0700
commitf810852ed2ab6c4394cdca68df8dd6fb4344b319 (patch)
tree9d6c4496a7725e1499fc44d5fecc4f66c51114d0 /browse-slack
parenta83095b209bbbf302b49a0e66109cd04458ff7e5 (diff)
downloadmu-f810852ed2ab6c4394cdca68df8dd6fb4344b319.tar.gz
slack: new view: top-level posts from a channel
- No way yet in the UI to switch views
- Pagination doesn't work yet; it's going to require more duplication :/
Diffstat (limited to 'browse-slack')
-rw-r--r--browse-slack/environment.mu53
-rw-r--r--browse-slack/main.mu44
-rw-r--r--browse-slack/test_data8
3 files changed, 96 insertions, 9 deletions
diff --git a/browse-slack/environment.mu b/browse-slack/environment.mu
index 35f6f1d8..5f192334 100644
--- a/browse-slack/environment.mu
+++ b/browse-slack/environment.mu
@@ -47,7 +47,7 @@ fn render-environment screen: (addr screen), env: (addr environment), users: (ad
   clear-screen screen
   render-search-input screen, env
   render-channels screen, env, channels
-  render-item-list screen, env, items, users
+  render-item-list screen, env, items, channels, users
   render-menu screen
 }
 
@@ -75,7 +75,7 @@ fn render-channels screen: (addr screen), env: (addr environment), _channels: (a
   }
 }
 
-fn render-item-list screen: (addr screen), _env: (addr environment), items: (addr item-list), users: (addr array user) {
+fn render-item-list screen: (addr screen), _env: (addr environment), items: (addr item-list), channels: (addr array channel), users: (addr array user) {
   var env/esi: (addr environment) <- copy _env
   var tmp-width/eax: int <- copy 0
   var tmp-height/ecx: int <- copy 0
@@ -92,13 +92,13 @@ fn render-item-list screen: (addr screen), _env: (addr environment), items: (add
   var current-tab-index/eax: int <- copy *current-tab-index-a
   var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
   var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
-  render-tab screen, current-tab, items, users, screen-height
+  render-tab screen, current-tab, items, channels, users, screen-height
   var top/eax: int <- copy screen-height
   top <- subtract 2/menu-space-ver
   clear-rect screen, 0 top, screen-width screen-height, 0/bg
 }
 
-fn render-tab screen: (addr screen), _current-tab: (addr tab), items: (addr item-list), users: (addr array user), screen-height: int {
+fn render-tab screen: (addr screen), _current-tab: (addr tab), items: (addr item-list), channels: (addr array channel), users: (addr array user), screen-height: int {
   var current-tab/esi: (addr tab) <- copy _current-tab
   var current-tab-type/eax: (addr int) <- get current-tab, type
   compare *current-tab-type, 0/all-items
@@ -107,11 +107,17 @@ fn render-tab screen: (addr screen), _current-tab: (addr tab), items: (addr item
     render-all-items screen, current-tab, items, users, screen-height
     return
   }
+  compare *current-tab-type, 1/channel
+  {
+    break-if-!=
+    render-channel-tab screen, current-tab, items, channels, users, screen-height
+    return
+  }
 }
 
 fn render-all-items screen: (addr screen), _current-tab: (addr tab), _items: (addr item-list), users: (addr array user), screen-height: int {
+  var current-tab/esi: (addr tab) <- copy _current-tab
   var items/edi: (addr item-list) <- copy _items
-  var current-tab/edx: (addr tab) <- copy _current-tab
   var newest-item/eax: (addr int) <- get current-tab, item-index
   var i/ebx: int <- copy *newest-item
   var items-data-first-free-addr/eax: (addr int) <- get items, data-first-free
@@ -134,6 +140,43 @@ fn render-all-items screen: (addr screen), _current-tab: (addr tab), _items: (ad
   }
 }
 
+fn render-channel-tab screen: (addr screen), _current-tab: (addr tab), _items: (addr item-list), _channels: (addr array channel), users: (addr array user), screen-height: int {
+  var current-tab/esi: (addr tab) <- copy _current-tab
+  var items/edi: (addr item-list) <- copy _items
+  var channels/ebx: (addr array channel) <- copy _channels
+  var channel-index-addr/eax: (addr int) <- get current-tab, root-index
+  var channel-index/eax: int <- copy *channel-index-addr
+  var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
+  var current-channel/ecx: (addr channel) <- index channels, channel-offset
+  var current-channel-posts-ah/eax: (addr handle array int) <- get current-channel, posts
+  var _current-channel-posts/eax: (addr array int) <- lookup *current-channel-posts-ah
+  var current-channel-posts/edx: (addr array int) <- copy _current-channel-posts
+  var current-channel-first-channel-item-addr/eax: (addr int) <- get current-tab, item-index
+  var i/ebx: int <- copy *current-channel-first-channel-item-addr
+  var current-channel-posts-first-free-addr/eax: (addr int) <- get current-channel, posts-first-free
+  set-cursor-position 0/screen, 0x68/x 0/y
+  draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "channel", 7/fg 0/bg
+  render-progress screen, i, *current-channel-posts-first-free-addr
+  var items-data-ah/eax: (addr handle array item) <- get items, data
+  var _items-data/eax: (addr array item) <- lookup *items-data-ah
+  var items-data/edi: (addr array item) <- copy _items-data
+  var y/ecx: int <- copy 2/search-space-ver
+  y <- add 1/item-padding-ver
+  {
+    compare i, 0
+    break-if-<
+    compare y, screen-height
+    break-if->=
+    var item-index-addr/eax: (addr int) <- index current-channel-posts, i
+    var item-index/eax: int <- copy *item-index-addr
+    var item-offset/eax: (offset item) <- compute-offset items-data, item-index
+    var curr-item/eax: (addr item) <- index items-data, item-offset
+    y <- render-item screen, curr-item, users, y, screen-height
+    i <- decrement
+    loop
+  }
+}
+
 # side-effect: mutates cursor position
 fn render-progress screen: (addr screen), curr: int, max: int {
   set-cursor-position 0/screen, 0x70/x 0/y
diff --git a/browse-slack/main.mu b/browse-slack/main.mu
index 20087524..5f8b43ed 100644
--- a/browse-slack/main.mu
+++ b/browse-slack/main.mu
@@ -83,6 +83,36 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
   var env-storage: environment
   var env/ebx: (addr environment) <- address env-storage
   initialize-environment env, items
+  # TEMPORARY
+  {
+    var tabs-ah/eax: (addr handle array tab) <- get env, tabs
+    var tabs/eax: (addr array tab) <- lookup *tabs-ah
+    var first-tab/eax: (addr tab) <- index tabs, 0/current-tab-index
+    var dest/edi: (addr int) <- get first-tab, type
+    copy-to *dest, 1/channel
+    dest <- get first-tab, root-index
+    copy-to *dest, 0/channel-general
+    dest <- get first-tab, item-index
+    var channel-index/eax: int <- copy 0  # turns out we currently can't pass literal directly to channels; should be an easy gap to fill
+    var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
+#?     {
+#?       var foo/eax: int <- copy channel-offset
+#?       draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 7/fg 0/bg
+#?     }
+    var curr-channel/eax: (addr channel) <- index channels, channel-offset
+#?     {
+#?       var foo/eax: int <- copy curr-channel
+#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 4/fg 0/bg
+#?     }
+    var curr-channel-posts-first-free-addr/eax: (addr int) <- get curr-channel, posts-first-free
+    var curr-channel-final-post-index/eax: int <- copy *curr-channel-posts-first-free-addr
+#?     set-cursor-position 0/screen, 0x20 0x20
+#?     draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, curr-channel-final-post-index, 4/fg 0/bg
+#?     abort "aaa"
+    curr-channel-final-post-index <- decrement
+    copy-to *dest, curr-channel-final-post-index
+  }
+  #
   {
     render-environment screen, env, users, channels, items
     {
@@ -325,17 +355,31 @@ fn parse-item record: (addr stream byte), _channels: (addr array channel), _item
   next-json-string record, s
   var dest/eax: (addr handle array byte) <- get item, channel
   stream-to-array s, dest
+#?   set-cursor-position 0/screen, 0x70 item-idx
   # cross-link to channels
   {
     var channels/esi: (addr array channel) <- copy _channels
     var channel-index/eax: int <- find-or-insert channels, s
+#?     draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, channel-index, 5/fg 0/bg
     var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
     var channel/eax: (addr channel) <- index channels, channel-offset
+#?     {
+#?       var foo/eax: int <- copy channel
+#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 4/fg 0/bg
+#?     }
     var channel-posts-ah/ecx: (addr handle array int) <- get channel, posts
     var channel-posts-first-free-addr/edx: (addr int) <- get channel, posts-first-free
+#?     {
+#?       var foo/eax: int <- copy channel-posts-first-free-addr
+#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 4/fg 0/bg
+#?     }
     var channel-posts-first-free/ebx: int <- copy *channel-posts-first-free-addr
+#?     draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, channel-posts-first-free, 3/fg 0/bg
     var channel-posts/eax: (addr array int) <- lookup *channel-posts-ah
     var dest/eax: (addr int) <- index channel-posts, channel-posts-first-free
+    var src/ecx: int <- copy item-idx
+    copy-to *dest, src
+    increment *channel-posts-first-free-addr
   }
   # user index
   {
diff --git a/browse-slack/test_data b/browse-slack/test_data
index 003d8015..b45b3015 100644
--- a/browse-slack/test_data
+++ b/browse-slack/test_data
@@ -6436,16 +6436,16 @@ P3
 ("1497638207.803814" -1 "general" 3 "That looks like an amazing study guide -- thanks for sharing! I personally don't know of any such collection of resources for the future of programming so I love the idea about starting one")
 ("1497639648.282491" -1 "general" 3 "I'd love to help with that. Maybe start on google docs so we can quickly aggregate a number of links?")
 ("1497731617.002526" -1 "general" 7 "<@UA18GGGGG> has joined the channel")
-("1498011970.183304" -1 "general" 2 "hey @all there's a good chance i won't make the next meeting (July 3rd).  i can try to help coordinate though if people are interseted in meeting.  <@UA14GGGGG> were you still planning to host at your office?")
-("1498056094.017893" -1 "general" 3 "Ah bummer - could you do the following week <@UA13GGGGG>?")
+("1498011970.183304" -1 "random" 2 "hey @all there's a good chance i won't make the next meeting (July 3rd).  i can try to help coordinate though if people are interseted in meeting.  <@UA14GGGGG> were you still planning to host at your office?")
+("1498056094.017893" -1 "random" 3 "Ah bummer - could you do the following week <@UA13GGGGG>?")
 ("1498067103.676667" -1 "general" 8 "<@UA19GGGGG> has joined the channel")
 ("1498159676.539946" -1 "general" 3 "Have y'all seen Luna Lang? <http://www.luna-lang.org/> it's on the top of HN today. I've tried to get access in the past but it seems like I may just have to be patient until they're in public beta")
 ("1498163656.952445" -1 "general" 4 "I havent, unless maybe someone brought it up at the last meeting")
 ("1498240486.121076" 9 "general" 3 "stefan: I created a google doc for this but I'm already becomming overwhelmed with this project... <https://docs.google.com/document/d/1TtfMqBBRGnwisCx42nuXa4Y5VF3EizpZxFQBivJWhhE/edit>\n\nThoughts on organization?")
 ("1498272401.219123" 9 "general" 1 "Looks good. I have to look at more of the links to come up with ideas to organize it.")
-("1498322070.622332" -1 "general" 4 "<!here|@here> I will be out of town as well on July 3rd.\n\nHow do we feel about moving the July meeting to the following week, July 10th?")
+("1498322070.622332" -1 "random" 4 "<!here|@here> I will be out of town as well on July 3rd.\n\nHow do we feel about moving the July meeting to the following week, July 10th?")
 ("1498322131.626321" 9 "general" 4 "What types of software solutions exists for this? Would a sub reddit be a better system? Disclaimer I haven\u2019t looked at the googledoc yet.")
-("1498403781.149763" -1 "general" 3 "sounds great to me!")
+("1498403781.149763" -1 "random" 3 "sounds great to me!")
 ("1498403819.151825" 9 "general" 3 "Yeah, I was thinking the same thing <@UA15GGGGG> - a subreddit system could be neat. Or maybe even a wiki solution...?")
 ("1498403846.153364" 9 "general" 3 "However, I don't want to over-engineer this. Potentially good categories or tags is enough")
 ("1498403868.154588" 9 "general" 3 "We could create a github issue for each link so we could comment on it there")