A lot of things.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
@@ -71,4 +72,40 @@ class XenforoApiService {
|
||||
});
|
||||
}
|
||||
|
||||
public function createCommentsThread( Entry $entry ): bool
|
||||
{
|
||||
if( !$entry->comments_thread_id || $entry->comments_thread_id <= 0 ){
|
||||
$data = [
|
||||
'node_id' => config('xenforo.comments_node_id'),
|
||||
'title' => $entry->complete_title,
|
||||
'message' => $entry->description,
|
||||
'prefix_id' => config('xenforo.comments_prefixes')[$entry->type] ?? 1,
|
||||
'custom_fields' => [ 'entry_id' => $entry->id ],
|
||||
'discussion_open' => true,
|
||||
];
|
||||
|
||||
// TODO: Flag must be removed.
|
||||
$response = $this->post("threads?api_bypass_permissions=true", config('xenforo.bot_user_id'), $data );
|
||||
if( $response['success'] === true ){
|
||||
$commentsThreadId = $response['thread']['thread_id'];
|
||||
$entry->update(['comments_thread_id' => $commentsThreadId]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function getThreadPosts(int $threadId, int $page = 1 ): array
|
||||
{
|
||||
$response = $this->get("threads/{$threadId}/posts?page=$page");
|
||||
if( !isset( $response['posts'] ) || $response['posts'] === [] )
|
||||
return [ 'posts' => [], 'pagination' => null ];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user