fix intro.cid and intro.suggest-id

This commit is contained in:
Philipp 2021-10-19 23:11:47 +02:00
parent b4572a5293
commit 44627a0b12
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
5 changed files with 32 additions and 24 deletions

View File

@ -147,12 +147,20 @@ class Introduction extends BaseDepository
}
}
public function existsForContact(int $cid, int $uid): bool
/**
* Checks, if the suggested contact already exists for the user
*
* @param int $sid
* @param int $uid
*
* @return bool
*/
public function suggestionExistsForUser(int $sid, int $uid): bool
{
try {
return $this->exists(['uid' => $uid, 'suggest-cid' => $cid]);
return $this->exists(['uid' => $uid, 'suggest-cid' => $sid]);
} catch (\Exception $e) {
throw new IntroductionPersistenceException(sprintf('Cannot check Introductions for contact %d and user %d', $cid, $uid), $e);
throw new IntroductionPersistenceException(sprintf('Cannot check suggested Introduction for contact %d and user %d', $sid, $uid), $e);
}
}

View File

@ -25,8 +25,8 @@ use Friendica\BaseEntity;
/**
* @property-read int $uid
* @property-read int $sid
* @property-read int|null $cid
* @property-read int $cid
* @property-read int|null $sid
* @property-read bool $knowyou
* @property-read bool $duplex
* @property-read string $note
@ -40,9 +40,9 @@ class Introduction extends BaseEntity
/** @var int */
protected $uid;
/** @var int */
protected $sid;
/** @var int|null */
protected $cid;
/** @var int|null */
protected $sid;
/** @var bool */
protected $knowyou;
/** @var bool */
@ -60,8 +60,8 @@ class Introduction extends BaseEntity
/**
* @param int $uid
* @param int $sid
* @param int|null $cid
* @param int $cid
* @param int|null $sid
* @param bool $knowyou
* @param bool $duplex
* @param string $note
@ -70,11 +70,11 @@ class Introduction extends BaseEntity
* @param bool $ignore
* @param int|null $id
*/
public function __construct(int $uid, int $sid, ?int $cid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
public function __construct(int $uid, int $cid, ?int $sid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
{
$this->uid = $uid;
$this->sid = $sid;
$this->cid = $cid;
$this->sid = $sid;
$this->knowyou = $knowyou;
$this->duplex = $duplex;
$this->note = $note;

View File

@ -36,8 +36,8 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
{
return new Entity\Introduction(
$row['uid'] ?? 0,
$row['suggest-cid'] ?? 0,
$row['contact-id'] ?? null,
$row['contact-id'] ?? 0,
$row['suggest-cid'] ?? null,
!empty($row['knowyou']),
!empty($row['duplex']),
$row['note'] ?? '',
@ -50,9 +50,9 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
public function createNew(
int $uid,
int $sid,
int $cid,
string $note,
int $cid = null,
int $sid = null,
bool $knowyou = false,
bool $duplex = false
): Entity\Introduction {

View File

@ -1352,7 +1352,7 @@ class DFRN
}
// Quit if we already have an introduction for this person
if (DI::intro()->existsForContact($cid, $uid)) {
if (DI::intro()->suggestionExistsForUser($cid, $uid)) {
return false;
}

View File

@ -42,8 +42,8 @@ class IntroductionTest extends TestCase
],
'assertion' => [
'uid' => 0,
'suggest-cid' => 0,
'contact-id' => null,
'contact-id' => 0,
'suggest-cid' => null,
'knowyou' => false,
'duplex' => false,
'note' => '',
@ -58,8 +58,8 @@ class IntroductionTest extends TestCase
{
self::assertEquals($intro->id, $assertion['id'] ?? null);
self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? 0);
self::assertEquals($intro->cid, $assertion['contact-id'] ?? null);
self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
self::assertEquals($intro->note, $assertion['note'] ?? '');
@ -94,11 +94,11 @@ class IntroductionTest extends TestCase
{
$factory = new Introduction(new NullLogger());
$intro = $factory->createNew($input['uid'] ?? 0, $input['sid'] ?? 0, $input['note'] ?? '');
$intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
$this->assertIntro($intro, [
'uid' => $input['uid'] ?? 0,
'sid' => $input['sid'] ?? 0,
'contact-id' => $input['cid'] ?? 0,
'note' => $input['note'] ?? '',
]);
}