-
Notifications
You must be signed in to change notification settings - Fork 13
feat: interaction activity tracking module #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielhe4rt
wants to merge
7
commits into
4.x
Choose a base branch
from
feat/interaction-activity
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c49427e
refactor(activity): restructure module into Message/Voice subdomains
danielhe4rt 644964b
feat(activity): add Tracking subdomain with Interaction model
danielhe4rt 32e815b
feat(integration-devto): add new module for DevTo OAuth and article sync
danielhe4rt e1215c1
feat(identity): add DevTo to IdentityProvider enum
danielhe4rt 89f2385
feat(gamification): add HasInteractions trait to Character model
danielhe4rt 1029afd
deps: bump and fix lock
danielhe4rt bfa2053
fix: linting
danielhe4rt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'classification' => [ | ||
| 'article' => ['tier' => 'high', 'coins_min' => 100, 'coins_max' => 300], | ||
| 'pr_merged' => ['tier' => 'high', 'coins_min' => 80, 'coins_max' => 250], | ||
| 'mentoring' => ['tier' => 'high', 'coins_min' => 50, 'coins_max' => 150], | ||
| 'squad_project' => ['tier' => 'high', 'coins_min' => 200, 'coins_max' => 500], | ||
| 'referral' => ['tier' => 'medium', 'coins_min' => 20, 'coins_max' => 30], | ||
| 'peer_review' => ['tier' => 'medium', 'coins_min' => 10, 'coins_max' => 25], | ||
| 'call_participation' => ['tier' => 'medium', 'coins_min' => 15, 'coins_max' => 30], | ||
| 'forum_debate' => ['tier' => 'medium', 'coins_min' => 10, 'coins_max' => 20], | ||
| 'content_share' => ['tier' => 'low', 'coins_min' => 5, 'coins_max' => 10], | ||
| 'engagement' => ['tier' => 'low', 'coins_min' => 1, 'coins_max' => 3], | ||
| 'repo_star' => ['tier' => 'low', 'coins_min' => 2, 'coins_max' => 2], | ||
| 'message' => ['tier' => 'low', 'coins_min' => 1, 'coins_max' => 2], | ||
| 'voice' => ['tier' => 'low', 'coins_min' => 1, 'coins_max' => 3], | ||
| ], | ||
|
|
||
| 'auto_approve_tiers' => ['low', 'medium'], | ||
|
|
||
| 'engagement_formula' => [ | ||
| 'reactions_multiplier' => 0.5, | ||
| 'reactions_cap' => 25, | ||
| 'bookmarks_multiplier' => 1.0, | ||
| 'bookmarks_cap' => 15, | ||
| 'comments_multiplier' => 2.0, | ||
| 'comments_cap' => 30, | ||
| ], | ||
|
|
||
| 'xp_multiplier' => 1, | ||
| ]; |
69 changes: 69 additions & 0 deletions
69
app-modules/activity/database/factories/InteractionFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Activity\Database\Factories; | ||
|
|
||
| use He4rt\Activity\Tracking\Enums\ActivityStatus; | ||
| use He4rt\Activity\Tracking\Enums\ActivityType; | ||
| use He4rt\Activity\Tracking\Enums\ValueTier; | ||
| use He4rt\Activity\Tracking\Models\Interaction; | ||
| use He4rt\Gamification\Character\Models\Character; | ||
| use He4rt\Identity\ExternalIdentity\Enums\IdentityProvider; | ||
| use He4rt\Identity\Tenant\Models\Tenant; | ||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
|
||
| /** | ||
| * @extends Factory<Interaction> | ||
| */ | ||
| final class InteractionFactory extends Factory | ||
| { | ||
| protected $model = Interaction::class; | ||
|
|
||
| public function definition(): array | ||
| { | ||
| return [ | ||
| 'character_id' => Character::factory(), | ||
| 'tenant_id' => Tenant::factory(), | ||
| 'type' => ActivityType::Article, | ||
| 'provider' => IdentityProvider::DevTo, | ||
| 'value_tier' => ValueTier::High, | ||
| 'coins_min' => 100, | ||
| 'coins_max' => 300, | ||
| 'status' => ActivityStatus::Pending, | ||
| 'occurred_at' => now(), | ||
| ]; | ||
| } | ||
|
|
||
| public function autoApproved(): self | ||
| { | ||
| return $this->state([ | ||
| 'status' => ActivityStatus::AutoApproved, | ||
| 'type' => ActivityType::Engagement, | ||
| 'value_tier' => ValueTier::Low, | ||
| 'coins_min' => 1, | ||
| 'coins_max' => 3, | ||
| ]); | ||
| } | ||
|
|
||
| public function approved(): self | ||
| { | ||
| return $this->state([ | ||
| 'status' => ActivityStatus::Approved, | ||
| 'reviewed_at' => now(), | ||
| ]); | ||
| } | ||
|
|
||
| public function withEngagement(int $reactions = 0, int $comments = 0, int $bookmarks = 0): self | ||
| { | ||
| return $this->state([ | ||
| 'metadata' => [ | ||
| 'engagement_snapshot' => [ | ||
| 'reactions' => $reactions, | ||
| 'comments' => $comments, | ||
| 'bookmarks' => $bookmarks, | ||
| ], | ||
| ], | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app-modules/activity/database/migrations/2026_03_18_000000_create_interactions_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| public function up(): void | ||
| { | ||
| Schema::create('interactions', function (Blueprint $table): void { | ||
| $table->uuid('id')->primary(); | ||
| $table->foreignUuid('character_id')->constrained('characters'); | ||
| $table->foreignId('tenant_id')->constrained('tenants'); | ||
| $table->string('type'); | ||
| $table->string('provider'); | ||
| $table->string('value_tier'); | ||
| $table->integer('coins_min'); | ||
| $table->integer('coins_max'); | ||
| $table->integer('coins_awarded')->nullable(); | ||
| $table->integer('xp_awarded')->nullable(); | ||
| $table->string('status')->default('pending'); | ||
| $table->nullableUuidMorphs('source'); | ||
| $table->string('external_ref')->unique()->nullable(); | ||
| $table->jsonb('metadata')->nullable(); | ||
| $table->timestamp('occurred_at'); | ||
| $table->timestamp('reviewed_at')->nullable(); | ||
| $table->timestamps(); | ||
|
|
||
| $table->index(['character_id', 'type', 'created_at'], 'idx_interactions_character_type'); | ||
| $table->index(['status', 'value_tier'], 'idx_interactions_status_tier'); | ||
| $table->index(['tenant_id', 'occurred_at'], 'idx_interactions_tenant'); | ||
| }); | ||
| } | ||
|
|
||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('interactions'); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope
external_refuniqueness to tenant/provider to avoid cross-tenant collisions.A global unique constraint on
external_refcan reject legitimate interactions from another tenant/provider using the same upstream reference.Suggested migration adjustment
🤖 Prompt for AI Agents