]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Channel.php
configurable min age and message source
[alttp.git] / app / Models / Channel.php
index 8045a4194fa529561ba6a091c0aa7770beb18dce..c6dfb6aaa19b57a019b51dba4f4167b49382e094 100644 (file)
@@ -43,14 +43,23 @@ class Channel extends Model {
        }
 
        public function queryChatlog() {
-               return ChatLog::where('type', '=', 'chat')
+               $min_age = $this->getChatSetting('min_age', 1);
+               $query = ChatLog::where('type', '=', 'chat')
                        ->where('banned', '=', false)
-                       ->where('created_at', '<', now()->sub(1, 'day'))
+                       ->where('created_at', '<', now()->sub($min_age, 'day'))
                        ->where(function ($query) {
                                $query->whereNull('detected_language');
                                $query->orWhereIn('detected_language', $this->getPreferredLanguages());
                        })
                        ->inRandomOrder();
+               $source = $this->getChatSetting('source', 'any');
+               if (in_array($source, ['catchan', 'chan'])) {
+                       $query->where('channel_id', $this->id);
+               }
+               if (in_array($source, ['cat', 'catchan'])) {
+                       $query->where('twitch_category', $this->twitch_category);
+               }
+               return $query;
        }
 
        public function getPreferredLanguages() {