commit 9912da4a2186fe59e5f4f1d8f36913a20b43ff15
parent 3731f370a862297913c0be3ecb6f59e81188fb32
Author: hhvn <hayden@haydenvh.com>
Date: Thu, 4 Feb 2021 11:58:46 +0000
bin/interface.sh include/userinfo.sh: add k command for marking posts as read
Diffstat:
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/bin/interface.sh b/bin/interface.sh
@@ -43,7 +43,7 @@ menu_boards(){
"$(eval "echo \$board_${b2}_desc")"
done | pager 5 $(echo "$banner" | wc -l)
printf '=======================================================================Page:%- 3d=\n' "$page"
- while prompt "Ne${k}x${s}t ${k}$([ $page -eq 0 ] && printf "${e}")p${s}revious ${k}u${s}sers ${k}s${s}elect rel${k}o${s}ad intro${k}d${s}uction ${k}h${s}elp" input
+ while prompt "Ne${k}x${s}t ${k}$([ $page -eq 0 ] && printf "${e}")p${s}revious ${k}u${s}sers ${k}s${s}elect rel${k}o${s}ad intro${k}d${s}uction mar${k}k${s} ${k}h${s}elp" input
do
parse_in "$input"
case "$cmd" in
@@ -67,6 +67,14 @@ menu_boards(){
d) cat $cwd/etc/intro ;;
u) set_mode users; break ;;
o) break ;;
+ k)
+ [ "$arg" = "" ] && markread_all "$user" && break
+ [ "$arg" != "" ] && board=$(echo "$boards" | tr ' ' '\n' | grep -i "$arg" | head -n 1 | tr '[:upper:]' '[:lower:]')
+ [ "$board" = "" ] && error "no such board" || {
+ markread_board "$board" "$user"
+ break
+ }
+ ;;
h) cat <<- EOF
<cmd> <arg>
@@ -76,6 +84,7 @@ menu_boards(){
d - veiw introduction
u - go to the users menu
o - reload the current menu
+ m - mark read all or <arg> board
h - show this help
(help varies depending on current menu)
diff --git a/include/userinfo.sh b/include/userinfo.sh
@@ -52,6 +52,39 @@ markread(){
unlock $datadir/boards/$1/list
}
+markread_board(){
+ lock $datadir/boards/$1/list
+ awk -v "user=$2" -F " " '
+ BEGIN {OFS="\t"}
+ {
+ n = ""
+ for (i=8; i <= NF; i++)
+ if ($i != user)
+ n = sprintf("%s\t%s", n, $i)
+ print $1, $2, $3, $4, $5, $6, $7, n
+ }' < $datadir/boards/$1/list > $datadir/boards/$1/list.new
+ mv $datadir/boards/$1/list.new $datadir/boards/$1/list
+ unlock $datadir/boards/$1/list
+}
+
+markread_all(){
+ for d in $datadir/boards/*
+ do
+ lock $d/list
+ awk -v "user=$1" -F " " '
+ BEGIN {OFS="\t"}
+ {
+ n = ""
+ for (i=8; i <= NF; i++)
+ if ($i != user)
+ n = sprintf("%s\t%s", n, $i)
+ print $1, $2, $3, $4, $5, $6, $7, n
+ }' < $d/list > $d/list.new
+ mv $d/list.new $d/list
+ unlock $d/list
+ done
+}
+
checknuser(){
[ "$(userget $1 expiry)" != "" ] && [ $(datediff $(userget $1 expiry) 2021-02-02) -gt -1 ] && rm $datadir/users/$1
[ -f $datadir/users/$1 ] && error "user already exists" && return 1