Add all files
This commit is contained in:
356
extensions/Others/SocialBase/docs/AUTO_MODERATION_HOOKS.md
Normal file
356
extensions/Others/SocialBase/docs/AUTO_MODERATION_HOOKS.md
Normal file
@@ -0,0 +1,356 @@
|
||||
# Auto-Moderation Hooks System
|
||||
|
||||
The SocialBase messaging system includes a powerful hooking system that allows extensions to automatically moderate messages using custom filters and AI.
|
||||
|
||||
## 🎯 Overview
|
||||
|
||||
When a message is sent, the system dispatches a `socialbase.message.moderation` event that extensions can listen to. Extensions can analyze the message and return an action to take.
|
||||
|
||||
## 📋 Available Actions
|
||||
|
||||
Extensions can return one of the following actions:
|
||||
|
||||
- **`flag`** - Flag the message for manual review
|
||||
- **`delete`** - Automatically delete the message
|
||||
- **`approve`** - Pre-approve the message
|
||||
- **`keep`** or `null` - Do nothing, allow the message
|
||||
|
||||
## 🔧 Implementation
|
||||
|
||||
### Basic Example
|
||||
|
||||
```php
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
// In your extension's boot() method
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
// Analyze the message
|
||||
$content = strtolower($message->content);
|
||||
|
||||
// Check for spam keywords
|
||||
$spamKeywords = ['casino', 'viagra', 'lottery', 'winner'];
|
||||
foreach ($spamKeywords as $keyword) {
|
||||
if (str_contains($content, $keyword)) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => "Message contains spam keyword: {$keyword}",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Allow the message
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Example with AI
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
// Use OpenAI or similar to analyze message
|
||||
$analysis = analyzeMessageWithAI($message->content);
|
||||
|
||||
if ($analysis['is_toxic'] && $analysis['confidence'] > 0.9) {
|
||||
return [
|
||||
'action' => 'delete',
|
||||
'reason' => 'Toxic content detected with high confidence',
|
||||
];
|
||||
}
|
||||
|
||||
if ($analysis['is_spam'] && $analysis['confidence'] > 0.7) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => 'Possible spam detected',
|
||||
];
|
||||
}
|
||||
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
```
|
||||
|
||||
### URL Filter Example
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
// Check for URLs
|
||||
if (preg_match('/(https?:\/\/[^\s]+)/', $message->content, $matches)) {
|
||||
$url = $matches[1];
|
||||
|
||||
// Check against blacklist
|
||||
$blacklistedDomains = ['spam-site.com', 'phishing-site.com'];
|
||||
foreach ($blacklistedDomains as $domain) {
|
||||
if (str_contains($url, $domain)) {
|
||||
return [
|
||||
'action' => 'delete',
|
||||
'reason' => "Blacklisted URL: {$domain}",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Flag messages with multiple URLs
|
||||
$urlCount = substr_count($message->content, 'http');
|
||||
if ($urlCount > 2) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => "Message contains {$urlCount} URLs",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
```
|
||||
|
||||
### Rate Limiting Example
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
if (!$message->sender_id) {
|
||||
return ['action' => 'keep']; // System messages
|
||||
}
|
||||
|
||||
// Check messages sent in last minute
|
||||
$recentMessages = \Paymenter\Extensions\Others\SocialBase\Models\Message::where('sender_id', $message->sender_id)
|
||||
->where('created_at', '>', now()->subMinute())
|
||||
->count();
|
||||
|
||||
if ($recentMessages > 10) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => 'User sent too many messages ({$recentMessages} in 1 minute)',
|
||||
];
|
||||
}
|
||||
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
```
|
||||
|
||||
### Content Length Filter
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
$length = strlen($message->content);
|
||||
|
||||
// Flag very short messages (potential spam)
|
||||
if ($length < 3) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => 'Message too short (possible spam)',
|
||||
];
|
||||
}
|
||||
|
||||
// Flag extremely long messages
|
||||
if ($length > 5000) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => 'Message exceeds maximum length',
|
||||
];
|
||||
}
|
||||
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
```
|
||||
|
||||
## 🚨 User Reporting System
|
||||
|
||||
Users can report messages directly. When a message receives 3 or more reports, it's automatically flagged for review.
|
||||
|
||||
### Report a Message (For Extensions)
|
||||
|
||||
```php
|
||||
use Paymenter\Extensions\Others\SocialBase\Helpers\MessagingHelper;
|
||||
|
||||
MessagingHelper::reportMessage(
|
||||
messageId: 123,
|
||||
reportedBy: $userId,
|
||||
reason: 'spam',
|
||||
description: 'This message contains unwanted advertising'
|
||||
);
|
||||
```
|
||||
|
||||
### Report Reasons
|
||||
|
||||
Common report reasons:
|
||||
- `spam` - Unwanted or repetitive content
|
||||
- `harassment` - Bullying or threatening behavior
|
||||
- `inappropriate` - Offensive or adult content
|
||||
- `scam` - Fraudulent or phishing attempt
|
||||
- `other` - Other reason (requires description)
|
||||
|
||||
## 📊 Available Message Data
|
||||
|
||||
The `$message` object passed to the hook contains:
|
||||
|
||||
```php
|
||||
$message->id // Message ID
|
||||
$message->conversation_id // Conversation ID
|
||||
$message->sender_id // Sender user ID (null for system messages)
|
||||
$message->sender // Sender user object
|
||||
$message->content // Message text content
|
||||
$message->type // 'text' or 'system'
|
||||
$message->is_system // Boolean
|
||||
$message->system_type // Type if system message
|
||||
$message->metadata // Additional data (array)
|
||||
$message->created_at // Timestamp
|
||||
$message->conversation // Conversation object with participants
|
||||
```
|
||||
|
||||
## 🔔 Available Events
|
||||
|
||||
### Message Events
|
||||
|
||||
```php
|
||||
// When a message is sent
|
||||
Event::listen('socialbase.message.sent', function ($message) {
|
||||
// Handle message sent
|
||||
});
|
||||
|
||||
// When a message is reported by a user
|
||||
Event::listen('socialbase.message.reported', function ($message, $report) {
|
||||
// Handle message report
|
||||
// $report contains: reporter, reason, description
|
||||
});
|
||||
|
||||
// When a message is flagged for moderation
|
||||
Event::listen('socialbase.message.flagged', function ($message, $flaggedBy) {
|
||||
// Handle message flagged
|
||||
});
|
||||
|
||||
// When a message is approved by moderator
|
||||
Event::listen('socialbase.message.approved', function ($message, $moderatorId) {
|
||||
// Handle message approved
|
||||
});
|
||||
|
||||
// When a message is deleted by moderator
|
||||
Event::listen('socialbase.message.deleted', function ($message, $moderatorId) {
|
||||
// Handle message deleted
|
||||
});
|
||||
```
|
||||
|
||||
## 🎓 Best Practices
|
||||
|
||||
1. **Return Early** - Only return an action if you need to moderate the message
|
||||
2. **Provide Reasons** - Always include a clear reason for moderation actions
|
||||
3. **Don't Block Execution** - Keep your analysis fast (<100ms recommended)
|
||||
4. **Log Actions** - Log your moderation decisions for debugging
|
||||
5. **Test Thoroughly** - Test with various message types before deploying
|
||||
6. **Avoid False Positives** - Be conservative with auto-delete actions
|
||||
7. **Use Confidence Scores** - For AI-based moderation, require high confidence
|
||||
|
||||
## ⚙️ Configuration Example
|
||||
|
||||
Create a config file for your moderation extension:
|
||||
|
||||
```php
|
||||
return [
|
||||
'enabled' => true,
|
||||
'auto_flag_spam' => true,
|
||||
'auto_delete_toxic' => false, // Safer to flag first
|
||||
'spam_keywords' => ['casino', 'viagra', 'lottery'],
|
||||
'max_urls_per_message' => 2,
|
||||
'min_message_length' => 3,
|
||||
'max_message_length' => 2000,
|
||||
'rate_limit_messages_per_minute' => 10,
|
||||
];
|
||||
```
|
||||
|
||||
## 🔒 Security Considerations
|
||||
|
||||
- **Never trust user input** - Always sanitize and validate
|
||||
- **Rate limit API calls** - If using external AI services
|
||||
- **Cache results** - Cache analysis results to avoid repeated processing
|
||||
- **Monitor performance** - Track execution time of your filters
|
||||
- **Fail safely** - If your filter errors, return `['action' => 'keep']`
|
||||
|
||||
## 📈 Example: Complete Moderation Extension
|
||||
|
||||
```php
|
||||
namespace Paymenter\Extensions\Others\MyModerationExtension;
|
||||
|
||||
use App\Classes\Extension\Extension;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class MyModerationExtension extends Extension
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
Event::listen('socialbase.message.moderation', function ($message) {
|
||||
// Skip system messages
|
||||
if ($message->is_system) {
|
||||
return ['action' => 'keep'];
|
||||
}
|
||||
|
||||
$content = strtolower($message->content);
|
||||
$config = $this->getConfig();
|
||||
|
||||
// Check spam keywords
|
||||
foreach ($config['spam_keywords'] as $keyword) {
|
||||
if (str_contains($content, $keyword)) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => "Spam keyword detected: {$keyword}",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Check URL count
|
||||
$urlCount = substr_count($message->content, 'http');
|
||||
if ($urlCount > $config['max_urls_per_message']) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => "Too many URLs ({$urlCount})",
|
||||
];
|
||||
}
|
||||
|
||||
// Check message length
|
||||
$length = strlen($message->content);
|
||||
if ($length > $config['max_message_length']) {
|
||||
return [
|
||||
'action' => 'flag',
|
||||
'reason' => "Message too long ({$length} characters)",
|
||||
];
|
||||
}
|
||||
|
||||
return ['action' => 'keep'];
|
||||
});
|
||||
}
|
||||
|
||||
public function getConfig($values = [])
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => 'spam_keywords',
|
||||
'type' => 'textarea',
|
||||
'label' => 'Spam Keywords (one per line)',
|
||||
'description' => 'Messages containing these words will be flagged',
|
||||
],
|
||||
[
|
||||
'name' => 'max_urls_per_message',
|
||||
'type' => 'number',
|
||||
'label' => 'Maximum URLs per message',
|
||||
'default' => 2,
|
||||
],
|
||||
[
|
||||
'name' => 'max_message_length',
|
||||
'type' => 'number',
|
||||
'label' => 'Maximum message length',
|
||||
'default' => 2000,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🎉 Summary
|
||||
|
||||
The auto-moderation hooks system allows you to:
|
||||
- ✅ Automatically filter spam and toxic content
|
||||
- ✅ Implement custom business rules
|
||||
- ✅ Integrate AI-based content analysis
|
||||
- ✅ Rate limit users
|
||||
- ✅ Block malicious URLs
|
||||
- ✅ Track and handle user reports
|
||||
- ✅ Build sophisticated content filters without touching core code
|
||||
|
||||
Happy moderating! 🛡️
|
||||
|
||||
305
extensions/Others/SocialBase/docs/MESSAGE_REPORTING.md
Normal file
305
extensions/Others/SocialBase/docs/MESSAGE_REPORTING.md
Normal file
@@ -0,0 +1,305 @@
|
||||
# Message Reporting System
|
||||
|
||||
The SocialBase messaging system includes comprehensive message reporting functionality with automatic notifications.
|
||||
|
||||
## Table of Contents
|
||||
- [How to Report a Message](#how-to-report-a-message)
|
||||
- [Notification System](#notification-system)
|
||||
- [Admin Workflow](#admin-workflow)
|
||||
- [Programmatic Usage](#programmatic-usage)
|
||||
|
||||
## How to Report a Message
|
||||
|
||||
### Using the Livewire Component
|
||||
|
||||
In your Blade views, you can add a report button for any message:
|
||||
|
||||
```blade
|
||||
<livewire:socialbase.report-message :messageId="$message->id" />
|
||||
```
|
||||
|
||||
This will render a "Report" button that opens a modal with:
|
||||
- Reason selection (spam, harassment, inappropriate, scam, other)
|
||||
- Optional description field (500 chars max)
|
||||
- Submit and cancel buttons
|
||||
|
||||
### Using PHP/Helper Method
|
||||
|
||||
```php
|
||||
use Paymenter\Extensions\Others\SocialBase\Helpers\MessagingHelper;
|
||||
|
||||
// Report a message
|
||||
MessagingHelper::reportMessage(
|
||||
$messageId, // ID of the message to report
|
||||
$reportedByUserId, // ID of the user reporting
|
||||
'spam', // Reason: spam, harassment, inappropriate, scam, other
|
||||
'Optional description' // Additional details (optional)
|
||||
);
|
||||
```
|
||||
|
||||
## Notification System
|
||||
|
||||
### When a User Reports a Message
|
||||
|
||||
The reporter automatically receives a **confirmation message**:
|
||||
|
||||
**Subject:** "Report Received - We're Reviewing It"
|
||||
|
||||
**Content:**
|
||||
```
|
||||
Thank you for reporting a message. We take all reports seriously and our moderation team will review it shortly.
|
||||
|
||||
Report Details:
|
||||
- Reason: [Spam/Harassment/etc]
|
||||
- Report ID: #123
|
||||
|
||||
You will receive another message once our team has reviewed your report.
|
||||
```
|
||||
|
||||
**Message Type:** `message_report_confirmation`
|
||||
|
||||
### When Admin Reviews the Report
|
||||
|
||||
#### If Report is Dismissed (No Action)
|
||||
|
||||
**Subject:** "Report Update: No Action Taken"
|
||||
|
||||
**Content:**
|
||||
```
|
||||
Thank you for your report (ID: #123).
|
||||
|
||||
After review, our moderation team has determined that the reported message does not violate our community guidelines. The message will remain visible.
|
||||
|
||||
Report Reason: [Reason]
|
||||
|
||||
If you believe this decision was made in error, please contact our support team.
|
||||
```
|
||||
|
||||
#### If Action is Taken
|
||||
|
||||
**Subject:** "Report Update: Action Taken"
|
||||
|
||||
**Content:**
|
||||
```
|
||||
Thank you for your report (ID: #123).
|
||||
|
||||
Our moderation team has reviewed your report and taken action.
|
||||
|
||||
Action Taken: [The reported message has been removed/flagged/etc]
|
||||
Report Reason: [Reason]
|
||||
|
||||
We appreciate your help in keeping our community safe and respectful.
|
||||
```
|
||||
|
||||
**Message Type:** `message_report_decision`
|
||||
|
||||
## Admin Workflow
|
||||
|
||||
### 1. Viewing Reports
|
||||
|
||||
Navigate to **Admin → Messaging → Message Reports**
|
||||
|
||||
The admin panel shows:
|
||||
- Reporter information
|
||||
- Reported message content
|
||||
- Message sender
|
||||
- Report reason and description
|
||||
- Current status (pending/reviewed/dismissed)
|
||||
|
||||
### 2. Reviewing a Report
|
||||
|
||||
1. Click the edit icon on a report
|
||||
2. Review the report details
|
||||
3. Check the message content and context
|
||||
4. Update the **Status** field:
|
||||
- **Pending** - Not yet reviewed
|
||||
- **Reviewed** - Action taken
|
||||
- **Dismissed** - No action needed
|
||||
5. Optionally moderate the message itself (flag/delete/approve)
|
||||
6. Click **Save**
|
||||
|
||||
### 3. Automatic Notifications
|
||||
|
||||
When you save a report with status changed from "pending":
|
||||
- The reporter is automatically notified
|
||||
- Notification includes action taken (based on message moderation status)
|
||||
- Event `socialbase.message.report_reviewed` is dispatched
|
||||
|
||||
## Programmatic Usage
|
||||
|
||||
### Listening for Report Events
|
||||
|
||||
#### When Message is Reported
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.reported', function ($report) {
|
||||
// $report->id - Report ID
|
||||
// $report->message_id - Reported message ID
|
||||
// $report->reported_by - Reporter user ID
|
||||
// $report->reason - Report reason
|
||||
// $report->description - Additional details
|
||||
});
|
||||
```
|
||||
|
||||
#### When Report is Reviewed
|
||||
|
||||
```php
|
||||
Event::listen('socialbase.message.report_reviewed', function ($report, $decision) {
|
||||
// $report - MessageReport model
|
||||
// $decision - 'reviewed' or 'dismissed'
|
||||
|
||||
// Access related data
|
||||
$message = $report->message;
|
||||
$reporter = $report->reporter;
|
||||
$reviewer = $report->reviewer;
|
||||
});
|
||||
```
|
||||
|
||||
### Auto-Flagging
|
||||
|
||||
Messages with **3 or more pending reports** are automatically flagged for review:
|
||||
|
||||
```php
|
||||
// This happens automatically in MessagingService::reportMessage()
|
||||
$pendingReports = MessageReport::where('message_id', $messageId)
|
||||
->where('status', 'pending')
|
||||
->count();
|
||||
|
||||
if ($pendingReports >= 3) {
|
||||
$message->update(['moderation_status' => 'flagged']);
|
||||
}
|
||||
```
|
||||
|
||||
## Report Reasons
|
||||
|
||||
Available report reasons:
|
||||
|
||||
| Reason | Description |
|
||||
|--------|-------------|
|
||||
| `spam` | Unsolicited or repetitive messages |
|
||||
| `harassment` | Abusive or threatening content |
|
||||
| `inappropriate` | Content that violates guidelines |
|
||||
| `scam` | Fraudulent or phishing attempts |
|
||||
| `other` | Other violations not listed |
|
||||
|
||||
## Database Schema
|
||||
|
||||
### ext_social_message_reports
|
||||
|
||||
| Column | Type | Description |
|
||||
|--------|------|-------------|
|
||||
| id | bigint | Primary key |
|
||||
| message_id | bigint | FK to ext_social_messages |
|
||||
| reported_by | bigint | FK to users |
|
||||
| reason | string | Report reason enum |
|
||||
| description | text | Additional details (optional) |
|
||||
| status | string | pending/reviewed/dismissed |
|
||||
| reviewed_by | bigint | FK to users (nullable) |
|
||||
| reviewed_at | timestamp | When reviewed (nullable) |
|
||||
| created_at | timestamp | When reported |
|
||||
| updated_at | timestamp | Last modified |
|
||||
|
||||
## Best Practices
|
||||
|
||||
### For Developers
|
||||
|
||||
1. **Always use the helper method** instead of creating reports directly
|
||||
2. **Don't send duplicate reports** - check if user already reported before allowing
|
||||
3. **Include context** in description field when possible
|
||||
4. **Respect privacy** - only show necessary information to reporters
|
||||
|
||||
### For Administrators
|
||||
|
||||
1. **Review reports promptly** to maintain user trust
|
||||
2. **Be consistent** with moderation decisions
|
||||
3. **Document patterns** - use moderation notes
|
||||
4. **Communicate clearly** - notifications explain your decisions
|
||||
5. **Monitor auto-flagged messages** - 3+ reports deserve attention
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- Users can only report messages in conversations they participate in
|
||||
- System messages cannot be reported
|
||||
- Reports are visible only to administrators with proper permissions
|
||||
- Reporter identity is kept confidential from message sender
|
||||
- All reports are logged for audit purposes
|
||||
|
||||
## Permissions
|
||||
|
||||
Required permissions for report management:
|
||||
|
||||
- `socialbase.reports.view` - View message reports
|
||||
- `socialbase.reports.review` - Update report status
|
||||
- `socialbase.reports.delete` - Delete reports
|
||||
|
||||
Set these in Admin → Roles & Permissions → [Role] → Social Base section.
|
||||
|
||||
## Integration Example
|
||||
|
||||
### Adding Report Button to Custom UI
|
||||
|
||||
```blade
|
||||
<div class="message">
|
||||
<div class="message-content">{{ $message->content }}</div>
|
||||
<div class="message-actions">
|
||||
<!-- Other actions -->
|
||||
@if(!$message->is_system && Auth::id() !== $message->sender_id)
|
||||
<livewire:socialbase.report-message :messageId="$message->id" />
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Custom Report Handler
|
||||
|
||||
```php
|
||||
use Paymenter\Extensions\Others\SocialBase\Helpers\MessagingHelper;
|
||||
|
||||
class CustomReportHandler
|
||||
{
|
||||
public function reportSpam($messageId, $userId)
|
||||
{
|
||||
// Add custom logic before reporting
|
||||
$this->logReport($userId, $messageId);
|
||||
|
||||
// Report the message
|
||||
MessagingHelper::reportMessage(
|
||||
$messageId,
|
||||
$userId,
|
||||
'spam',
|
||||
'Automated spam detection'
|
||||
);
|
||||
|
||||
// Add custom logic after reporting
|
||||
$this->notifyModerators($messageId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Reports Not Sending Notifications
|
||||
|
||||
1. Check that `socialbase.message.reported` event is dispatched
|
||||
2. Verify MessagingHelper is available
|
||||
3. Check logs for error messages
|
||||
4. Ensure user has valid email/account
|
||||
|
||||
### Auto-Flagging Not Working
|
||||
|
||||
1. Verify the reportMessage() method is being used
|
||||
2. Check if message already flagged
|
||||
3. Ensure at least 3 pending reports exist
|
||||
4. Review logs for any errors
|
||||
|
||||
### Report Modal Not Showing
|
||||
|
||||
1. Ensure Livewire is properly loaded
|
||||
2. Check JavaScript console for errors
|
||||
3. Verify component is registered
|
||||
4. Clear cache: `php artisan optimize:clear`
|
||||
|
||||
---
|
||||
|
||||
For more information about the messaging system, see [MESSAGING_SYSTEM.md](MESSAGING_SYSTEM.md)
|
||||
|
||||
285
extensions/Others/SocialBase/docs/MESSAGING_SYSTEM.md
Normal file
285
extensions/Others/SocialBase/docs/MESSAGING_SYSTEM.md
Normal file
@@ -0,0 +1,285 @@
|
||||
# SocialBase Messaging System
|
||||
|
||||
The SocialBase extension includes a comprehensive messaging system that allows:
|
||||
- User-to-user direct messaging
|
||||
- System messages from extensions
|
||||
- Admin moderation tools
|
||||
- Message flagging and review
|
||||
|
||||
## For Extension Developers
|
||||
|
||||
### Sending System Messages
|
||||
|
||||
Other extensions can easily send system messages to users using the `MessagingHelper` class.
|
||||
|
||||
```php
|
||||
use Paymenter\Extensions\Others\SocialBase\Helpers\MessagingHelper;
|
||||
|
||||
// Send a system message to a single user
|
||||
MessagingHelper::sendSystemMessage(
|
||||
userId: 1,
|
||||
content: 'Your order #12345 has been completed',
|
||||
systemType: 'order_update',
|
||||
metadata: ['order_id' => 12345]
|
||||
);
|
||||
|
||||
// Send a system message to multiple users
|
||||
MessagingHelper::sendSystemMessageToUsers(
|
||||
userIds: [1, 2, 3],
|
||||
content: 'System maintenance scheduled for tomorrow',
|
||||
systemType: 'system_announcement'
|
||||
);
|
||||
|
||||
// Send a direct message from one user to another
|
||||
MessagingHelper::sendDirectMessage(
|
||||
senderId: 1,
|
||||
recipientId: 2,
|
||||
content: 'Hello! I have a question about my order.',
|
||||
metadata: []
|
||||
);
|
||||
|
||||
// Check if messaging system is available
|
||||
if (MessagingHelper::isAvailable()) {
|
||||
// Send messages
|
||||
}
|
||||
|
||||
// Get unread message count for a user
|
||||
$unreadCount = MessagingHelper::getUnreadCount($userId);
|
||||
```
|
||||
|
||||
### System Message Types
|
||||
|
||||
When sending system messages, use appropriate `systemType` values to categorize them:
|
||||
|
||||
- `general` - General system notifications
|
||||
- `order_update` - Order status changes
|
||||
- `payment_received` - Payment confirmations
|
||||
- `account_notification` - Account-related notifications
|
||||
- `ticket_update` - Support ticket updates
|
||||
- `service_activation` - Service activation notifications
|
||||
- `invoice_generated` - New invoice notifications
|
||||
- Custom types specific to your extension
|
||||
|
||||
### Listening for Message Events
|
||||
|
||||
You can listen for messaging events in your extension:
|
||||
|
||||
```php
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
Event::listen('socialbase.message.sent', function ($message) {
|
||||
// Handle when a user message is sent
|
||||
});
|
||||
|
||||
Event::listen('socialbase.system_message.sent', function ($message, $userId) {
|
||||
// Handle when a system message is sent
|
||||
});
|
||||
|
||||
Event::listen('socialbase.message.flagged', function ($message, $flaggedBy) {
|
||||
// Handle when a message is flagged for moderation
|
||||
});
|
||||
|
||||
Event::listen('socialbase.message.approved', function ($message, $moderatorId) {
|
||||
// Handle when a message is approved by a moderator
|
||||
});
|
||||
|
||||
Event::listen('socialbase.message.deleted', function ($message, $moderatorId) {
|
||||
// Handle when a message is deleted by a moderator
|
||||
});
|
||||
```
|
||||
|
||||
### Using the MessagingService Directly
|
||||
|
||||
For advanced use cases, you can use the `MessagingService` class directly:
|
||||
|
||||
```php
|
||||
use Paymenter\Extensions\Others\SocialBase\Services\MessagingService;
|
||||
|
||||
$service = new MessagingService();
|
||||
|
||||
// Send a direct message
|
||||
$message = $service->sendDirectMessage($senderId, $recipientId, $content);
|
||||
|
||||
// Send a message to an existing conversation
|
||||
$message = $service->sendMessage($conversationId, $senderId, $content);
|
||||
|
||||
// Send system message
|
||||
$message = $service->sendSystemMessage($userId, $content, 'order_update', ['order_id' => 123]);
|
||||
|
||||
// Get user's conversations
|
||||
$conversations = $service->getUserConversations($userId, $includeArchived = false);
|
||||
|
||||
// Get unread count
|
||||
$unreadCount = $service->getUnreadCount($userId);
|
||||
|
||||
// Moderation actions
|
||||
$service->flagMessage($messageId, $flaggedBy, $reason);
|
||||
$service->approveMessage($messageId, $moderatorId);
|
||||
$service->deleteMessage($messageId, $moderatorId, $reason);
|
||||
```
|
||||
|
||||
## For Users
|
||||
|
||||
### Accessing Messages
|
||||
|
||||
- Navigate to the Messages page from the main navigation menu
|
||||
- Unread message counts are displayed in the navigation
|
||||
- Click on any conversation to view and reply to messages
|
||||
|
||||
### Sending Messages
|
||||
|
||||
1. Visit a user's profile
|
||||
2. Click the "Send Message" button
|
||||
3. Type your message and click Send
|
||||
|
||||
### Message Notifications
|
||||
|
||||
- Unread messages are highlighted in the conversation list
|
||||
- System messages appear with a special icon
|
||||
- Message counts update in real-time
|
||||
|
||||
## For Administrators
|
||||
|
||||
### Message Moderation
|
||||
|
||||
Access the Message Moderation panel from the admin dashboard:
|
||||
|
||||
1. Navigate to **Message Moderation** in the admin sidebar
|
||||
2. View all flagged messages
|
||||
3. Filter by moderation status, system messages, etc.
|
||||
|
||||
### Moderation Actions
|
||||
|
||||
- **Approve**: Mark a message as reviewed and appropriate
|
||||
- **Flag**: Mark a message for review (with reason)
|
||||
- **Delete**: Remove a message (with reason for deletion)
|
||||
|
||||
### Bulk Actions
|
||||
|
||||
Select multiple messages to:
|
||||
- Approve multiple messages at once
|
||||
- Delete multiple messages
|
||||
|
||||
### Viewing Message Details
|
||||
|
||||
Click "View" on any message to see:
|
||||
- Full message content
|
||||
- Sender information
|
||||
- Conversation context
|
||||
- Metadata (for system messages)
|
||||
- Moderation history
|
||||
|
||||
## Database Schema
|
||||
|
||||
### Tables
|
||||
|
||||
- `ext_social_conversations` - Conversation threads
|
||||
- `ext_social_conversation_participants` - Users in conversations
|
||||
- `ext_social_messages` - Individual messages
|
||||
- `ext_social_message_reads` - Read receipts
|
||||
|
||||
### Conversation Types
|
||||
|
||||
- `direct` - One-on-one user conversations
|
||||
- `group` - Group conversations (future feature)
|
||||
- `system` - System message conversations
|
||||
|
||||
## Example Use Cases
|
||||
|
||||
### Order Update Notification
|
||||
|
||||
```php
|
||||
// In your order processing extension
|
||||
use Paymenter\Extensions\Others\SocialBase\Helpers\MessagingHelper;
|
||||
|
||||
public function notifyOrderComplete($order)
|
||||
{
|
||||
MessagingHelper::sendSystemMessage(
|
||||
userId: $order->user_id,
|
||||
content: "Your order #{$order->id} has been completed successfully!",
|
||||
systemType: 'order_update',
|
||||
metadata: [
|
||||
'order_id' => $order->id,
|
||||
'status' => 'completed',
|
||||
]
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Payment Confirmation
|
||||
|
||||
```php
|
||||
public function notifyPaymentReceived($invoice)
|
||||
{
|
||||
MessagingHelper::sendSystemMessage(
|
||||
userId: $invoice->user_id,
|
||||
content: "Payment of {$invoice->total} received for invoice #{$invoice->id}",
|
||||
systemType: 'payment_received',
|
||||
metadata: [
|
||||
'invoice_id' => $invoice->id,
|
||||
'amount' => $invoice->total,
|
||||
]
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Broadcast System Announcement
|
||||
|
||||
```php
|
||||
public function sendMaintenanceNotification()
|
||||
{
|
||||
$allUserIds = User::pluck('id')->toArray();
|
||||
|
||||
MessagingHelper::sendSystemMessageToUsers(
|
||||
userIds: $allUserIds,
|
||||
content: 'Scheduled maintenance will occur tomorrow at 2 AM UTC for approximately 2 hours.',
|
||||
systemType: 'system_announcement'
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### MessagingHelper
|
||||
|
||||
| Method | Parameters | Returns | Description |
|
||||
|--------|------------|---------|-------------|
|
||||
| `sendSystemMessage` | `$userId`, `$content`, `$systemType`, `$metadata` | `Message` | Send system message to one user |
|
||||
| `sendSystemMessageToUsers` | `$userIds`, `$content`, `$systemType`, `$metadata` | `Message[]` | Send system message to multiple users |
|
||||
| `sendDirectMessage` | `$senderId`, `$recipientId`, `$content`, `$metadata` | `Message` | Send direct message between users |
|
||||
| `getUnreadCount` | `$userId` | `int` | Get unread message count |
|
||||
| `isAvailable` | - | `bool` | Check if messaging system is enabled |
|
||||
|
||||
### MessagingService
|
||||
|
||||
See "Using the MessagingService Directly" section above for full API reference.
|
||||
|
||||
## Configuration
|
||||
|
||||
The messaging system works out of the box with no additional configuration required. Messages are stored in the database and managed through Livewire components.
|
||||
|
||||
## Security
|
||||
|
||||
- Users can only send messages to other users
|
||||
- Users can only read their own conversations
|
||||
- Admins can moderate all messages
|
||||
- System messages can only be sent by extensions (not directly by users)
|
||||
- Message content is sanitized to prevent XSS attacks
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
- Conversations are paginated
|
||||
- Messages load on-demand
|
||||
- Indexes on key columns ensure fast queries
|
||||
- Soft deletes allow message recovery
|
||||
|
||||
## Future Features
|
||||
|
||||
- Group conversations
|
||||
- File attachments
|
||||
- Voice messages
|
||||
- Read receipts UI
|
||||
- Typing indicators
|
||||
- Push notifications
|
||||
- Email notifications for messages
|
||||
|
||||
321
extensions/Others/SocialBase/docs/USER_REPORTING.md
Normal file
321
extensions/Others/SocialBase/docs/USER_REPORTING.md
Normal file
@@ -0,0 +1,321 @@
|
||||
# User Reporting System
|
||||
|
||||
The SocialBase extension includes a comprehensive user reporting and moderation system that allows users to report inappropriate profiles and enables administrators to review and take action on these reports.
|
||||
|
||||
## Features
|
||||
|
||||
### User Features
|
||||
- **Report User Profiles**: Users can report other user profiles for various violations
|
||||
- **Multiple Report Reasons**: Support for common violation types (spam, harassment, inappropriate content, impersonation, scam/fraud)
|
||||
- **Additional Description**: Optional field for providing context
|
||||
- **Confirmation Notification**: Automatic system message confirming report receipt
|
||||
- **Decision Notification**: Automatic notification when admin reviews the report
|
||||
- **Easy Access**: Report button in user profile dropdown menu
|
||||
|
||||
### Admin Features
|
||||
- **Centralized Dashboard**: Dedicated admin resource in Profiles cluster
|
||||
- **Pending Reports Badge**: Visual indicator of pending reports in navigation
|
||||
- **Detailed Information**: View reported user, reporter, reason, and description
|
||||
- **Flexible Status Options**:
|
||||
- Pending Review (default)
|
||||
- Action Taken
|
||||
- No Action Required
|
||||
- Dismissed
|
||||
- **Admin Notes**: Internal notes field for documenting actions taken
|
||||
- **Automated Timestamps**: Tracks reviewer and review timestamp
|
||||
- **Permission-Based Access**: Integrated with Paymenter's permission system
|
||||
|
||||
## How to Report a User
|
||||
|
||||
### For Users
|
||||
|
||||
1. **Navigate to User Profile**
|
||||
- Go to any user's profile page
|
||||
|
||||
2. **Access Report Option**
|
||||
- Click the dropdown menu (⋮) in the profile header
|
||||
- Select "Report User" from the menu
|
||||
|
||||
3. **Fill Out Report Form**
|
||||
- Select a reason from the dropdown:
|
||||
- Spam
|
||||
- Harassment
|
||||
- Inappropriate Content
|
||||
- Impersonation
|
||||
- Scam/Fraud
|
||||
- Other
|
||||
- Optionally add a detailed description (up to 1000 characters)
|
||||
|
||||
4. **Submit Report**
|
||||
- Click "Submit Report"
|
||||
- You'll receive a confirmation system message immediately
|
||||
|
||||
5. **Wait for Decision**
|
||||
- Moderation team will review your report
|
||||
- You'll receive a system message with the decision
|
||||
|
||||
## How to Review Reports
|
||||
|
||||
### For Administrators
|
||||
|
||||
1. **Access User Reports**
|
||||
- Go to Admin Panel
|
||||
- Navigate to "Profiles" cluster
|
||||
- Click "User Reports"
|
||||
|
||||
2. **View Pending Reports**
|
||||
- Reports are filtered to show pending only by default
|
||||
- Badge on navigation shows count of pending reports
|
||||
- Reports are sorted by date (newest first)
|
||||
|
||||
3. **Review Report Details**
|
||||
- Click the edit icon (pencil) on any report
|
||||
- View complete information:
|
||||
- Reported user's name and email
|
||||
- Reporter's name and email
|
||||
- Report reason and description
|
||||
- Timestamps
|
||||
|
||||
4. **Make a Decision**
|
||||
- Change status from "Pending Review" to:
|
||||
- **Action Taken**: When you've taken action against the user
|
||||
- **No Action Required**: When report doesn't violate policies
|
||||
- **Dismissed**: When report is invalid or spam
|
||||
- Optionally add internal admin notes
|
||||
- Click "Save"
|
||||
|
||||
5. **Reporter Notification**
|
||||
- Reporter automatically receives a system message with:
|
||||
- Report ID reference
|
||||
- Status update
|
||||
- Appropriate message based on decision
|
||||
- Thank you for contributing to community safety
|
||||
|
||||
## Database Schema
|
||||
|
||||
### User Reports Table (`ext_social_user_reports`)
|
||||
|
||||
| Column | Type | Description |
|
||||
|--------|------|-------------|
|
||||
| id | bigint | Primary key |
|
||||
| reported_user_id | bigint | User being reported |
|
||||
| reported_by | bigint | User who made the report |
|
||||
| reason | string | Report reason (enum) |
|
||||
| description | text | Additional details (nullable) |
|
||||
| status | string | Review status (default: pending) |
|
||||
| admin_notes | text | Internal admin notes (nullable) |
|
||||
| reviewed_by | bigint | Admin who reviewed (nullable) |
|
||||
| reviewed_at | timestamp | When reviewed (nullable) |
|
||||
| created_at | timestamp | When reported |
|
||||
| updated_at | timestamp | Last update |
|
||||
|
||||
## Events
|
||||
|
||||
The user reporting system dispatches the following events:
|
||||
|
||||
### `socialbase.user.reported`
|
||||
**Dispatched when**: A user submits a report
|
||||
|
||||
**Data**: UserReport model instance
|
||||
|
||||
**Actions**:
|
||||
- Sends confirmation system message to reporter
|
||||
- Message includes report ID and reason
|
||||
|
||||
### `socialbase.user.report_reviewed`
|
||||
**Dispatched when**: Admin changes report status from pending
|
||||
|
||||
**Data**: UserReport model instance
|
||||
|
||||
**Actions**:
|
||||
- Sends decision system message to reporter
|
||||
- Message content varies by status:
|
||||
- **Action Taken**: Confirms appropriate action was taken
|
||||
- **No Action**: Explains no violation was found
|
||||
- **Dismissed**: Indicates report was dismissed
|
||||
|
||||
## System Messages
|
||||
|
||||
### Confirmation Message
|
||||
Sent immediately when user submits a report:
|
||||
|
||||
```
|
||||
**Report Received - We're Reviewing It**
|
||||
|
||||
Thank you for reporting a user. We take all reports seriously and our moderation team will review it shortly.
|
||||
|
||||
Report Details:
|
||||
- Reason: [Reason]
|
||||
- Report ID: #[ID]
|
||||
|
||||
You will receive another message once our team has reviewed your report.
|
||||
```
|
||||
|
||||
### Decision Messages
|
||||
|
||||
**Action Taken**:
|
||||
```
|
||||
**User Report Update - Decision Made**
|
||||
|
||||
Thank you for your report (ID: #[ID]) regarding [Username].
|
||||
|
||||
Our moderation team has reviewed your report.
|
||||
|
||||
Report Reason: [Reason]
|
||||
Status: Action Taken
|
||||
|
||||
Appropriate action has been taken based on our community guidelines. We appreciate your help in keeping our community safe.
|
||||
|
||||
Thank you for contributing to a safer community.
|
||||
```
|
||||
|
||||
**No Action Required**:
|
||||
```
|
||||
**User Report Update - Decision Made**
|
||||
|
||||
Thank you for your report (ID: #[ID]) regarding [Username].
|
||||
|
||||
Our moderation team has reviewed your report.
|
||||
|
||||
Report Reason: [Reason]
|
||||
Status: No Action
|
||||
|
||||
After careful review, our team determined that no policy violation occurred. If you have additional concerns, please contact our support team.
|
||||
|
||||
Thank you for contributing to a safer community.
|
||||
```
|
||||
|
||||
**Dismissed**:
|
||||
```
|
||||
**User Report Update - Decision Made**
|
||||
|
||||
Thank you for your report (ID: #[ID]) regarding [Username].
|
||||
|
||||
Our moderation team has reviewed your report.
|
||||
|
||||
Report Reason: [Reason]
|
||||
Status: Dismissed
|
||||
|
||||
This report has been dismissed. If you believe this decision was made in error, please contact our support team.
|
||||
|
||||
Thank you for contributing to a safer community.
|
||||
```
|
||||
|
||||
## Permissions
|
||||
|
||||
The user reporting system uses Paymenter's built-in permission system:
|
||||
|
||||
| Permission | Description |
|
||||
|------------|-------------|
|
||||
| `socialbase.reports.view` | View user reports in admin panel |
|
||||
| `socialbase.reports.review` | Review and update report status |
|
||||
| `socialbase.reports.delete` | Delete user reports |
|
||||
|
||||
Configure these permissions in: **Admin Panel → Administration → Roles**
|
||||
|
||||
## Technical Implementation
|
||||
|
||||
### Models
|
||||
- **UserReport** (`Paymenter\Extensions\Others\SocialBase\Models\UserReport`)
|
||||
- Relationships: reportedUser, reporter, reviewer
|
||||
|
||||
### Livewire Components
|
||||
- **ReportUser** (`socialbase.report-user`)
|
||||
- Handles report submission form
|
||||
- Validates input
|
||||
- Dispatches events
|
||||
|
||||
### Admin Resources
|
||||
- **UserReportResource**
|
||||
- Located in: `Admin/Resources/UserReportResource.php`
|
||||
- Cluster: ProfilesCluster
|
||||
- Pages: List, View, Edit
|
||||
|
||||
### Policies
|
||||
- **UserReportPolicy**
|
||||
- Controls admin access to reports
|
||||
- Enforces permission checks
|
||||
|
||||
### Event Listeners
|
||||
Registered in `SocialBase.php`:
|
||||
- `socialbase.user.reported` → Send confirmation
|
||||
- `socialbase.user.report_reviewed` → Send decision
|
||||
|
||||
## Best Practices
|
||||
|
||||
### For Users
|
||||
1. Only report genuine violations
|
||||
2. Provide specific details in description
|
||||
3. Select the most appropriate reason
|
||||
4. Don't spam reports
|
||||
5. Wait for moderation team response
|
||||
|
||||
### For Administrators
|
||||
1. Review all reports promptly
|
||||
2. Add admin notes for documentation
|
||||
3. Be consistent in decisions
|
||||
4. Take appropriate action for valid reports
|
||||
5. Communicate clearly through system messages
|
||||
6. Consider patterns (multiple reports on same user)
|
||||
|
||||
## Privacy & Security
|
||||
|
||||
- Report details are only visible to administrators
|
||||
- Reported users are not notified of reports
|
||||
- Reporter identity is protected
|
||||
- Admin notes are internal only
|
||||
- All actions are logged with timestamps
|
||||
- Permission-based access control
|
||||
|
||||
## Integration with Other Systems
|
||||
|
||||
The user reporting system integrates with:
|
||||
- **Messaging System**: For automated notifications
|
||||
- **Permission System**: For access control
|
||||
- **Event System**: For extensibility
|
||||
- **Profile System**: For context and actions
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
Potential future features:
|
||||
- Email notifications for high-priority reports
|
||||
- Automatic actions for repeat offenders
|
||||
- Report analytics dashboard
|
||||
- Appeal system for reported users
|
||||
- Integration with ban/restriction system
|
||||
- Bulk report handling
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Reports Not Appearing in Admin
|
||||
- Check extension is enabled
|
||||
- Clear caches: `php artisan cache:clear`
|
||||
- Verify migrations ran: check `ext_social_user_reports` table exists
|
||||
- Check user has `socialbase.reports.view` permission
|
||||
|
||||
### System Messages Not Sending
|
||||
- Verify MessagingHelper class exists
|
||||
- Check event listeners are registered
|
||||
- Review logs in storage/logs for errors
|
||||
- Ensure system conversation is created
|
||||
|
||||
### Report Button Not Showing
|
||||
- Check user is viewing another user's profile (not their own)
|
||||
- Verify Livewire component is registered
|
||||
- Clear view cache: `php artisan view:clear`
|
||||
- Check browser console for JavaScript errors
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
1. Check this documentation
|
||||
2. Review system logs (`storage/logs/laravel.log`)
|
||||
3. Verify permissions and configuration
|
||||
4. Check the SocialBase extension status
|
||||
|
||||
---
|
||||
|
||||
**Version**: 1.0
|
||||
**Last Updated**: October 1, 2025
|
||||
**Extension**: SocialBase for Paymenter
|
||||
|
||||
Reference in New Issue
Block a user