forum

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 24 Imported by: 0

README

Forum

Forum sections and topics for Kosatka: the /forum pages - sections from a vocabulary, topics as content of their own type with threaded replies, the active and unanswered topics - and the forum settings.

The Forum module (forum) gives a site a classic discussion forum: categories with sections, topics in the sections and threaded replies under each topic. The forum's structure is a taxonomy vocabulary that you choose, its topics are content of the module's own Forum type, and the replies are ordinary comments.

Install

A site with modules from outside the engine builds its own binary (kosatka.Main); app module add adds this one to it:

app module add github.com/kosatka-cms/kosatka-module-forum
go build -o app .

Then enable Forum on the site's Modules page: it installs its tables and starter rows. See Using modules.

A new site built with it gets it with app install -modules forum,… (or -modules all).

A site installed with the forum and -demo has it set up: a Forum vocabulary with two categories and their sections, a few topics with replies by the demo users, and a Forum link in the main menu.

What it adds

What Where
The forum's front page: every category with its sections /forum
A category's page: the same table for one category the category term's address
A section's page: its topics the section term's address, for example /forum/questions
Active topics: topics of all sections by their latest post /forum/active
Unanswered topics: topics without replies, newest first /forum/unanswered
A topic's page with its replies /forum/<topic-slug>
Create new topic /forum/new-topic/<section address>
Edit topic, Delete topic /forum/topic/<id>/edit, /forum/topic/<id>/delete
The settings page Configuration → Modules → Forum (/admin/config/forum)
The Forum content type (forum topics) its permissions are on People → Permissions

The section pages and the topics are in the sitemap. robots.txt keeps search engines off the create, edit and delete pages, and the Active topics and Unanswered topics lists are marked not to be indexed.

The module has no blocks of its own. The topic page shows the blocks of the Inside content (content page) region (content_inline) between the topic and its replies, as content pages do (see Blocks).

How the forum is built

The forum reads its structure from one vocabulary (see Taxonomy):

  • a root term is a category. It only groups sections: its page lists them, and it holds no topics;
  • a child term of a category is a section: the place where topics are posted;
  • deeper terms are not shown on the forum's pages.

Categories and sections come in the order of their weight, then name. A term's name and description are shown in the tables; the term's address is the address of its forum page.

Until a vocabulary is chosen, the forum is empty.

Set up the forum

  1. Open Taxonomy (/admin/config/taxonomy) and create a vocabulary for the forum only, for example "Forum", with Term path prefix forum. Leave Term pages off: the forum shows these terms itself.
  2. Add the categories as top-level terms, for example "General" and "Off topic".
  3. Add the sections as their children, for example "Questions" and "Announcements" under "General". With an empty Path, a term gets the vocabulary prefix plus its name (forum/questions), which is where its forum page will be.
  4. Open Configuration → Modules → Forum (/admin/config/forum), choose the vocabulary in Forum vocabulary and click Save.
  5. Check who may post: installing the module gives the Signed-in user role Create in the Forum group of People → Permissions, so every signed-in user can start topics. Untick it there, or give it to other roles, to choose who may.
  6. Add a link to /forum to a menu (see Menus).

The prefix doesn't have to be forum: a section whose address starts with the vocabulary's prefix (say boards/general/questions) opens at that address too. Keep the terms' addresses under the prefix, or the links on the forum pages won't open.

To change sections later, edit the terms: renaming, reordering or adding a section shows on the forum at once. To switch the forum off without disabling the module, choose - not selected (forum disabled) - and save.

Post a topic

A user with the Create permission of the Forum type sees Create new topic above and below a section's topics; a guest sees Log in to post new forum topics. instead.

The form has:

Field
Forum section the section; the current one is selected. The categories are listed as headings and can't be chosen. Required
Title required, up to 255 characters
Body the text, in a visual editor with headings, lists, links and images from the user's files

Create topic publishes the topic at once and opens it. Its address is /forum/ plus the title, transliterated (-1, -2… is added when it's taken). Editing the title later doesn't change the address.

Replies

The replies are the topic's comments. A signed-in user presses Reply (under the topic or under a reply, to answer that reply); a guest sees Log in or register to post comments. Replies come 50 per page; Last post jumps to the newest one.

The comment rules are the site's usual ones: a reply goes through the site's comment checks (see Comments), so it is published at once or waits for approval - by default, a new author's first one waits. Authors edit their own replies, and roles with Administer comments edit and delete any. Forum replies are kept out of the site's Recent comments block.

When the Private messages module is on, other signed-in users see a link to send the topic's author a message next to the author's name.

Moderate topics

On a topic's page, a user who may do so sees these buttons:

Button Who sees it
Pin to top / Unpin roles with Edit any of the Forum type. A pinned topic leads its section's list, marked Sticky:
Edit roles with Edit any, and the author with Edit own while the topic is published
Delete roles with Delete any

Edit opens the same form as creating. Changing Forum section moves the topic to another section.

Delete asks for confirmation and removes the topic with all its replies for good, along with the files nothing else uses.

Forum topics also appear in the admin's content list (Content), where they can be published, unpublished or deleted in bulk like other content. An unpublished topic disappears from the forum's lists and counts.

With the Action log module on, its Forum group records a topic moved to another section (from which to which), pinned and unpinned.

Topic lists

A section's page lists 25 topics per page: pinned ones first, then by the latest post. Click a column heading to sort by it, and again to reverse:

Column
Topic / Topic starter the title, the author and the date
Replies the number of replies; a topic with more than 20 is shown as a Hot topic
Views how many times the topic was viewed
Last post who replied last and when

Active topics and Unanswered topics use the same table, across all sections, with each topic's section under its title.

Statistics

Below the categories, the front page shows Statistics: the number of published topics, of replies (Posts) and of the site's users, and Newest member: with the five newest active accounts (not blocked, not awaiting approval). Each section row has its own Topics and Posts counts and its Last post: the topic with the latest activity.

Disable and uninstall

While the module is disabled, the /forum pages answer 404 and the topics don't open; the topics, replies and settings stay.

Uninstalling (see Using modules) first deletes the forum topics with their replies, then the module's tables and settings. The forum's vocabulary lives in the core's taxonomy: uninstalling deletes it with its terms too, unless something else uses it (a taxonomy field of a content type, a search setting, or content tagged with its terms). In that case it stays, and you can delete it yourself on the Taxonomy page.

Development

Its strings are translated in translations/<lang>.json.

The module is built on the engine's module SDK only (github.com/kosatka-cms/kosatka/modulekit, pkg/*).

go test ./...
# with MySQL and PostgreSQL (the engine's docker-compose.test.yml):
KOSATKA_TEST_MYSQL_DSN="root:test@tcp(127.0.0.1:33306)/?parseTime=true" \
KOSATKA_TEST_POSTGRES_DSN="postgres://postgres:test@127.0.0.1:35432/postgres?sslmode=disable" \
  go test -tags dbintegration ./...

A schema change: edit ent/schema, go generate ./ent, then go run ./cmd/migrations -name <name> (both test databases running) - it writes the next migration for MySQL and PostgreSQL into ent/migrations; go run ./cmd/migrations -check fails while the files are behind the schema. See Write a module.

License

MIT

Documentation

Index

Constants

View Source
const (
	ActionGroup      = "forum"
	ActionTopicMove  = "forum.topic_move"
	ActionTopicPin   = "forum.topic_pin"
	ActionTopicUnpin = "forum.topic_unpin"
)

The forum's actions in the action log: their group and types. A topic created or deleted is the core's "Content" group (modulekit.RecordNodeCreated, the core's deletion).

Variables

View Source
var Assets embed.FS

Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

Functions

func CommentsChanged

func CommentsChanged(repo *EntForumRepository) func(ctx context.Context, nodeID int) error

CommentsChanged - the forum's CommentsService.OnNodeCommentsChanged hook: a topic's reply count and last reply time follow its comments (the topic lists sort and filter by them). Nothing while the module is off (its tables may not exist).

func ForumUninstallStep

func ForumUninstallStep(settings ForumSettingsRepository, vocabularies interface {
	DeleteVocabularyIfUnused(ctx context.Context, vid int) (bool, error)
}, logger *slog.Logger) func(ctx context.Context) error

ForumUninstallStep - the forum module's own uninstall step: its vocabulary of sections (forum settings) is deleted with its terms unless something else uses it (a taxonomy field, a search badge, a field value). Runs after the forum's content is gone, before its settings table is dropped.

func RegisterAdminRoutes

func RegisterAdminRoutes(r modulekit.Mux, fc *ForumController, admin func(http.Handler) http.Handler)

RegisterAdminRoutes registers the forum settings page behind admin (sign-in and the admin permission).

func RegisterForumRoutes

func RegisterForumRoutes(r modulekit.Mux, store *sessions.CookieStore, fc *ForumController)

RegisterForumRoutes registers the forum's pages: the index, the active and unanswered topics, a section, and a topic's new, edit, delete and pin actions (a new topic - signed in only).

func SitemapPaths

func SitemapPaths(svc ForumService) func(ctx context.Context) ([]string, error)

SitemapPaths - the forum sections for the sitemap (AddSitemapPaths), at their terms' addresses, as the forum links to them.

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the module's services, controller, sitemap and comments hooks, its actions in the action log, routes, section pages (the 404-path fallback) and uninstall step (modulekit).

Types

type DefaultForumService

type DefaultForumService struct {
	// contains filtered or unexported fields
}

DefaultForumService implements ForumService.

func (*DefaultForumService) CountTopics

func (s *DefaultForumService) CountTopics(ctx context.Context, sectionID int) (int, error)

CountTopics counts topics in a section.

func (*DefaultForumService) CreateTopic

func (s *DefaultForumService) CreateTopic(ctx context.Context, sectionID int, title, body string, authorID int) (*ForumTopicDetail, error)

CreateTopic creates a new forum topic; the action log gets "Content created".

func (*DefaultForumService) GetCategory

func (s *DefaultForumService) GetCategory(ctx context.Context, id int) (*ForumCategory, error)

GetCategory - see ForumService.GetCategory.

func (*DefaultForumService) GetForumIndex

func (s *DefaultForumService) GetForumIndex(ctx context.Context) (*ForumIndex, error)

GetForumIndex retrieves the main forum page data.

func (*DefaultForumService) GetForumTermsForSelect

func (s *DefaultForumService) GetForumTermsForSelect(ctx context.Context) ([]ForumTermOption, error)

GetForumTermsForSelect returns forum terms for the section dropdown.

func (*DefaultForumService) GetSectionBySlug

func (s *DefaultForumService) GetSectionBySlug(ctx context.Context, slug string) (*ForumSectionPage, int, error)

GetSectionBySlug - see ForumService.GetSectionBySlug.

func (*DefaultForumService) GetStatistics

func (s *DefaultForumService) GetStatistics(ctx context.Context) (*ForumStatistics, error)

GetStatistics retrieves overall forum statistics.

func (*DefaultForumService) GetTopic

func (s *DefaultForumService) GetTopic(ctx context.Context, slug string) (*ForumTopicDetail, error)

GetTopic retrieves a forum topic by slug.

func (*DefaultForumService) GetTopicSectionID

func (s *DefaultForumService) GetTopicSectionID(ctx context.Context, nodeID int) (int, error)

GetTopicSectionID returns the section (tid) for a forum topic.

func (*DefaultForumService) GetTopics

func (s *DefaultForumService) GetTopics(ctx context.Context, sectionID int, filter ForumTopicFilter) ([]ForumTopic, error)

GetTopics retrieves topics for a section with filters.

func (*DefaultForumService) ListTopics

func (s *DefaultForumService) ListTopics(ctx context.Context, filter ForumTopicFilter) ([]ForumTopic, int, error)

ListTopics - a page of topics by the filter and their total.

func (*DefaultForumService) SectionPathPrefix

func (s *DefaultForumService) SectionPathPrefix(ctx context.Context) string

SectionPathPrefix - see ForumService.SectionPathPrefix.

func (*DefaultForumService) SetTopicSticky

func (s *DefaultForumService) SetTopicSticky(ctx context.Context, topic modulekit.Node, sticky bool) error

SetTopicSticky pins the topic at the top of its section (or unpins it); the action log gets "Topic pinned" or "Topic unpinned".

func (*DefaultForumService) UpdateTopic

func (s *DefaultForumService) UpdateTopic(ctx context.Context, nodeID int, title, body string, sectionID int) error

UpdateTopic updates a forum topic; moved to another section, it is "Topic moved" in the action log, from which section to which.

type EntForumRepository

type EntForumRepository struct {
	// contains filtered or unexported fields
}

EntForumRepository handles forum data access.

func NewForumRepository

func NewForumRepository(db *sql.DB, nodes modulekit.NodesRepository, users modulekit.UserRepository, taxonomy Taxonomy) *EntForumRepository

NewForumRepository creates a new forum repository: its own tables on db (the module's own ent schema, ent/), a topic's node, author and section through the core; its lists in SQL over both. A built-in module, tested with the engine, may read the core's tables in its SQL; a module of its own repository goes through the SDK's services instead (docs/modules/sdk.md): the core's columns aren't its API.

func (*EntForumRepository) CountTopicsBySection

func (r *EntForumRepository) CountTopicsBySection(ctx context.Context, sectionID int) (int, error)

CountTopicsBySection counts the public topics of a section.

func (*EntForumRepository) CountTopicsFiltered

func (r *EntForumRepository) CountTopicsFiltered(ctx context.Context, filter ForumTopicFilter) (int, error)

CountTopicsFiltered counts the topics ListTopics pages over.

func (*EntForumRepository) CreateTopic

func (r *EntForumRepository) CreateTopic(ctx context.Context, sectionID int, title, body string, authorID int) (*ForumTopicDetail, error)

CreateTopic creates a new forum topic.

func (*EntForumRepository) GetForumCategories

func (r *EntForumRepository) GetForumCategories(ctx context.Context) ([]ForumCategory, error)

GetForumCategories retrieves all forum categories with sections and statistics.

func (*EntForumRepository) GetForumStatistics

func (r *EntForumRepository) GetForumStatistics(ctx context.Context) (*ForumStatistics, error)

GetForumStatistics retrieves overall forum statistics.

func (*EntForumRepository) GetForumTermsForSelect

func (r *EntForumRepository) GetForumTermsForSelect(ctx context.Context) ([]ForumTermOption, error)

GetForumTermsForSelect returns all forum terms (categories and sections) for the section dropdown.

func (*EntForumRepository) GetSectionBySlug

func (r *EntForumRepository) GetSectionBySlug(ctx context.Context, slug string) (*ForumSection, error)

GetSectionBySlug retrieves a forum section by slug with its parent category (for breadcrumbs).

func (*EntForumRepository) GetTopicBySlug

func (r *EntForumRepository) GetTopicBySlug(ctx context.Context, slug string) (*ForumTopicDetail, error)

GetTopicBySlug retrieves a topic by slug, or by the path of its page (a slug without the type's prefix has it added there, NodeRelPath), whatever its status: who may see it is the page's to decide (AuthService.CanViewNode on ForumTopicDetail.node).

func (*EntForumRepository) GetTopicSectionID

func (r *EntForumRepository) GetTopicSectionID(ctx context.Context, nodeID int) (int, error)

GetTopicSectionID returns the taxonomy term ID (section) of a forum topic.

func (*EntForumRepository) GetTopicsBySection

func (r *EntForumRepository) GetTopicsBySection(ctx context.Context, sectionID int, filter ForumTopicFilter) ([]ForumTopic, error)

GetTopicsBySection retrieves topics of a forum section.

func (*EntForumRepository) ListTopics

func (r *EntForumRepository) ListTopics(ctx context.Context, filter ForumTopicFilter) ([]ForumTopic, error)

ListTopics retrieves topics by the filter.

func (*EntForumRepository) RecountTopicStats

func (r *EntForumRepository) RecountTopicStats(ctx context.Context, nodeID int) error

RecountTopicStats sets the topic's comment count and last comment time from its comments (nothing for a node that isn't a topic).

func (*EntForumRepository) SectionPathPrefix

func (r *EntForumRepository) SectionPathPrefix(ctx context.Context) (string, error)

SectionPathPrefix - see ForumRepository.SectionPathPrefix.

func (*EntForumRepository) SetSticky

func (r *EntForumRepository) SetSticky(ctx context.Context, nodeID int, sticky bool) error

SetSticky - see ForumRepository.SetSticky.

func (*EntForumRepository) TopicExistsBySlug

func (r *EntForumRepository) TopicExistsBySlug(ctx context.Context, slug string) (bool, error)

TopicExistsBySlug reports whether a forum topic with the given slug exists.

func (*EntForumRepository) UpdateTopic

func (r *EntForumRepository) UpdateTopic(ctx context.Context, nodeID int, title, body string, sectionID int) error

UpdateTopic updates a forum topic's title, body and section (in one transaction).

type EntForumSettingsRepository

type EntForumSettingsRepository struct {
	// contains filtered or unexported fields
}

EntForumSettingsRepository - forum_settings, on the module's own ent schema (ent/).

func NewForumSettingsRepository

func NewForumSettingsRepository(db *sql.DB) *EntForumSettingsRepository

NewForumSettingsRepository - the forum settings' repository on db.

func (*EntForumSettingsRepository) Get

Get - the forum's settings, from its single row.

func (*EntForumSettingsRepository) Update

Update saves s to the single settings row (VocabularyID 0 - none).

type ForumCategory

type ForumCategory struct {
	ID          int
	Name        string
	Description string
	Slug        string
	Weight      int
	Sections    []ForumSection
}

ForumCategory represents a top-level forum category (container)

func ToForumCategoriesEntity

func ToForumCategoriesEntity(rows []ForumCategoryRowDTO) []ForumCategory

ToForumCategoriesEntity converts DTO rows to entity categories.

type ForumCategoryRowDTO

type ForumCategoryRowDTO struct {
	ContainerID     int
	ContainerName   string
	ContainerDesc   string
	ContainerSlug   string
	ContainerWeight int
	SectionID       sql.NullInt64
	SectionName     sql.NullString
	SectionDesc     sql.NullString
	SectionSlug     sql.NullString
	SectionWeight   sql.NullInt64
	TopicsCount     int
	PostsCount      int
	LastActivity    sql.NullTime
	LastTopicTitle  sql.NullString
	LastTopicSlug   sql.NullString
	LastAuthor      sql.NullString
}

ForumCategoryRowDTO represents a row from GetForumCategories query.

type ForumCommentRowDTO

type ForumCommentRowDTO struct {
	ID            int
	ParentID      sql.NullInt64
	CreatedAt     time.Time
	Content       string
	AuthorID      int
	AuthorName    string
	AuthorCreated time.Time
}

ForumCommentRowDTO represents a comment row from GetTopicBySlug query.

type ForumController

type ForumController struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

ForumController handles forum HTTP requests.

func NewForumController

func NewForumController(deps modulekit.BaseDeps, d ForumDeps) *ForumController

NewForumController creates a ForumController.

func (*ForumController) ActiveTopics

func (c *ForumController) ActiveTopics(w http.ResponseWriter, r *http.Request)

ActiveTopics handles GET /forum/active: every section's topics by their last post.

func (*ForumController) CreateTopicForm

func (c *ForumController) CreateTopicForm(w http.ResponseWriter, r *http.Request)

CreateTopicForm displays the form for creating a forum topic.

func (*ForumController) CreateTopicSubmit

func (c *ForumController) CreateTopicSubmit(w http.ResponseWriter, r *http.Request)

CreateTopicSubmit handles the create forum topic form submission.

func (*ForumController) DeleteTopic

func (c *ForumController) DeleteTopic(w http.ResponseWriter, r *http.Request)

DeleteTopic handles the delete forum topic form submission: the topic is deleted for good, with its replies.

func (*ForumController) DeleteTopicConfirm

func (c *ForumController) DeleteTopicConfirm(w http.ResponseWriter, r *http.Request)

DeleteTopicConfirm displays the delete confirmation page for a forum topic.

func (*ForumController) EditTopicForm

func (c *ForumController) EditTopicForm(w http.ResponseWriter, r *http.Request)

EditTopicForm displays the form for editing a forum topic.

func (*ForumController) EditTopicSubmit

func (c *ForumController) EditTopicSubmit(w http.ResponseWriter, r *http.Request)

EditTopicSubmit handles the edit forum topic form submission.

func (*ForumController) ForumSettingsPage

func (c *ForumController) ForumSettingsPage(w http.ResponseWriter, r *http.Request)

ForumSettingsPage handles GET/POST /admin/config/forum - the forum's vocabulary (ForumSettings). Same pattern as UploadSettingsPage.

func (*ForumController) Index

Index displays the main forum page with categories and sections.

func (*ForumController) Section

func (c *ForumController) Section(w http.ResponseWriter, r *http.Request)

Section displays a forum section with its topics: the section, category or topic whose slug is the URL's path.

func (*ForumController) SectionFallback

func (c *ForumController) SectionFallback(w http.ResponseWriter, r *http.Request) bool

SectionFallback serves a forum section at the forum vocabulary's own term path prefix (/<prefix>/category/section - the URLs of its terms), besides the module's /forum/… routes. Returns false for any other path.

func (*ForumController) StickTopic

func (c *ForumController) StickTopic(w http.ResponseWriter, r *http.Request)

StickTopic handles POST /forum/topic/{id}/sticky: sticky=1 pins the topic at the top of its section, anything else unpins it; back to the topic.

func (*ForumController) UnansweredTopics

func (c *ForumController) UnansweredTopics(w http.ResponseWriter, r *http.Request)

UnansweredTopics handles GET /forum/unanswered: topics without replies, newest first.

type ForumDeps

type ForumDeps struct {
	ForumService    ForumService
	TaxonomyService modulekit.TaxonomyService
	NodeDeleter     modulekit.NodeDeleter
	Settings        ForumSettingsRepository
}

ForumDeps - what NewForumController needs besides the BaseDeps.

type ForumIndex

type ForumIndex struct {
	Categories []ForumCategory
	Statistics *ForumStatistics
}

ForumIndex represents the main forum page data

type ForumLastComment

type ForumLastComment struct {
	ID        int
	Author    string
	Timestamp time.Time
}

ForumLastComment represents the last comment info

type ForumLastTopic

type ForumLastTopic struct {
	ID        int
	Title     string
	Slug      string
	Author    string
	Timestamp time.Time
}

ForumLastTopic represents the last topic info in a section

func (ForumLastTopic) Path

func (t ForumLastTopic) Path() string

Path - the topic's page.

type ForumRepository

type ForumRepository interface {
	GetForumCategories(ctx context.Context) ([]ForumCategory, error)
	GetSectionBySlug(ctx context.Context, slug string) (*ForumSection, error)
	GetTopicsBySection(ctx context.Context, sectionID int, filter ForumTopicFilter) ([]ForumTopic, error)
	CountTopicsBySection(ctx context.Context, sectionID int) (int, error)
	// ListTopics - topics by the filter (one section or all, optionally
	// only unanswered), each with its section when listing all.
	ListTopics(ctx context.Context, filter ForumTopicFilter) ([]ForumTopic, error)
	// CountTopicsFiltered - how many topics ListTopics pages over.
	CountTopicsFiltered(ctx context.Context, filter ForumTopicFilter) (int, error)
	GetTopicBySlug(ctx context.Context, slug string) (*ForumTopicDetail, error)
	GetForumStatistics(ctx context.Context) (*ForumStatistics, error)
	GetForumTermsForSelect(ctx context.Context) ([]ForumTermOption, error)
	GetTopicSectionID(ctx context.Context, nodeID int) (int, error)
	CreateTopic(ctx context.Context, sectionID int, title, body string, authorID int) (*ForumTopicDetail, error)
	UpdateTopic(ctx context.Context, nodeID int, title, body string, sectionID int) error
	// SetSticky pins the topic at the top of its section's list (or not).
	SetSticky(ctx context.Context, nodeID int, sticky bool) error
	TopicExistsBySlug(ctx context.Context, slug string) (bool, error)
	// SectionPathPrefix - the forum vocabulary's term path prefix (its
	// sections' URLs start with it, e.g. "forums"), "" - none set.
	SectionPathPrefix(ctx context.Context) (string, error)
}

ForumRepository defines methods for forum data access

type ForumSection

type ForumSection struct {
	ID          int
	ParentID    int
	Name        string
	Description string
	Slug        string
	Weight      int
	TopicsCount int
	PostsCount  int
	LastTopic   *ForumLastTopic
	// Parent category for breadcrumbs
	ParentName string
	ParentSlug string
}

ForumSection represents a forum section within a category

func ToForumSectionEntity

func ToForumSectionEntity(row ForumCategoryRowDTO) ForumSection

ToForumSectionEntity converts a DTO row to a ForumSection entity.

type ForumSectionPage

type ForumSectionPage struct {
	Section    *ForumSection
	Topics     []ForumTopic
	TotalCount int
}

ForumSectionPage represents a forum section page data

type ForumService

type ForumService interface {
	GetForumIndex(ctx context.Context) (*ForumIndex, error)
	// SectionPathPrefix - the forum vocabulary's term path prefix: the
	// URL prefix of its sections ("" - none).
	SectionPathPrefix(ctx context.Context) string
	// GetSectionBySlug - the section or category whose slug is slug;
	// ErrEntityNotFound when none.
	GetSectionBySlug(ctx context.Context, slug string) (*ForumSectionPage, int, error)
	// GetCategory - a category (root term) with its sections and stats.
	GetCategory(ctx context.Context, id int) (*ForumCategory, error)
	GetTopics(ctx context.Context, sectionID int, filter ForumTopicFilter) ([]ForumTopic, error)
	CountTopics(ctx context.Context, sectionID int) (int, error)
	// ListTopics - a page of topics by the filter and how many there are
	// in all (the active and unanswered lists).
	ListTopics(ctx context.Context, filter ForumTopicFilter) ([]ForumTopic, int, error)
	GetTopic(ctx context.Context, slug string) (*ForumTopicDetail, error)
	GetStatistics(ctx context.Context) (*ForumStatistics, error)
	GetForumTermsForSelect(ctx context.Context) ([]ForumTermOption, error)
	GetTopicSectionID(ctx context.Context, nodeID int) (int, error)
	CreateTopic(ctx context.Context, sectionID int, title, body string, authorID int) (*ForumTopicDetail, error)
	UpdateTopic(ctx context.Context, nodeID int, title, body string, sectionID int) error
	// SetTopicSticky pins the topic at the top of its section (or not).
	SetTopicSticky(ctx context.Context, topic modulekit.Node, sticky bool) error
}

ForumService defines the forum business logic.

func NewForumService

func NewForumService(r ForumRepository, baseLogger *slog.Logger) ForumService

NewForumService creates a new forum service.

type ForumSettings

type ForumSettings struct {
	VocabularyID int
}

ForumSettings - the forum module's settings (single DB row). The vocabulary's root terms are the forum's categories, their children its sections; 0 - none chosen, the forum is empty.

type ForumSettingsRepository

type ForumSettingsRepository interface {
	Get(ctx context.Context) (*ForumSettings, error)
	Update(ctx context.Context, s *ForumSettings) error
}

ForumSettingsRepository persists the single forum settings row, same shape as UploadSettingsRepository.

type ForumStatistics

type ForumStatistics struct {
	TotalTopics      int
	TotalPosts       int
	TotalUsers       int
	LatestUsers      []string
	ActiveUsersCount int
}

ForumStatistics represents overall forum statistics

func ToForumStatisticsEntity

func ToForumStatisticsEntity(dto ForumStatisticsDTO, latestUsers []string) ForumStatistics

ToForumStatisticsEntity converts DTO to ForumStatistics entity.

type ForumStatisticsDTO

type ForumStatisticsDTO struct {
	TotalTopics int
	TotalPosts  sql.NullInt64
	TotalUsers  int
}

ForumStatisticsDTO represents statistics from GetForumStatistics query.

type ForumTermOption

type ForumTermOption struct {
	ID          int
	Name        string
	ParentID    int
	DisplayName string // With "- " prefix for sections
}

ForumTermOption represents a forum term for the section select dropdown

type ForumTopic

type ForumTopic struct {
	ID           int
	Title        string
	Slug         string
	Author       *modulekit.User
	CreatedAt    time.Time
	Sticky       bool
	CommentCount int
	ViewsCount   int
	LastComment  *ForumLastComment
	// Section - the topic's section, in lists across sections (nil in a
	// section's own list).
	Section *ForumTopicSection
	IsHot   bool
}

ForumTopic represents a forum topic in a list

func ToForumTopicEntity

func ToForumTopicEntity(row ForumTopicRowDTO) ForumTopic

ToForumTopicEntity converts a DTO row to a ForumTopic entity.

func ToForumTopicsEntity

func ToForumTopicsEntity(rows []ForumTopicRowDTO) []ForumTopic

ToForumTopicsEntity converts DTO rows to entity topics.

func (ForumTopic) Path

func (t ForumTopic) Path() string

Path - the topic's page.

type ForumTopicDetail

type ForumTopicDetail struct {
	ID            int
	Title         string
	Slug          string
	Content       string
	Author        *modulekit.User
	CreatedAt     time.Time
	UpdatedAt     time.Time
	Sticky        bool
	ViewsCount    int
	CommentCount  int
	LastCommentAt time.Time
	Comments      []modulekit.Comment
	// Section for breadcrumbs (includes parent category)
	Section *ForumSection
	// contains filtered or unexported fields
}

ForumTopicDetail represents detailed forum topic info

func ToForumTopicDetail

func ToForumTopicDetail(n modulekit.Node, author *modulekit.User, stats *generated.ForumStats, body string) ForumTopicDetail

ToForumTopicDetail - a topic from its node (the core's), its author (nil - the account is gone), its stats row (nil - none yet) and body.

func (ForumTopicDetail) Path

func (t ForumTopicDetail) Path() string

Path - the topic's page.

type ForumTopicDetailDTO

type ForumTopicDetailDTO struct {
	ID            int
	Title         string
	Slug          string
	CreatedAt     time.Time
	UpdatedAt     time.Time
	AuthorID      int
	AuthorName    string
	AuthorCreated time.Time
	Sticky        bool
	CommentCount  int
	LastCommentAt time.Time
	ViewsCount    int
	Content       string
}

ForumTopicDetailDTO represents a topic from GetTopicBySlug query.

type ForumTopicFilter

type ForumTopicFilter struct {
	// SectionID - the section's topics (0 - every section's).
	SectionID int
	// Unanswered - only topics without replies.
	Unanswered bool
	Offset     int
	Limit      int
	OrderBy    string
	OrderDir   string
	Sticky     *bool
}

ForumTopicFilter represents filter options for topics

type ForumTopicRowDTO

type ForumTopicRowDTO struct {
	ID                int
	Title             string
	Slug              string
	CreatedAt         time.Time
	AuthorID          int
	AuthorName        string
	Sticky            bool
	CommentCount      int
	LastCommentAt     time.Time
	ViewsCount        int
	LastCommentAuthor sql.NullString
	SectionName       string
	SectionSlug       string
}

ForumTopicRowDTO represents a row from GetTopicsBySection query.

type ForumTopicSection

type ForumTopicSection struct {
	Name string
	Slug string
}

ForumTopicSection - a section as a topic list names it.

type Taxonomy

type Taxonomy interface {
	VocabularyByID(ctx context.Context, id int) (*modulekit.TaxonomyVocabulary, error)
	TermByID(ctx context.Context, id int) (*modulekit.TaxonomyTerm, error)
	TermBySlug(ctx context.Context, slug string) (*modulekit.TaxonomyTerm, error)
	TermsByVocabularyID(ctx context.Context, vocabularyID int) (modulekit.TaxonomyTerms, error)
	NodeTermsByID(ctx context.Context, nodeID int) (modulekit.TaxonomyTerms, error)
	UpdateNodeTerms(ctx context.Context, nodeID int, termIDs []int) error
}

Taxonomy - the core's vocabularies and terms the forum's sections are (Deps.Taxonomy).

Directories

Path Synopsis
cmd
migrations command
Command migrations writes the module's next migration (kosatka.GenerateMigrations), run from the module's root with the two test databases running:
Command migrations writes the module's next migration (kosatka.GenerateMigrations), run from the module's root with the two test databases running:
ent
Package ent - the forum module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, cmd/migrations writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the forum module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, cmd/migrations writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the forum module's own ent schema: its tables, apart from the core's.
Package schema - the forum module's own ent schema: its tables, apart from the core's.
Package manifest declares the forum module (its registry entry).
Package manifest declares the forum module (its registry entry).
Package translations holds the forum module's interface catalogs (<lang>.json, see pkg/i18n): the strings only the module's code uses.
Package translations holds the forum module's interface catalogs (<lang>.json, see pkg/i18n): the strings only the module's code uses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL