Skip to content

Commit

Permalink
threads should not be showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
IoIxD committed Jul 23, 2024
1 parent e62f7dc commit cabbb57
Show file tree
Hide file tree
Showing 31 changed files with 52 additions and 37 deletions.
Empty file modified .github/pull_request_template.md
100644 → 100755
Empty file.
Empty file modified .github/workflows/ci.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified config.example.toml
100644 → 100755
Empty file.
Empty file modified database/database.go
100644 → 100755
Empty file.
Empty file modified database/postgres.go
100644 → 100755
Empty file.
Empty file modified discord.go
100644 → 100755
Empty file.
Empty file modified funcmap.go
100644 → 100755
Empty file.
Empty file modified go.mod
100644 → 100755
Empty file.
Empty file modified go.sum
100644 → 100755
Empty file.
Empty file modified main.go
100644 → 100755
Empty file.
Empty file modified message.go
100644 → 100755
Empty file.
Empty file modified resources/static/favicon.ico
100644 → 100755
Empty file.
Empty file modified resources/static/style.css
100644 → 100755
Empty file.
Empty file modified resources/templates/error.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/footer.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/forum.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/guild.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/header.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/icons.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/index.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/post.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/privacy.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/searchbar.html
100644 → 100755
Empty file.
Empty file modified resources/templates/searchforum.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/searchguild.gohtml
100644 → 100755
Empty file.
Empty file modified resources/templates/tos.gohtml
100644 → 100755
Empty file.
89 changes: 52 additions & 37 deletions server.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newServer(st *state.State, fsys fs.FS, db database.Database, config config)
})
})
})

getHead(r, "/privacy", srv.PrivacyPage)
getHead(r, "/tos", srv.TOSPage)
getHead(r, "/static/*", http.FileServer(http.FS(fsys)).ServeHTTP)
Expand Down Expand Up @@ -200,19 +200,25 @@ func (s *server) publicActiveThreads(gid discord.GuildID) ([]discord.Channel, er
if channel.Type != discord.GuildPublicThread {
continue
}
parent, err := s.discord.Cabinet.Channel(channel.ParentID)
if err != nil {
return nil, err
}
if parent.Type != discord.GuildForum {
continue
}
threads = append(threads, channel)
}
return threads, nil
}


func filter(ss []Post, test func(Post) bool) (ret []Post) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}

func (s *server) getIndex(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -298,7 +304,6 @@ func (s *server) getGuild(w http.ResponseWriter, r *http.Request) {
s.executeTemplate(w, r, "guild.gohtml", ctx)
}


func (s *server) searchGuild(w http.ResponseWriter, r *http.Request) {
s.executeTemplate(w, r, "searchguild.gohtml", nil)
}
Expand All @@ -316,32 +321,32 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("q")

if query == "" {
s.getForum(w,r)
s.getForum(w, r)
return
}

ctx := struct {
Guild *discord.Guild
Forum *discord.Channel
Posts []Post
Prev int
Next int
URL string
Query string
Guild *discord.Guild
Forum *discord.Channel
Posts []Post
Prev int
Next int
URL string
Query string
AppendedStr string
}{Guild: guild,
Forum: forum,
URL: s.URL,
Query: query,
AppendedStr: "/search?q="+query,
Forum: forum,
URL: s.URL,
Query: query,
AppendedStr: "/search?q=" + query,
}
channels, err := s.channels(guild.ID)
if err != nil {
s.displayErr(w, http.StatusInternalServerError,
fmt.Errorf("fetching guild threads: %w", err))
return
}
arr := strings.Split(query," ")
arr := strings.Split(query, " ")

if query == "" {
// Show blank page.
Expand All @@ -364,25 +369,25 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) {
}
}
if slices.Contains(titles, post.Channel.Name) {
continue;
continue
}
if strings.Contains(strings.ToLower(post.Channel.Name),query) {
if strings.Contains(strings.ToLower(post.Channel.Name), query) {
posts = append(posts, post)
titles = append(titles, post.Channel.Name)
} else {
for _, str := range(arr) {
for _, str := range arr {
if len(str) <= 1 {
continue;
continue
}
if strings.Contains(strings.ToLower(post.Channel.Name),strings.ToLower(str)) {
if strings.Contains(strings.ToLower(post.Channel.Name), strings.ToLower(str)) {
posts = append(posts, post)
titles = append(titles, post.Channel.Name)
}
}
}
}
sort.SliceStable(posts, func(i, j int) bool {
return strings.Contains(strings.ToLower(posts[i].Channel.Name),strings.ToLower(query))
return strings.Contains(strings.ToLower(posts[i].Channel.Name), strings.ToLower(query))
})
page, err := strconv.Atoi(chi.URLParam(r, "page"))
if err != nil || page < 1 {
Expand All @@ -403,8 +408,6 @@ func (s *server) searchForum(w http.ResponseWriter, r *http.Request) {
s.executeTemplate(w, r, "searchforum.gohtml", ctx)
}



type Post struct {
discord.Channel
Tags []discord.Tag
Expand All @@ -425,13 +428,13 @@ func (s *server) getForum(w http.ResponseWriter, r *http.Request) {
}

ctx := struct {
Guild *discord.Guild
Forum *discord.Channel
Posts []Post
Prev int
Next int
URL string
Query string
Guild *discord.Guild
Forum *discord.Channel
Posts []Post
Prev int
Next int
URL string
Query string
AppendedStr string
}{Guild: guild,
Forum: forum,
Expand All @@ -444,6 +447,14 @@ func (s *server) getForum(w http.ResponseWriter, r *http.Request) {
}
var posts []Post
for _, thread := range channels {
parent, err := s.discord.Cabinet.Channel(thread.ParentID)
if err != nil {
s.displayErr(w, http.StatusInternalServerError,
fmt.Errorf("fetching parent channel's type: %w", err))
}
if parent.Type != discord.GuildForum {
continue
}
if thread.ParentID != forum.ID ||
thread.Type != discord.GuildPublicThread {
continue
Expand Down Expand Up @@ -496,6 +507,10 @@ func (s *server) getPost(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}

if forum.Type != discord.GuildForum {
return
}
ctx := struct {
Guild *discord.Guild
Forum *discord.Channel
Expand Down
Empty file modified sitemap.go
100644 → 100755
Empty file.

0 comments on commit cabbb57

Please sign in to comment.