Skip to content

Commit

Permalink
refactor: Tighten ActorType fields and methods
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Mar 1, 2024
1 parent 90e5c0b commit 616b3a1
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 80 deletions.
1 change: 1 addition & 0 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function __construct(
/**
* Sends a new message to the given chat.
*
* @psalm-param Attendee::ACTOR_* $actorType
* @param bool $shouldSkipLastMessageUpdate If multiple messages will be posted
* (e.g. when adding multiple users to a room) we can skip the last
* message and last activity update until the last entry was created
Expand Down
4 changes: 3 additions & 1 deletion lib/Chat/CommentsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OC\Comments\Comment;
use OC\Comments\Manager;
use OCA\Talk\Model\Attendee;
use OCP\Comments\IComment;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function getCommentsById(array $ids): array {
}

/**
* @param string $actorType
* @psalm-param Attendee::ACTOR_* $actorType
* @param string $actorId
* @param string[] $messageIds
* @return array
Expand Down Expand Up @@ -100,6 +101,7 @@ public function retrieveReactionsByActor(string $actorType, string $actorId, arr
* @param string $objectType Limit the search by object type
* @param string[] $objectIds Limit the search by object ids
* @param string $verb Limit the verb of the comment
* @psalm-param ?Attendee::ACTOR_* $actorType
* @return list<IComment>
*/
public function searchForObjectsWithFilters(string $search, string $objectType, array $objectIds, string $verb, ?\DateTimeImmutable $since, ?\DateTimeImmutable $until, ?string $actorType, ?string $actorId, int $offset, int $limit = 50): array {
Expand Down
3 changes: 3 additions & 0 deletions lib/Chat/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ protected function setLastEditInfo(Message $message): void {
}
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
protected function getActorInformation(Message $message, string $actorType, string $actorId, string $displayName = ''): array {
if ($actorType === Attendee::ACTOR_USERS) {
$tempDisplayName = $this->userManager->getDisplayName($actorId);
Expand Down
3 changes: 3 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ protected function getActorFromComment(Room $room, IComment $comment): array {
return $this->getActor($room, $comment->getActorType(), $comment->getActorId());
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
protected function getActor(Room $room, string $actorType, string $actorId): array {
if ($actorType === Attendee::ACTOR_GUESTS || $actorType === Attendee::ACTOR_EMAILS) {
return $this->getGuest($room, $actorType, $actorId);
Expand Down
9 changes: 6 additions & 3 deletions lib/Chat/ReactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\Talk\Exceptions\ReactionAlreadyExistsException;
use OCA\Talk\Exceptions\ReactionNotSupportedException;
use OCA\Talk\Exceptions\ReactionOutOfContextException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\ResponseDefinitions;
use OCA\Talk\Room;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function __construct(
* Add reaction
*
* @param Room $chat
* @param string $actorType
* @psalm-param Attendee::ACTOR_* $actorType
* @param string $actorId
* @param integer $messageId
* @param string $reaction
Expand Down Expand Up @@ -99,7 +100,7 @@ public function addReactionMessage(Room $chat, string $actorType, string $actorI
* Delete reaction
*
* @param Room $chat
* @param string $actorType
* @psalm-param Attendee::ACTOR_* $actorType
* @param string $actorId
* @param integer $messageId
* @param string $reaction
Expand Down Expand Up @@ -159,8 +160,10 @@ public function retrieveReactionMessages(Room $chat, Participant $participant, i
$message = $this->messageParser->createMessage($chat, $participant, $comment, $this->l);
$this->messageParser->parseMessage($message);

/** @var Attendee::ACTOR_* $actorType */
$actorType = $comment->getActorType();
$reactions[$comment->getMessage()][] = [
'actorType' => $comment->getActorType(),
'actorType' => $actorType,
'actorId' => $comment->getActorId(),
'actorDisplayName' => $message->getActorDisplayName(),
'timestamp' => $comment->getCreationDateTime()->getTimestamp(),
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/DisplayNameListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function handle(Event $event): void {
}
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
protected function updateCachedName(string $actorType, string $actorId, string $newName): void {
$this->participantService->updateDisplayNameForActor(
$actorType,
Expand Down
2 changes: 1 addition & 1 deletion lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function getRoomsForUser(string $userId, array $sessionIds = [], bool $in
}

/**
* @param string $actorType
* @psalm-param Attendee::ACTOR_* $actorType
* @param string $actorId
* @param array $sessionIds A list of talk sessions to consider for loading (otherwise no session is loaded)
* @param bool $includeLastMessage
Expand Down
21 changes: 18 additions & 3 deletions lib/Model/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* @method int getMessageTime()
* @method void setObjectType(string $objectType)
* @method string getObjectType()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
*/
Expand All @@ -62,7 +60,10 @@ class Attachment extends Entity {
/** @var string */
protected $objectType;

/** @var string */
/**
* @var string
* @psalm-var Attendee::ACTOR_*
*/
protected $actorType;

/** @var string */
Expand All @@ -77,6 +78,20 @@ public function __construct() {
$this->addType('actorId', 'string');
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function setActorType(string $actorType): void {
$this->actorType = $actorType;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}

/**
* @return array
*/
Expand Down
21 changes: 18 additions & 3 deletions lib/Model/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
/**
* @method void setRoomId(int $roomId)
* @method int getRoomId()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @method void setDisplayName(string $displayName)
Expand Down Expand Up @@ -111,7 +109,10 @@ class Attendee extends Entity {
/** @var int */
protected $roomId;

/** @var string */
/**
* @var string
* @psalm-var Attendee::ACTOR_*
*/
protected $actorType;

/** @var string */
Expand Down Expand Up @@ -191,6 +192,20 @@ public function __construct() {
$this->addType('callId', 'string');
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function setActorType(string $actorType): void {
$this->actorType = $actorType;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}

public function getDisplayName(): string {
return (string) $this->displayName;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/AttendeeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(IDBConnection $db) {

/**
* @param int $roomId
* @param string $actorType
* @psalm-param Attendee::ACTOR_* $actorType
* @param string $actorId
* @return Attendee
* @throws DoesNotExistException
Expand Down
21 changes: 18 additions & 3 deletions lib/Model/Consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
/**
* @method void setToken(string $token)
* @method string getToken()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @method void setDateTime(\DateTime $dateTime)
* @method \DateTime getDateTime()
*/
class Consent extends Entity implements \JsonSerializable {
protected string $token = '';
protected string $actorType = '';
/**
* @psalm-var Attendee::ACTOR_*
*/
protected string $actorType;
protected string $actorId = '';
protected ?\DateTime $dateTime = null;

Expand All @@ -50,6 +51,20 @@ public function __construct() {
$this->addType('dateTime', 'datetime');
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function setActorType(string $actorType): void {
$this->actorType = $actorType;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}

public function jsonSerialize(): array {
return [
'token' => $this->getToken(),
Expand Down
5 changes: 5 additions & 0 deletions lib/Model/ConsentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function deleteByToken(string $token): int {
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
* @return Consent[]
*/
public function findForActor(string $actorType, string $actorId): array {
Expand All @@ -75,6 +76,9 @@ public function findForActor(string $actorType, string $actorId): array {
return $this->findEntities($query);
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function deleteByActor(string $actorType, string $actorId): int {
$query = $this->db->getQueryBuilder();
$query->delete($this->getTableName())
Expand All @@ -85,6 +89,7 @@ public function deleteByActor(string $actorType, string $actorId): int {
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
* @return Consent[]
*/
public function findForTokenByActor(string $token, string $actorType, string $actorId): array {
Expand Down
13 changes: 11 additions & 2 deletions lib/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ class Message {
/** @var array */
protected $parameters = [];

/** @var string */
protected $actorType = '';
/**
* @var string
* @psalm-var Attendee::ACTOR_*
*/
protected $actorType;

/** @var string */
protected $actorId = '';
Expand Down Expand Up @@ -148,6 +151,9 @@ public function getMessageType(): string {
return $this->type;
}

/**
* @psalm-param Attendee::ACTOR_* $type
*/
public function setActor(string $type, string $id, string $displayName): void {
$this->actorType = $type;
$this->actorId = $id;
Expand All @@ -161,6 +167,9 @@ public function setLastEdit(string $type, string $id, string $displayName, int $
$this->lastEditTimestamp = $timestamp;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}
Expand Down
21 changes: 18 additions & 3 deletions lib/Model/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
* @method string getVotes()
* @method void setNumVoters(int $numVoters)
* @method int getNumVoters()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @method void setDisplayName(string $displayName)
Expand All @@ -67,7 +65,10 @@ class Poll extends Entity {
protected string $options = '';
protected string $votes = '';
protected int $numVoters = 0;
protected string $actorType = '';
/**
* @psalm-var Attendee::ACTOR_*
*/
protected string $actorType;
protected string $actorId = '';
protected ?string $displayName = null;
protected int $status = self::STATUS_OPEN;
Expand All @@ -88,6 +89,20 @@ public function __construct() {
$this->addType('maxVotes', 'int');
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function setActorType(string $actorType): void {
$this->actorType = $actorType;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}

/**
* @return TalkPoll
*/
Expand Down
21 changes: 18 additions & 3 deletions lib/Model/ProxyCacheMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
* @method string getRemoteToken()
* @method void setRemoteMessageId(int $remoteMessageId)
* @method int getRemoteMessageId()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @method void setActorDisplayName(string $actorDisplayName)
Expand All @@ -62,7 +60,10 @@ class ProxyCacheMessages extends Entity implements \JsonSerializable {
protected string $remoteServerUrl = '';
protected string $remoteToken = '';
protected int $remoteMessageId = 0;
protected string $actorType = '';
/**
* @psalm-var Attendee::ACTOR_*
*/
protected string $actorType;
protected string $actorId = '';
protected ?string $actorDisplayName = null;
/**
Expand Down Expand Up @@ -104,6 +105,20 @@ public function getMessageType(): string {
return $this->messageType;
}

/**
* @psalm-param Attendee::ACTOR_* $actorType
*/
public function setActorType(string $actorType): void {
$this->actorType = $actorType;
}

/**
* @psalm-return Attendee::ACTOR_*
*/
public function getActorType(): string {
return $this->actorType;
}

/**
* @return TalkRoomProxyMessage
*/
Expand Down
Loading

0 comments on commit 616b3a1

Please sign in to comment.