hbbs

bbs.hlirc.net
Log | Files | Refs | README | LICENSE

commit 3731f370a862297913c0be3ecb6f59e81188fb32
parent fed33d13ec178dc29265ceb4d974e7c1b14ffd38
Author: hhvn <hayden@haydenvh.com>
Date:   Thu,  4 Feb 2021 11:24:31 +0000

bin/interface.sh include/userinfo.sh: add new/unread system

Diffstat:
Mbin/interface.sh | 47++++++++++++++++++++++++++++++++++++++---------
Minclude/userinfo.sh | 24++++++++++++++++++++++++
2 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/bin/interface.sh b/bin/interface.sh @@ -5,6 +5,9 @@ k=$(tput setaf $key___colour) e=$(tput setaf $error_colour) +N=$(tput setaf $new___colour) +U=$(tput setaf $num___colour) +D=$(tput setaf $date__colour) s=$(tput sgr0) set_mode(){ @@ -31,9 +34,10 @@ menu_boards(){ for b in $boards do b2=$(echo "$b" | tr '[:upper:]' '[:lower:]') + new=$(awk -v "user=$user" -F" " '{for (i=8; i<=NF; i++) if ($i == user) print}' < $datadir/boards/$b2/list | wc -l) printf '%- 20s [%s% 4d%s] %s\n' \ "$b" \ - "$(tput setaf $num___colour)" \ + "$([ $new -ne 0 ] && printf "$N" || printf "$U")" \ "$(awk '$4 != "root"' < $datadir/boards/$b2/list | wc -l)" \ "${s}" \ "$(eval "echo \$board_${b2}_desc")" @@ -89,10 +93,18 @@ menu_list(){ [ ! -f $datadir/boards/$board/list ] && echo "1 0 01-Jan-1970 root empty" > $datadir/boards/$board/list echo " ID Date User Subject " echo ================================================================================ - awk -v "n=1" -v "c0=${s}" -v "c1=$(tput setaf $num___colour)" -v "c2=$(tput setaf $date__colour)" -F" " \ - '$1 != n {print "--------------------------------------------------------------------------------"} - $4 != "root" {printf("%s% 3s.%- 3s%s [%s%s%s] %- 10s | %s\n", c1, $1, $2, c0, c2, $3, c0, $4, $5); n=$1} - $4 == "root" {print ""}' < $datadir/boards/$board/list | pager 5 $(echo "$banner" | wc -l) + awk -v "n=1" -v "c0=${s}" -v "c1=${U}" -v "c2=${D}" -v "c3=${N}" -v "user=$user" -F" " ' + $1 != n {print "--------------------------------------------------------------------------------"} + $4 != "root" { + n = "" + for (i=8; i<=NF; i++) + if ($i == user) + n = c3 + + printf("%s% 3s.%- 3s%s [%s%s%s] %- 10s | %s%s%s\n", c1, $1, $2, c0, c2, $3, c0, $4, n, $5, c0); + n = $1 + } + $4 == "root" {print ""}' < $datadir/boards/$board/list | pager printf '=%- 10s============================================================Page:%- 3d=\n' "$(echo "$board" | tr '[:lower:]' '[:upper:]')" "$page" | tr ' ' '=' | sed 's/==$/ =/;s/:=/: /' while prompt "Ne${k}x${s}t ${k}$([ $page -eq 0 ] && printf "${e}")p${s}revious ${k}b${s}oards rel${k}o${s}ad ${k}r${s}ead ${k}$(check_post_perm $board $user noprint || printf "${e}")n${s}ew ${k}h${s}elp" input do @@ -134,8 +146,14 @@ menu_list(){ break } lock $datadir/boards/$board/list - awk -v "data=1 0 $(date +%d-%b-%Y) $user $subject $(basename $file)" -F" " \ - 'BEGIN {print data}; $4 != "root" {print $1 + 1 "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t" $7}' \ + awk -v "data=1 0 $(date +%d-%b-%Y) $user $subject $(basename $file) $(basename $file) $(userlist "$user")" -F" " \ + 'BEGIN {print data} + $4 != "root" { + ul="" + for (i=8; i<=NF; i++) + ul = sprintf("%s\t%s", ul, $i) + print $1 + 1 "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t" $7 ul + }' \ < $datadir/boards/$board/list > $datadir/boards/$board/list.new mv $datadir/boards/$board/list.new $datadir/boards/$board/list unlock $datadir/boards/$board/list @@ -176,6 +194,7 @@ pager2(){ } menu_read(){ + markread "$board" "$user" "$id" id2=${id##*.} [ $id2 -eq 0 ] && clear file=$(awk -v "id1=${id%%.*}" -v "id2=${id2}" -F" " '$1 == id1 && $2 == id2 {print $6 " " $7}' < $datadir/boards/$board/list) @@ -220,9 +239,19 @@ menu_read(){ } lnum=$(echo "$(awk -v "file=$(echo "$ofile" | sed 's/ .*//')" -F" " '$6 == file' < $datadir/boards/$board/list | wc -l) - 1" | bc) lock $datadir/boards/$board/list - awk -v "n=1" -v "file=$(basename "$file")" -v "lnum=$lnum" -v "user=$user" -v "date=$(date +%d-%b-%Y)" -v "ofile=$(echo "$ofile" | sed 's/ .*//')" -F" " ' + awk \ + -v "n=1" \ + -v "file=$(basename "$file")" \ + -v "lnum=$lnum" \ + -v "user=$user" \ + -v "date=$(date +%d-%b-%Y)" \ + -v "ofile=$(echo "$ofile" | sed 's/ .*//')" \ + -v "ul=$(userlist "$user")" -F" " ' $6 == ofile && $2 != lnum {print} - $6 == ofile && $2 == lnum {print; print $1 "\t" lnum + 1 "\t" date "\t" user "\t-->\t" ofile "\t" file} + $6 == ofile && $2 == lnum { + print + print $1 "\t" lnum + 1 "\t" date "\t" user "\t-->\t" ofile "\t" file "\t" ul + } $6 != ofile ' < $datadir/boards/$board/list > $datadir/boards/$board/list.new mv $datadir/boards/$board/list.new $datadir/boards/$board/list diff --git a/include/userinfo.sh b/include/userinfo.sh @@ -28,6 +28,30 @@ userget(){ }' < $datadir/users/$1 2>/dev/null } +userlist(){ + for u in $datadir/users/* + do + u2=$(basename $u) + [ "$u2" != "$1" ] && printf "%s\t" "$u2" + done +} + +markread(){ + lock $datadir/boards/$1/list + awk -v "user=$2" -v "id1=${3%%.*}" -v "id2=${3##*.}" -F" " ' + BEGIN {OFS="\t"} + $1 != id1 || $2 != id2 + $1 == id1 && $2 == id2 { + 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 +} + 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