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
| Composition | Meaning |
|---|---|
| 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 · project | Identifies 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:
<?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
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();
}
}use App\Models\Invitation;
use Storyfeed\Facades\Story;
Story::for(Invitation::class)->verb('accept')
->headline(':actor accepted :object for :target');Checking for Missing Roles
user · moved · document · folder BThis 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
user · archived · document · — coherent — nothing was aimed atuse 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.