rumours

package
v0.0.0-...-95891f2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rumours is the Rumours page block: what the party has heard about a page, who said it, how sure they were, what the Director knows is true and what the party has decided to believe.

The two judgements are kept apart on purpose. The Director's truth is theirs alone and never leaves the service for anyone else; the party's belief is set by a Scribe or the Director and shown to everyone once marked. A Scribe can add rumours and mark what the party thinks but can never change the truth. The service decides what each viewer is told and who may write; the handler, the block and the script add no rule of their own.

Index

Constants

View Source
const (
	TruthOpen  = "open"
	TruthTrue  = "true"
	TruthFalse = "false"
)

What the Director knows about a rumour. Only the Director ever reads or sets it.

View Source
const (
	BeliefNone   = ""
	BeliefTrue   = "true"
	BeliefFalse  = "false"
	BeliefUnsure = "unsure"
)

What the party has decided to believe. BeliefNone is a rumour nobody has marked yet.

View Source
const (
	SureMin     = 1
	SureMax     = 3
	SureDefault = 2
)

How sure the person who said it was, as shown by the three dots.

View Source
const (
	// QuoteMax is the longest rumour, in characters.
	QuoteMax = 280
	// SourceMax is the longest "who said it", in characters.
	SourceMax = 80
	// MaxRumours is how many rumours one page keeps. It is also the most a
	// read sends, so a page can never hold a rumour its block cannot show;
	// adding past it asks for some to be removed first.
	MaxRumours = 200
)

Bounds that keep a page's rumours a small thing. They are why the block can read a whole page in one query instead of paging it.

View Source
const BlockType = "rumours"

BlockType is the block's type in the page block registry.

View Source
const PluginSlug = "rumours"

PluginSlug names the Rumours block in the plugin migration bookkeeping and the health registry. It has a slug and a migrations directory of its own so a failed migration here leaves only the Rumours block out, and never marks another plugin degraded or runs another plugin's files.

Variables

View Source
var MigrationsFS embed.FS

MigrationsFS contains the embedded SQL migration files so the table is created from the compiled binary regardless of the working directory (same pattern as the other plugins).

View Source
var StaticAssetsFS embed.FS

StaticAssetsFS holds the block's script, served at /static/plugins/rumours/ and loaded on sight the first time a page shows the block.

Functions

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)

RegisterRoutes mounts the block's routes. Reads need a campaign member and the service narrows them further; writes are the Director's and Scribes'.

func SureWord

func SureWord(n int) string

SureWord is the words for a sureness; anything out of range reads as the middle step rather than failing a page render.

Types

type AddInput

type AddInput struct {
	CampaignID string
	EntityID   string
	Quote      string
	Who        string
	Sure       int
	Viewer     Viewer
}

AddInput is a new rumour.

type Handler

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

Handler serves the Rumours block's JSON. It binds, checks the page is one the caller may open, and calls the service; every rule about who may see or write what is the service's.

func NewHandler

func NewHandler(svc Service, pages Pages) *Handler

NewHandler creates the Rumours handler.

func (*Handler) Add

func (h *Handler) Add(c *echo.Context) error

Add writes a rumour and returns it.

func (*Handler) List

func (h *Handler) List(c *echo.Context) error

List returns the page's rumours as the caller may see them.

func (*Handler) Remove

func (h *Handler) Remove(c *echo.Context) error

Remove deletes a rumour.

func (*Handler) SetBelief

func (h *Handler) SetBelief(c *echo.Context) error

SetBelief records what the party thinks and returns the rumour.

func (*Handler) SetTruth

func (h *Handler) SetTruth(c *echo.Context) error

SetTruth records what is true and returns the rumour.

func (*Handler) Update

func (h *Handler) Update(c *echo.Context) error

Update edits a rumour's words and returns it.

type Pages

type Pages interface {
	Open(ctx context.Context, campaignID, entityID string, role int, userID string) error
}

Pages answers whether the caller may open a page. It is owned here and implemented in internal/app over the entities service, so this plugin never imports another plugin. A page that is missing, in another campaign or hidden from the caller is the same answer: not found.

type Repository

type Repository interface {
	// List returns the page's rumours, newest first, at most limit, and how
	// many the page holds in all.
	List(ctx context.Context, campaignID, entityID string, withTruth bool, limit int) ([]Rumour, int, error)
	// Get returns one rumour of that page, or nil when it is not there.
	Get(ctx context.Context, campaignID, entityID, id string, withTruth bool) (*Rumour, error)
	// Insert adds a rumour unless the page already holds max; it also checks
	// the page is in the campaign, under a lock that serialises two adds.
	Insert(ctx context.Context, r Rumour, max int) error
	// UpdateText changes what was said, who said it and how sure they were.
	UpdateText(ctx context.Context, campaignID, entityID, id, quote, source string, sure int) (bool, error)
	// SetTruth records the Director's verdict.
	SetTruth(ctx context.Context, campaignID, entityID, id, truth string) (bool, error)
	// SetBelief records what the party thinks and who marked it.
	SetBelief(ctx context.Context, campaignID, entityID, id, belief, byUser string, byDM bool) (bool, error)
	// Delete removes a rumour of that page; false when it was not there.
	Delete(ctx context.Context, campaignID, entityID, id string) (bool, error)
}

Repository owns the page_rumours table. It decides nothing about who may do what, except one thing the SQL itself enforces: a read made without withTruth never selects the truth column, so a read for a Scribe or a player cannot carry it even if a caller forgets to drop it afterwards.

func NewRepository

func NewRepository(db *sql.DB) Repository

NewRepository creates the MariaDB repository for rumours.

type Rumour

type Rumour struct {
	ID         string
	CampaignID string
	EntityID   string
	Quote      string
	Source     string
	Sure       int
	Truth      string
	Belief     string
	BeliefBy   string
	BeliefName string
	BeliefByDM bool
	ByDM       bool
	CreatedBy  string
	AuthorName string
	CreatedAt  time.Time
}

Rumour is one stored rumour with the names of the people who touched it. Truth is empty when the read was made for someone who may not see it.

type RumourView

type RumourView struct {
	ID    string `json:"id"`
	Quote string `json:"quote"`
	Who   string `json:"who"`
	Sure  int    `json:"sure"`
	// When is the day it was heard, already worded for the page.
	When string `json:"when"`
	// AddedBy is "you", a person's name, or empty for a rumour the Director
	// wrote (the Director's own rumours carry no byline).
	AddedBy string `json:"addedBy,omitempty"`
	// Belief is what the party thinks; empty until someone marks it.
	Belief   string `json:"belief"`
	BeliefBy string `json:"beliefBy,omitempty"`
	// Truth is only ever set in a view built for the Director.
	Truth *string `json:"truth,omitempty"`
	// CanEdit is whether this viewer may edit or remove this rumour.
	CanEdit bool `json:"canEdit"`
}

RumourView is a rumour as one viewer may see it. Truth is a pointer so that for everyone but the Director the key is absent from the JSON altogether, not present and empty.

type Service

type Service interface {
	// View is the whole block for one viewer.
	View(ctx context.Context, campaignID, entityID string, v Viewer) (*View, error)
	// Add writes a rumour. Director and Scribes.
	Add(ctx context.Context, in AddInput) (*RumourView, error)
	// Update edits a rumour's words. Director, or the Scribe who wrote it.
	Update(ctx context.Context, campaignID, entityID, rumourID string, in UpdateRumourInput, v Viewer) (*RumourView, error)
	// SetTruth records what is true. Director only.
	SetTruth(ctx context.Context, campaignID, entityID, rumourID, truth string, v Viewer) (*RumourView, error)
	// SetBelief records what the party thinks. Director and Scribes.
	SetBelief(ctx context.Context, campaignID, entityID, rumourID, belief string, v Viewer) (*RumourView, error)
	// Remove deletes a rumour. Director, or the Scribe who wrote it.
	Remove(ctx context.Context, campaignID, entityID, rumourID string, v Viewer) error
}

Service is the Rumours block's business logic. Every method takes the viewer and decides here what that viewer may be told and may do; handlers, the block and the script add no rule of their own.

The rules, in one place:

  • Everyone who can open the page reads its rumours and what the party thinks. Only the Director is ever sent what is true.
  • The Director and Scribes add rumours and set what the party thinks.
  • Only the Director changes what is true.
  • The Director edits or removes any rumour; a Scribe, only their own.

func NewService

func NewService(repo Repository) Service

NewService creates the Rumours service.

type UpdateRumourInput

type UpdateRumourInput struct {
	Quote patch.Field[string]
	Who   patch.Field[string]
	Sure  patch.Field[int]
}

UpdateRumourInput edits what was said, who said it or how sure they were. Each field is a patch.Field so a body naming one of them leaves the others as they are. All three are required columns, so an explicit null preserves. Which rumour, on which page, and who is asking travel beside it.

type View

type View struct {
	// Hidden means the block draws nothing for this viewer: a player on a page
	// with no rumours has nothing to read and no way to add one.
	Hidden bool `json:"-"`
	// IsDM is true for the Director, the only viewer sent the truth.
	IsDM bool `json:"isDM"`
	// CanAdd and CanMark are what this viewer may do; the server re-checks
	// both on every write.
	CanAdd  bool `json:"canAdd"`
	CanMark bool `json:"canMark"`
	// Total is how many rumours the page holds. When it exceeds the length of
	// Rumours the read was cut off, and the block says so.
	Total   int          `json:"total"`
	Rumours []RumourView `json:"rumours"`
}

View is everything the block shows one viewer.

func (*View) Cut

func (v *View) Cut() bool

Cut reports whether the read sent fewer rumours than the page holds.

type Viewer

type Viewer struct {
	UserID string
	Role   int
}

Viewer is who is asking. Role is the campaign's visibility role (CampaignContext.VisibilityRole), so a granted co-Director counts as the Director; the service never compares it against anything else.

func ViewerOf

func ViewerOf(cc *campaigns.CampaignContext, userID string) Viewer

ViewerOf is who is asking, from the campaign context. VisibilityRole is used as on the page itself, so a granted co-Director sees and may do what the owner does.

func (Viewer) CanAdd

func (v Viewer) CanAdd() bool

CanAdd says who may write a rumour: the Director and Scribes. Players read.

func (Viewer) CanMark

func (v Viewer) CanMark() bool

CanMark says who may set what the party thinks.

func (Viewer) IsDM

func (v Viewer) IsDM() bool

IsDM is true for the Director and a granted co-Director.

func (Viewer) IsScribe

func (v Viewer) IsScribe() bool

IsScribe is true for a Scribe who is not also the Director.

Jump to

Keyboard shortcuts

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