Discuss: root contract wiring
The pkg:discuss blocks of app.contract: routes, drafts, targets, the two resources, the discussPosted mutation, actions and the view switch.

Resources and mutations may only be declared in the root component, so the data wiring for comments lives in the // >>> pkg:discuss blocks of app.contract (Package conventions and ownership blocks). The components that consume it are in Discuss: screens and components.

Routes and declarations

Routes (app.contract L34-L38): thread "/c/:uid/:comment", comments "/comments/:ref", compose "/compose/:ref".

Declarations (L107-L120):

Name

Meaning

discussEpoch

Bumped by discussRefresh.

discussDraft, discussComposeDraft, discussReplyTo

The reply draft, the compose-sheet draft, the comment being answered.

discussTargets

Refs of every loaded document on the reader's server, plus the ref of a visible comments or compose route.

discussThreadIds

uid/comment of a visible thread route.

discussSignedIn

currentAccount is set and its key is in meIds (Me).

discussAccountName

The profile name, else the key name, else the short id.

discussions

resource … = discussList(readContextServer, discussTargets, discussEpoch + readEpoch) as shape Discussion[] else empty()

discussThreads

resource … = discussThreadList(readContextServer, discussThreadIds, discussEpoch + readEpoch) as shape DiscussThread[] else empty()

discussPosted

mutation … as shape DiscussReply refreshes discussions, discussThreads then discussAfterPost

discussPostError

The mutation's error; the view hides it while a post is pending.

Actions (L328-L365):

Action

Effect

discussRefresh

discussEpoch + 1

discussRetry

refresh discussThreads

discussEdit(v), discussEditCompose(v)

Update a draft.

discussSetReply(id)

Set discussReplyTo and focus("reply-composer").

discussPost(target, parent)

Picks the compose draft when parent is empty, else the reply draft. Sends only when the text is not blank, the person is signed in and no post is pending: discussPost(readContextServer, currentAccount, target, parent, text, time.epochAtZero + performanceNow()).

discussAfterPost

On ok: from the compose sheet, clear its draft, go back and go to r.value (the new thread); otherwise clear the reply draft and target. Then haptic("success"). A failed post keeps the draft.

discussCancelCompose

Back.

discussOpenCreate

Resets the create form, asks for new recovery words and goes to /me/create (Me: screens and components).

The provide block supplies discussions, discussNow and discussUtc for injection, and the view switch renders the three screens.

Things to keep in mind

    Both resources are asked on readContextServer, and the post goes there too, so a comment on a typed-site document is written to that site (Read: root contract wiring).

    discussTargets includes only documents whose server equals readContextServer, so comments are not requested for covered documents from another site.

    The post time is time.epochAtZero + performanceNow(), taken in the action. It becomes the Comment blob's timestamp (Discuss: loading and posting).

    refreshes discussions, discussThreads re-asks both resources after a post; the module has already dropped the document's cached listing.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments