(Update)[Chat 2.0] Add repository

Also updated some other stuff ...
This commit is contained in:
poppabear8883
2018-05-07 16:35:24 -04:00
parent d9d4dc31df
commit e01fcb8855
10 changed files with 204 additions and 12 deletions
+18 -1
View File
@@ -12,6 +12,7 @@
namespace App\Console\Commands;
use App\Repositories\ChatRepository;
use Illuminate\Console\Command;
use App\Torrent;
use App\History;
@@ -22,6 +23,19 @@ use App\Message;
class autoGraveyard extends Command
{
/**
* @var ChatRepository
*/
private $chat;
public function __construct(ChatRepository $chat)
{
parent::__construct();
$this->chat = $chat;
}
/**
* The name and signature of the console command.
*
@@ -59,7 +73,10 @@ class autoGraveyard extends Command
// Auto Shout
$appurl = config('app.url');
Message::create(['user_id' => "1", 'chatroom_id' => "1", 'message' => "Ladies and Gents, [url={$appurl}/" . $user->username . "." . $user->id . "]" . $user->username . "[/url] has succesfully ressurected [url={$appurl}/torrents/" . $torrent->slug . "." . $torrent->id . "]" . $torrent->name . "[/url]. :zombie:"]);
$this->chat->system(
"Ladies and Gents, [url={$appurl}/{$user->username}.{$user->id}]{$user->username}[/url] has succesfully ressurected [url={$appurl}/torrents/{$torrent->slug}.{$torrent->id}]{$torrent->name}[/url]. :zombie:"
);
// PM User
PrivateMessage::create(['sender_id' => "1", 'reciever_id' => $user->id, 'subject' => "Successful Graveyard Ressurection", 'message' => "You have successfully ressurected [url={$appurl}/torrents/" . $torrent->slug . "." . $torrent->id . "]" . $torrent->name . "[/url] :zombie: ! Thank you for bringing a torrent back from the dead! Enjoy the freeleech tokens!
+14 -1
View File
@@ -12,6 +12,7 @@
namespace App\Console\Commands;
use App\Repositories\ChatRepository;
use Illuminate\Console\Command;
use App\Message;
use App\User;
@@ -20,6 +21,18 @@ use Carbon\Carbon;
class autoNerdStat extends Command
{
/**
* @var ChatRepository
*/
private $chat;
public function __construct(ChatRepository $chat)
{
parent::__construct();
$this->chat = $chat;
}
/**
* The name and signature of the console command.
*
@@ -79,6 +92,6 @@ class autoNerdStat extends Command
$selected = mt_rand(0, count($statArray) - 1);
// Auto Shout Nerd Stat
Message::create(['user_id' => "2", 'chatroom_id' => "3", 'message' => ":nerd: [b]Random Nerd Stat:[/b] " . $statArray[$selected] . " :nerd:"]);
$this->chat->system(":nerd: [b]Random Nerd Stat:[/b] " . $statArray[$selected] . " :nerd:");
}
}
+17 -1
View File
@@ -12,6 +12,7 @@
namespace App\Console\Commands;
use App\Repositories\ChatRepository;
use Illuminate\Console\Command;
use App\Message;
use App\FeaturedTorrent;
@@ -20,6 +21,18 @@ use Carbon\Carbon;
class removeFeaturedTorrent extends Command
{
/**
* @var ChatRepository
*/
private $chat;
public function __construct(ChatRepository $chat)
{
parent::__construct();
$this->chat = $chat;
}
/**
* The name and signature of the console command.
*
@@ -54,7 +67,10 @@ class removeFeaturedTorrent extends Command
// Auto Announce Featured Expired
$appurl = config('app.url');
Message::create(['user_id' => "1", 'chatroom_id' => "1", 'message' => "Ladies and Gents, [url={$appurl}/torrents/" . $torrent->slug . "." . $torrent->id . "]" . $torrent->name . "[/url] is no longer featured. :poop:"]);
$this->chat->system(
"Ladies and Gents, [url={$appurl}/torrents/{$torrent->slug}.{$torrent->id}]{$torrent->name}[/url] is no longer featured. :poop:"
);
// Delete The Record From DB
$featured_torrent->delete();
+16 -3
View File
@@ -9,6 +9,7 @@ use App\Http\Resources\ChatMessageResource;
use App\Http\Resources\ChatRoomResource;
use App\Http\Resources\UserResource;
use App\Message;
use App\Repositories\ChatRepository;
use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
@@ -16,6 +17,15 @@ use App\Http\Controllers\Controller;
class ChatController extends Controller
{
/**
* @var ChatRepository
*/
private $chat;
public function __construct(ChatRepository $chat)
{
$this->chat = $chat;
}
/* STATUSES */
public function statuses()
@@ -34,13 +44,16 @@ class ChatController extends Controller
/* MESSAGES */
public function createMessage(Request $request)
{
$user_id = $request->get('user_id');
$room_id = $request->get('chatroom_id');
$message = $request->get('message');
$broadcast = $request->get('broadcast');
$save = $request->get('save');
$message = Message::create($request->except(['broadcast', 'save']));
if ($broadcast) {
broadcast(new MessageSent($message));
$message = $this->chat->message($user_id, $room_id, $message);
} else {
$message = $this->chat->dontBroadcast()->message($user_id, $room_id, $message);
}
if (!$save) {
-1
View File
@@ -17,7 +17,6 @@ use Illuminate\Support\Facades\DB;
use App\User;
use App\BonExchange;
use App\BonTransactions;
use App\Shoutbox;
use App\PrivateMessage;
use App\PersonalFreeleech;
use App\Torrent;
+18 -4
View File
@@ -12,6 +12,8 @@
namespace App\Http\Controllers;
use App\Events\MessageSent;
use App\Repositories\ChatRepository;
use App\Repositories\TaggedUserRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
@@ -45,9 +47,15 @@ class ForumController extends Controller
*/
private $tag;
public function __construct(TaggedUserRepository $tag)
/**
* @var ChatRepository
*/
private $chat;
public function __construct(TaggedUserRepository $tag, ChatRepository $chat)
{
$this->tag = $tag;
$this->chat = $chat;
}
/**
@@ -264,9 +272,12 @@ class ForumController extends Controller
// Find the user who initated the topic
$topicCreator = User::findOrFail($topic->first_post_user_id);
// Post To ShoutBox
// Post To Chatbox
$appurl = config('app.url');
Message::create(['user_id' => "1", 'chatroom_id' => "3", 'message' => "User [url={$appurl}/" . $user->username . "." . $user->id . "]" . $user->username . "[/url] has left a reply on topic [url={$appurl}/forums/topic/" . $topic->slug . "." . $topic->id . "?page={$post->getPageNumber()}#post-{$post->id}" . "]" . $topic->name . "[/url]"]);
$postUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}?page={$post->getPageNumber()}#post-{$post->id}";
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
$this->chat->system("User [url=$profileUrl]{$user->username}[/url] has left a reply on topic [url={$postUrl}]{$topic->name}[/url]");
// Mail Topic Creator Of New Reply
if ($post->user_id != $topic->first_post_user_id) {
@@ -357,7 +368,10 @@ class ForumController extends Controller
// Post To ShoutBox
$appurl = config('app.url');
Message::create(['user_id' => "1", 'chatroom_id' => "3", 'message' => "User [url={$appurl}/" . $user->username . "." . $user->id . "]" . $user->username . "[/url] has created a new topic [url={$appurl}/forums/topic/" . $topic->slug . "." . $topic->id . "]" . $topic->name . "[/url]"]);
$topicUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}";
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
$this->chat->system("User [url={$profileUrl}]{$user->username}[/url] has created a new topic [url={$topicUrl}]{$topic->name}[/url]");
//Achievements
$user->unlock(new UserMadeFirstPost(), 1);
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace App\Repositories;
use App\Chatroom;
use App\Events\MessageSent;
use App\Message;
use Illuminate\Database\Eloquent\Model;
class ChatRepository
{
protected $broadcast = true;
/**
* @var Message
*/
private $message;
/**
* @var Chatroom
*/
private $room;
public function __construct(Message $message, Chatroom $room)
{
$this->message = $message;
$this->room = $room;
}
public function message($user_id, $room_id, $message)
{
$message = $this->message->create([
'user_id' => $user_id,
'chatroom_id' => $room_id,
'message' => $message
]);
if ($this->broadcast)
broadcast(new MessageSent($message));
return $message;
}
/**
* @param $message
* @return mixed
*/
public function system($message)
{
$this->message(1, $this->systemChatroom(), $message);
return $this;
}
public function dontBroadcast()
{
$this->broadcast = false;
return $this;
}
public function systemChatroom($room = null)
{
$config = config('chat.system_chatroom');
if ($room !== null)
{
if ($room instanceof Model) {
$room = $room->id;
} elseif (is_int($room)) {
$room = $this->room->findOrFail($room)->id;
} else {
$room = $this->room->whereName($room)->first()->id;
}
} elseif (is_int($config)) {
$room = $this->room->findOrFail($config)->id;
} elseif ($config instanceof Model) {
$room = $config->id;
} else {
$room = $this->room->whereName($config)->first()->id;
}
return $room;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
return [
/**
* Which broadcasting driver will be used ?
*
* Supports: Pusher or Database
*
* Note: If using a Free Pusher account, once daily limits are hit the system will automatically fallback to
* database driver.
*/
'driver' => 'Pusher',
/**
* Which chatroom should system messages be routed to ?
*
* Note: can use the id or name of the chatroom
*
* id (integer) example: 3
* name (string) example: 'System'
*/
'system_chatroom' => 'System',
];
@@ -199,7 +199,11 @@
this.auth = response.data
/* Add system message */
this.createMessage(`${this.auth.username} has updated their status to ${this.auth.chat_status.name}`, true)
this.createMessage(
`[url=/${this.auth.username}.${this.auth.id}]${this.auth.username}[/url] has updated their status to [b]${this.auth.chat_status.name}[/b]`,
true
)
})
}
},
+2
View File
@@ -442,6 +442,8 @@
font-size: 0.9em;
color: #939393;
background: transparent;
padding: 0;
margin: 0;
}
}