Skip to content

Commit

Permalink
add new method getInboxAll
Browse files Browse the repository at this point in the history
  • Loading branch information
Nahid Bin Azhar committed Jul 26, 2016
1 parent a0458d7 commit 06e34f9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Version :1.1.4
=============================
1. Fixed facades issue
2. Improve inbox for sender and reciever wise soft delete
3. Improve conversations data
3. Improve conversations data
4. Add a new method for talk 'getInboxAll'. Its return all messages with soft deleted message
36 changes: 36 additions & 0 deletions src/Conversations/ConversationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ public function getList($user, $offset, $take)
);


return $conversations;
}



public function getListAll($user, $offset, $take)
{
$conversations = DB::select(
DB::raw("SELECT " . $this->getUserColumns() . "msg.user_id as sender_id, conv.id as conv_id, msg.message, msg.created_at, msg.is_seen
FROM " . DB::getTablePrefix() . config('talk.user.table') . " user, " . DB::getTablePrefix() . "conversations conv, " . DB::getTablePrefix() . "messages msg
WHERE conv.id = msg.conversation_id
AND (
conv.user_one ={$user}
OR conv.user_two ={$user}
) and (msg.created_at)
in (
SELECT max(msg.created_at) as created_at
FROM " . DB::getTablePrefix() . "conversations conv, " . DB::getTablePrefix() . "messages msg
WHERE CASE
WHEN conv.user_one ={$user}
THEN conv.user_two = user.id
WHEN conv.user_two ={$user}
THEN conv.user_one = user.id
END
AND conv.id = msg.conversation_id
AND (
conv.user_one ={$user}
OR conv.user_two ={$user}
)
GROUP BY conv.id
)
ORDER BY msg.created_at DESC
LIMIT " . $offset . ", " . $take)
);


return $conversations;
}
}
12 changes: 12 additions & 0 deletions src/Talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ public function getInbox($offset = 0, $take = 20)
return $this->conversation->getList($this->authUserId, $offset, $take);
}

/**
* fetch all inbox with soft deleted message for currently loggedin user with pagination
*
* @param int $offset
* @param int $take
* @return array
*/
public function getInboxAll($offset = 0, $take = 20)
{
return $this->conversation->getListAll($this->authUserId, $offset, $take);
}


/**
* fetch all conversation by using coversation id
Expand Down

0 comments on commit 06e34f9

Please sign in to comment.