Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten MessageType and ActorType usage #11696

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class ChatManager {
public const VERB_MESSAGE_DELETED = 'comment_deleted';
public const VERB_REACTION = 'reaction';
public const VERB_REACTION_DELETED = 'reaction_deleted';
public const VERB_VOICE_MESSAGE = 'voice-message';
public const VERB_RECORD_AUDIO = 'record-audio';
public const VERB_RECORD_VIDEO = 'record-video';

protected ICache $cache;
protected ICache $unreadCountCache;
Expand Down Expand Up @@ -113,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
9 changes: 6 additions & 3 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ protected function parseMessage(Message $chatMessage): void {
$metaData = $parameters['metaData'] ?? [];
if (isset($metaData['messageType'])) {
if ($metaData['messageType'] === 'voice-message') {
$chatMessage->setMessageType('voice-message');
$chatMessage->setMessageType(ChatManager::VERB_VOICE_MESSAGE);
} elseif ($metaData['messageType'] === 'record-audio') {
$chatMessage->setMessageType('record-audio');
$chatMessage->setMessageType(ChatManager::VERB_RECORD_AUDIO);
} elseif ($metaData['messageType'] === 'record-video') {
$chatMessage->setMessageType('record-video');
$chatMessage->setMessageType(ChatManager::VERB_RECORD_VIDEO);
} else {
$chatMessage->setMessageType(ChatManager::VERB_MESSAGE);
}
Expand Down 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
26 changes: 22 additions & 4 deletions lib/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class Message {
/** @var bool */
protected $visible = true;

/** @var string */
protected $type = '';
/**
* @var string
* @psalm-var ChatManager::VERB_*
*/
protected $type;

/** @var string */
protected $message = '';
Expand All @@ -52,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 @@ -131,14 +137,23 @@ public function getMessageRaw(): string {
return $this->rawMessage;
}

/**
* @psalm-param ChatManager::VERB_* $type
*/
public function setMessageType(string $type): void {
$this->type = $type;
}

/**
* @return ChatManager::VERB_* $type
*/
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 @@ -152,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
Loading
Loading