package main // Exhibit 5. The directory is open to every app, so a brand-new app can find people who have never // used it. The zoo only searches for signed-in people, so it is not an open directory for the whole // internet. import "core:strings" import "ratcloud:rc" e05 :: proc() -> Exhibit { return { n = 5, try_ = "find a friend", wing = "Identity", title = "Find a friend", promise = "Any app can search for people by name, including people who have never used it.", block = "rc.search_users(q) finds people by the start of their username or of any word of their name, across the whole platform.", src = {"e05_find_a_friend.odin", #load("e05_find_a_friend.odin", string)}, script = {"web/e05.js", #load("web/e05.js", string)}, show = proc(me: ^rc.User) -> string { if me == nil do return signin_line("to search for people.") return `
` }, api = proc(a: ^Api) -> bool { if a.do_ != "search" do return false if a.me == nil {reply_err(a, 401, "sign in to search"); return true} reply(a, struct { users: []rc.User `json:"users"`, }{rc.search_users(in_str(a, "q"), 12)}) return true }, // rc-check is root's robot: it has an account but has never used the zoo. check = proc() -> Check { hits := rc.search_users("rc-check", 5) names := make([dynamic]string) for u in hits { if u.username == "rc-check" do return pass("found @rc-check, who has an account but has never used the zoo") append(&names, u.username) } return fail(cat(`searching "rc-check" did not find root's robot, who has an account`, cat(" (found: ", strings.join(names[:], ", "), ")") if len(names) > 0 else "")) }, } }