1
0
mirror of https://github.com/Rudi9719/kbtui.git synced 2026-03-22 08:47:24 +00:00
Files
kbtui/userTags.go
Casper Weiss Bang 023f22a1ea More User Info
Added:
- `/inspect` (`/id`)
- `/follow`
- `/unfollow`
2019-12-01 20:42:59 +01:00

59 lines
1.4 KiB
Go

package main
import (
"fmt"
"strings"
)
var followedInSteps = make(map[string]int)
var trustTreeParent = make(map[string]string)
func clearFlagCache() {
followedInSteps = make(map[string]int)
trustTreeParent = make(map[string]string)
}
var maxDepth = 4
func generateFollowersList() {
// Does a BFS of followedInSteps
queue := []string{k.Username}
printInfo("Generating Tree of Trust...")
lastDepth := 1
for len(queue) > 0 {
head := queue[0]
queue = queue[1:]
depth := followedInSteps[head] + 1
if depth > maxDepth {
continue
}
if depth > lastDepth {
printInfo(fmt.Sprintf("Trust generated at Level #%d", depth-1))
lastDepth = depth
}
bytes, _ := k.Exec("list-following", head)
bigString := string(bytes)
following := strings.Split(bigString, "\n")
for _, user := range following {
if followedInSteps[user] == 0 && user != k.Username {
followedInSteps[user] = depth
trustTreeParent[user] = head
queue = append(queue, user)
}
}
}
printInfo(fmt.Sprintf("Trust-level estabilished for %d users", len(followedInSteps)))
}
func getUserFlags(username string) StyledString {
tags := ""
followDepth := followedInSteps[username]
if followDepth == 1 {
tags += fmt.Sprintf(" %s", config.Formatting.IconFollowingUser)
} else if followDepth > 1 {
tags += fmt.Sprintf(" %s%d", config.Formatting.IconIndirectFollowUser, followDepth-1)
}
return config.Colors.Message.SenderTags.stylize(tags)
}