Skip to content

Commit

Permalink
fix(#2): added exclusion for the draft folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars- committed Apr 18, 2024
1 parent c50df9d commit 3716bbc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Providers/InternalConversationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public function hooks() {
$rawSqlBuilder .= " OR JSON_CONTAINS(meta, '\"$teamId\"', '$.\"internal_conversations.users\"')";
}

if ( $folder->type == Folder::TYPE_MINE ) {
if ( $folder->type == Folder::TYPE_DRAFTS ) {
$rawSqlBuilder .= ' OR (`conversations`.created_by_user_id = ' . $user_id . ' AND `conversations`.state = ' . Conversation::STATE_DRAFT . ')';
}


if ( $folder->type == Folder::TYPE_MINE ) {
$query_conversations = Conversation::where( 'user_id', $user_id )
->where( 'mailbox_id', $folder->mailbox_id )
->whereIn( 'status', [ Conversation::STATUS_ACTIVE, Conversation::STATUS_PENDING ] )
Expand Down Expand Up @@ -194,7 +199,7 @@ public function hooks() {
$allowedConversations = $query_conversations->where( 'type', $customType )->whereRaw( $rawSqlBuilder )->pluck( 'id' )->toArray();

if ( count( $allowedConversations ) > 0 ) {
$query->whereRaw( "(type != $customType OR id IN (" . implode( ',', $allowedConversations ) . "))" );
$query->whereRaw( "(`conversations`.type != $customType OR `conversations`.id IN (" . implode( ',', $allowedConversations ) . "))" );
} else {
$query->where( 'type', '!=', $customType );
}
Expand All @@ -215,7 +220,13 @@ public function hooks() {
$teamIds = $teamsForUser->pluck( 'id' )->toArray();
}


$connectedUsers = $conversation->getMeta( 'internal_conversations.users', [] );

if ( $conversation->state === Conversation::STATE_DRAFT ) {
$connectedUsers[] = $conversation->created_by_user_id;
}

if ( ! in_array( $user_id, $connectedUsers ) ) {
$teamIsConnected = false;

Expand Down

0 comments on commit 3716bbc

Please sign in to comment.