src/Repositories/Character/Mail.php
public function getCharacterMailTimeline(int $message_id = null)
    {

        // Get the User for permissions and affiliation
        // checks
        $user = auth()->user();
        $messages = MailHeader::with('recipients', 'body');

        // If a user is not a super user, only return their own mail and those
        // which they are affiliated to to receive.
        if (! $user->hasSuperUser()) {

            $messages = $messages->where(function ($query) use ($user) {

                // If the user has any affiliations and can
                // list those characters, add them
                if ($user->has('character.mail', false))
                    $query = $query->whereIn('character_id', array_keys($user->getAffiliationMap()['char']));

                // Add mail owned by *this* character
                $query->orWhere('character_id', $user->id);
            });
        }

        // Filter by messageID if its set
        if (! is_null($message_id))
            return $messages->where('mail_id', $message_id)
                ->first();

        return $messages->orderBy('timestamp', 'desc')
            ->groupBy('mail_id')
            ->paginate(25);
    }
public function getCharacterMailTimeline(int $message_id = null)
    {

        // Get the User for permissions and affiliation
        // checks
        $user = auth()->user();
        $messages = MailHeader::with('recipients', 'body');

        // If a user is not a super user, only return their own mail and those
        // which they are affiliated to to receive.
        if (! $user->hasSuperUser()) {

            $messages = $messages->where(function ($query) use ($user) {

                // If the user has any affiliations and can
                // list those characters, add them
                if ($user->has('character.mail', false))
                    $query = $query->whereIn('character_id', array_keys($user->getAffiliationMap()['char']));

                // Add mail owned by *this* character
                $query->orWhere('character_id', $user->id);
            });
        }

        // Filter by messageID if its set
        if (! is_null($message_id))
            return $messages->where('mail_id', $message_id)
                ->first();

        return $messages->orderBy('timestamp', 'desc')
            ->groupBy('mail_id')
            ->paginate(25);
    }
public function getCharacterMailTimeline ( int $ message_id = null ) { // Get the User for permissions and affiliation // checks $ user = auth ( ) -> user ( ) ; $ messages = MailHeader :: with ( 'recipients' , 'body' ) ; // If a user is not a super user, only return their own mail and those // which they are affiliated to to receive. if ( ! $ user -> hasSuperUser ( ) ) { $ messages = $ messages -> where ( function ( $ query ) use ( $ user ) { // If the user has any affiliations and can // list those characters, add them if ( $ user -> has ( 'character.mail' , false ) ) $ query = $ query -> whereIn ( 'character_id' , array_keys ( $ user -> getAffiliationMap ( ) [ 'char' ] ) ) ; // Add mail owned by *this* character $ query -> orWhere ( 'character_id' , $ user -> id ) ; } ) ; } // Filter by messageID if its set if ( ! is_null ( $ message_id ) ) return $ messages -> where ( 'mail_id' , $ message_id ) -> first ( ) ; return $ messages -> orderBy ( 'timestamp' , 'desc' ) -> groupBy ( 'mail_id' ) -> paginate ( 25 ) ; }
Get the mail timeline for all of the characters
a logged in user has access to. Either by owning the
api key with the characters, or having the correct
affiliation & role.

Supplying the $message_id will return only that
mail.

@param int $message_id

@return mixed
Get the mail timeline for all of the characters a logged in user has access to . Either by owning the api key with the characters or having the correct affiliation & role .