• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tattersoftware / codeigniter4-chat / 7559670250

17 Jan 2024 05:41PM UTC coverage: 70.33%. First build
7559670250

Pull #26

github

web-flow
Merge 391387cc6 into a55dbe47f
Pull Request #26: Bump actions/cache from 3 to 4

128 of 182 relevant lines covered (70.33%)

6.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Models/MessageModel.php
1
<?php
2

3
namespace Tatter\Chat\Models;
4

5
use CodeIgniter\Model;
6
use Tatter\Chat\Entities\Message;
7

8
class MessageModel extends Model
9
{
10
    protected $table          = 'chat_messages';
11
    protected $primaryKey     = 'id';
12
    protected $returnType     = Message::class;
13
    protected $useTimestamps  = true;
14
    protected $useSoftDeletes = true;
15
    protected $skipValidation = true;
16
    protected $allowedFields  = ['conversation_id', 'participant_id', 'content'];
17

18
    /**
19
     * Returns all unread Messages for a user.
20
     *
21
     * @param int $userId ID of the user to match
22
     *
23
     * @return Message[]
24
     */
25
    public function findUserUnread(int $userId): array
26
    {
27
        $result = $this->builder()
4✔
28
            ->select('chat_messages.*, chat_participants.updated_at')
4✔
29
            ->join(
4✔
30
                'chat_participants',
4✔
31
                'chat_messages.conversation_id = chat_participants.conversation_id AND user_id = ' . $userId
4✔
32
            )
4✔
33
            ->where('chat_messages.created_at > chat_participants.updated_at')
4✔
34
            ->get()->getCustomResultObject($this->returnType);
4✔
35

36
        return $result ?? [];
4✔
37
    }
38
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc