]> git.plutz.net Git - httpchat/blobdiff - channel.sh
introduce nickname registration
[httpchat] / channel.sh
index eab42fc6d9b07f012735c384ef050b7037cbbe6a..1f86e5214c061525e5e6486c9db93f03f6367c00 100755 (executable)
@@ -1,11 +1,5 @@
 #!/bin/sh
 
-if [ "$(COOKIE nick)" ]; then
-  nickname="?$(COOKIE nick)"
-else
-  nickname='?Guest'
-fi
-  
 if [ -f "$chatfile" ]; then
   read -r channelkey x <"$chatfile"
   channelkey="$( printf '%s-%s' "$channelkey" "$SESSION_ID" |sha256sum)"
@@ -24,47 +18,38 @@ case $(POST action) in
     fi
     REDIRECT "$(URL "/$LOCATION")"
     ;;
-  nick)
-    SET_COOKIE +1209600 "nick=$(POST nickname |URL)"
-    REDIRECT "$(URL "/$LOCATION")"
-    ;;
-  *) if [ ! -f "$chatfile" ]; then
-      yield_page create <<-EOF
-       [form #nonexist method=POST action="$(URL "/$LOCATION")"
-           There is no channel named $(HTML "$LOCATION")
-           [submit "action" "create" Create]
-        ]
+esac
+
+if [ ! -f "$chatfile" ]; then
+  yield_page create <<-EOF
+       [form #nonexist method="POST"
+          There is no channel named $(HTML "$LOCATION")
+          [submit "action" "create" Create]
+       ]
        EOF
-    else
-      { printf '
-        [form #channel method=POST action="%s"
-          [submit "action" "submit" style="display: none;"]
-          [input type=hidden name=channelkey value="%s"]
-          %s [input name="message" autofocus=true][submit "action" "submit" Send!]
-        ]
-      ' "$(URL "/$LOCATION")" "$channelkey" "$(settings_menu)"
-      SHESCAPE='s;[]&<>#."[];\\&;g;'
+else
+  printf '%s: %s\r\n' Refresh 1
+  { printf '
+    [form #channel method="POST"
+      [submit "action" "submit" style="display: none;"]
+      [input type=hidden name=channelkey value="%s"]
+      [a .settings href="?settings#nick" Settings][input autocomplete="off" name="message" autofocus=true][submit "action" "submit" Send!]
+    ]
+  ' "$channelkey"
+  SHESCAPE='s;[]&<>#."[];\\&;g;'
 
-      printf '[div #chat'
-      # tail -n30 -f "$chatfile" | {
-      #   read x
-      #   while read -r date nick message; do
-      #     printf '[p .message [span .date %s] [span .nick [span .indicator %s]%s:] [span .message %s]]\n' \
-      #            "${date#*_}" "${nick%${nick#?}}" "$(UNSTRING "${nick#?}" |HTML)" "$(UNSTRING "$message" |HTML)"
-      #     done
-      #   }
-      tail -n50 -f "$chatfile" \
-      | sed -nuE '
-        /^[^ ]+ [^ ]+ [^ ]+$/{
-        h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;;         s;.+;[p .message [span .date &];p;
-        g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
-        g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
-        }
-        b; :ESC
-        '"$UNSTRING"' '"$SHESCAPE"'
-        /^a/bA; /^b/bB;
-        '
-      } |yield_page channel
-    fi 
-    ;;
-esac
+  while sleep 10; do printf '\n'; done &
+  printf '[div #chat'
+  tail --pid $$ -n50 -f "$chatfile" \
+  | sed -nuE '
+    /^[^ ]+ [^ ]+ [^ ]+$/{
+    h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;;         s;.+;[p .message [span .date &];p;
+    g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
+    g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
+    }
+    b; :ESC
+    '"$UNSTRING"' '"$SHESCAPE"'
+    /^a/bA; /^b/bB;
+    '
+  } |yield_page channel
+fi