<commit_before><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Movim\Session;
use App\Contact;
use App\Configuration;

class User extends Model
{
    protected $fillable = ['id', 'language', 'nightmode', 'chatmain', 'nsfw', 'nickname', 'notificationchat', 'notificationcall'];
    public $with = ['session', 'capability'];
    protected $keyType = 'string';
    public $incrementing = false;
    private static $me = null;
    private $unreads = null;

    public function save(array $options = [])
    {
        parent::save($options);

        // Reload the user
        self::me(true);
        (new \Movim\Bootstrap)->loadLanguage();
    }

    public function session()
    {
        return $this->hasOne('App\Session');
    }

    public function contact()
    {
        return $this->hasOne('App\Contact', 'id');
    }

    public function capability()
    {
        return $this->hasOne('App\Info', 'server', 'id');
    }

    public function messages()
    {
        return $this->hasMany('App\Message');
    }

    public function unreads(string $jid = null, bool $quoted = false, $cached = false)
    {
        if ($this->unreads !== null && $cached) return $this->unreads;

        $unreads = $this->messages()
                        ->where('seen', false)
                        ->where('jidfrom', '!=', $this->id)
                        ->where(function ($query) use ($quoted) {
                            $query->where('type', 'chat')
                                ->orWhere(function ($query) use ($quoted) {
                                    $query->where('type', 'groupchat')
                                          ->whereNull('subject');

                                    if ($quoted) {
                                        $query->where('quoted', true);
                                    }
                                });
                        });

        if ($jid) {
            $unreads = $unreads->where('jidfrom', $jid);
        }

        $this->unreads = $unreads->count();

        return $this->unreads;
    }

    public function encryptedPasswords()
    {<commit_msg>Global chat counter count the number of chats and not messages anymore<commit_after><?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Movim\Session;
use App\Contact;
use App\Configuration;

class User extends Model
{
    protected $fillable = ['id', 'language', 'nightmode', 'chatmain', 'nsfw', 'nickname', 'notificationchat', 'notificationcall'];
    public $with = ['session', 'capability'];
    protected $keyType = 'string';
    public $incrementing = false;
    private static $me = null;
    private $unreads = null;

    public function save(array $options = [])
    {
        parent::save($options);

        // Reload the user
        self::me(true);
        (new \Movim\Bootstrap)->loadLanguage();
    }

    public function session()
    {
        return $this->hasOne('App\Session');
    }

    public function contact()
    {
        return $this->hasOne('App\Contact', 'id');
    }

    public function capability()
    {
        return $this->hasOne('App\Info', 'server', 'id');
    }

    public function messages()
    {
        return $this->hasMany('App\Message');
    }

    public function unreads(string $jid = null, bool $quoted = false, $cached = false)
    {
        if ($this->unreads !== null && $cached) return $this->unreads;

        $unreads = $this->messages()
                        ->where('seen', false)
                        ->where('jidfrom', '!=', $this->id)
                        ->where(function ($query) use ($quoted) {
                            $query->where('type', 'chat')
                                ->orWhere(function ($query) use ($quoted) {
                                    $query->where('type', 'groupchat')
                                          ->whereNull('subject');

                                    if ($quoted) {
                                        $query->where('quoted', true);
                                    }
                                });
                        });

        if ($jid) {
            $unreads = $unreads->where('jidfrom', $jid);
        } else {
            $unreads = $unreads->distinct('jidfrom');
        }

        $this->unreads = $unreads->count();

        return $this->unreads;
    }

    public function encryptedPasswords()
    {
{'fraction_non_alphanumeric': 0.14655172413793102, 'fraction_numerical': 0.0, 'mean_word_length': 1.6166172106824925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1717145', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1158, 'n_words': 268}