Handle rare case where contact doesn't exist in Model\Group::getIdsByContactId

- Address https://github.com/friendica/friendica/issues/11632#issuecomment-1193953621
pull/11770/head
Hypolite Petovan 2022-07-25 09:13:42 -04:00
rodzic a5d679ea95
commit 488f4dcaa4
1 zmienionych plików z 10 dodań i 6 usunięć

Wyświetl plik

@ -138,25 +138,29 @@ class Group
*/
public static function getIdsByContactId(int $cid): array
{
$return = [];
$contact = Contact::getById($cid, ['rel']);
if (!$contact) {
return [];
}
$groupIds = [];
$stmt = DBA::select('group_member', ['gid'], ['contact-id' => $cid]);
while ($group = DBA::fetch($stmt)) {
$return[] = $group['gid'];
$groupIds[] = $group['gid'];
}
DBA::close($stmt);
// Meta-groups
$contact = Contact::getById($cid, ['rel']);
if ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND) {
$return[] = self::FOLLOWERS;
$groupIds[] = self::FOLLOWERS;
}
if ($contact['rel'] == Contact::FRIEND) {
$return[] = self::MUTUALS;
$groupIds[] = self::MUTUALS;
}
return $return;
return $groupIds;
}
/**