Skip to content

Commit 7bd3191

Browse files
committed
fixed DB::selectChats(), small text update in whoiscommand
1 parent 28bd0f9 commit 7bd3191

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/Commands/AdminCommands/WhoisCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function execute()
143143
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: '.$old_id.')' : ''). "\n";
144144
$text .= 'Type: ' . ucfirst($chat->getType()) . "\n";
145145
$text .= 'Title: ' . $chat->getTitle() . "\n";
146-
$text .= 'Bot added to group: ' . $created_at . "\n";
146+
$text .= 'First time added to group: ' . $created_at . "\n";
147147
$text .= 'Last activity: ' . $updated_at . "\n";
148148
}
149149
} elseif (is_array($results) && count($results) > 1) {

src/DB.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,6 @@ public static function insertMessageRequest(Message &$message)
691691
/**
692692
* Select Group and single Chats
693693
*
694-
* @todo Seems to not return anything when $select_users = false
695-
*
696694
* @param bool $select_groups
697695
* @param bool $select_super_groups
698696
* @param bool $select_users
@@ -722,26 +720,39 @@ public static function selectChats(
722720
$query = 'SELECT * ,
723721
' . TB_CHAT . '.`id` AS `chat_id`,
724722
' . TB_CHAT . '.`created_at` AS `chat_created_at`,
725-
' . TB_CHAT . '.`updated_at` AS `chat_updated_at`,
726-
' . TB_USER . '.`id` AS `user_id`
727-
FROM `' . TB_CHAT . '` LEFT JOIN `' . TB_USER . '`
728-
ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`';
723+
' . TB_CHAT . '.`updated_at` AS `chat_updated_at`
724+
' .
725+
(($select_users) ? ', ' . TB_USER . '.`id` AS `user_id` FROM `' . TB_CHAT . '` LEFT JOIN `' . TB_USER . '`
726+
ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`' : 'FROM `' . TB_CHAT . '`');
729727

730728
//Building parts of query
731-
$chat_or_user = '';
732729
$where = [];
733730
$tokens = [];
734731

735732
if (!$select_groups || !$select_users || !$select_super_groups) {
733+
$chat_or_user = '';
734+
736735
if ($select_groups) {
737-
$where[] = TB_CHAT . '.`type` = "group"';
736+
$chat_or_user .= TB_CHAT . '.`type` = "group"';
738737
}
738+
739739
if ($select_super_groups) {
740-
$where[] = TB_CHAT . '.`type` = "supergroup"';
740+
if (!empty($chat_or_user)) {
741+
$chat_or_user .= ' OR ';
742+
}
743+
744+
$chat_or_user .= TB_CHAT . '.`type` = "supergroup"';
741745
}
746+
742747
if ($select_users) {
743-
$where[] = TB_CHAT . '.`type` = "private"';
748+
if (!empty($chat_or_user)) {
749+
$chat_or_user .= ' OR ';
750+
}
751+
752+
$chat_or_user .= TB_CHAT . '.`type` = "private"';
744753
}
754+
755+
$where[] = '(' . $chat_or_user . ')';
745756
}
746757

747758
if (! is_null($date_from)) {
@@ -760,7 +771,12 @@ public static function selectChats(
760771
}
761772

762773
if (! is_null($text)) {
763-
$where[] = '(LOWER('.TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)';
774+
if ($select_users) {
775+
$where[] = '(LOWER('.TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)';
776+
} else {
777+
$where[] = 'LOWER('.TB_CHAT . '.`title`) LIKE :text';
778+
}
779+
764780
$tokens[':text'] = '%'.strtolower($text).'%';
765781
}
766782

@@ -788,3 +804,4 @@ public static function selectChats(
788804
return $result;
789805
}
790806
}
807+

0 commit comments

Comments
 (0)