Pre-1.0. Not intended for public use yet. The API is subject to undocumented change, and these pages may already be wrong about it.

Skip to content

Composing a Coherent Activity ​

Introduction ​

A developer adds a new kind of activity, for example a clause rewritten in an agreement. They pick a verb, an object and a headline, and the feed shows it. Weeks later, the headline names the wrong thing, a filter by agreement misses it, or a token prints empty. Checking each field before the first publish catches these while they are cheap to fix.

Before recording a new kind of activity, list its fields and check that they describe what happened. The headline states the minimal fact, no less and no more; evidence and detail belong in the body.

Naming the Object ​

Use the object's plain name as its label. When a user accepts an invitation to a project, the invitation's label names the invitation and the project's label names the project; the headline template supplies for :target. A qualifier such as as a reviewer belongs in the body.

Choosing the Object and Target ​

CompositionMeaning
Inviter · joined · invitee · —The inviter sent the invitation earlier but did not act in this event.
Invitee · joined · invitee · —The invitee appears as both actor and object, without identifying what they joined.
Invitee · accepted · invitation · projectIdentifies who accepted, what they accepted, and which project it was for.

Each field should identify someone or something involved in the event. The same entity may fill more than one role: someone editing their own profile is both actor and object.

Record the activity where your application accepts the invitation:

app/Http/Controllers/AcceptInvitationController.php
php
<?php

namespace App\Http\Controllers;

use App\Models\Invitation;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class AcceptInvitationController
{
    public function __invoke(Request $request, Invitation $invitation): RedirectResponse
    {
        Storyfeed::activity()
            ->by($request->user())
            ->action('accept', $invitation)
            ->to($invitation->project)
            ->publish();

        return back();
    }
}
php
<?php

namespace App\Http\Controllers;

use App\Models\Invitation;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class AcceptInvitationController
{
    public function __invoke(Request $request, Invitation $invitation): RedirectResponse
    {
        Storyfeed::record(
            verb: 'accept',
            object: $invitation,
            actor: $request->user(),
            target: $invitation->project,
        );

        return back();
    }
}
routes/feed.php
php
use App\Models\Invitation;
use Storyfeed\Facades\Story;

Story::for(Invitation::class)->verb('accept')
    ->headline(':actor accepted :object for :target');

Checking for Missing Roles ​

text
user · moved · document · folder B

This records the move but omits the document's original folder. Decide whether the event needs that detail; its omission does not make the other fields incorrect.

Check the stored values, then read the rendered headline aloud. Compare $item->headline()->toString() with the sentence you intended; its verb, roles, and preposition should state that fact.

Finding Unfilled Tokens ​

text
user · archived · document · —   coherent — nothing was aimed at
routes/feed.php
php
use App\Models\Document;
use Storyfeed\Facades\Story;

Story::for(Document::class)->verb('archive')
    ->headline(':actor archived :object from :target'); // Nothing fills :target.

The fields describe the event, but the headline includes an empty target. The headline reader substitutes the empty-role placeholder where the target’s name would be.

Released under the MIT License.