Skip to content

Commit 29fa726

Browse files
committed
feat(openapi): Add known limitations to some type, int and string fields
Signed-off-by: Joas Schilling <[email protected]>
1 parent ff12362 commit 29fa726

File tree

16 files changed

+235
-198
lines changed

16 files changed

+235
-198
lines changed

lib/Chat/ChatManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function addSystemMessage(
245245
* @return IComment
246246
*/
247247
public function addChangelogMessage(Room $chat, string $message): IComment {
248-
$comment = $this->commentsManager->create(Attendee::ACTOR_GUESTS, Attendee::ACTOR_ID_CHANGELOG, 'chat', (string) $chat->getId());
248+
$comment = $this->commentsManager->create(Attendee::ACTOR_GUESTS, Attendee::CHANGELOG_ACTOR_ID, 'chat', (string) $chat->getId());
249249

250250
$comment->setMessage($message, self::MAX_CHAT_LENGTH);
251251
$comment->setCreationDateTime($this->timeFactory->getDateTime());
@@ -345,8 +345,8 @@ public function sendMessage(
345345

346346
// Update last_message
347347
if ($comment->getActorType() !== Attendee::ACTOR_BOTS
348-
|| $comment->getActorId() === Attendee::ACTOR_ID_CHANGELOG
349-
|| str_starts_with($comment->getActorId(), Attendee::ACTOR_BOT_PREFIX)) {
348+
|| $comment->getActorId() === Attendee::CHANGELOG_ACTOR_ID
349+
|| str_starts_with($comment->getActorId(), Attendee::BOT_ACTOR_PREFIX)) {
350350
$this->roomService->setLastMessage($chat, $comment);
351351
$this->unreadCountCache->clear($chat->getId() . '-');
352352
} else {

lib/Chat/MessageParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function getActorInformation(Message $message, string $actorType, stri
137137
$displayName = $actorId;
138138
$actorId = MatterbridgeManager::BRIDGE_BOT_USERID;
139139
} elseif ($actorType === Attendee::ACTOR_GUESTS
140-
&& !in_array($actorId, [Attendee::ACTOR_ID_CLI, Attendee::ACTOR_ID_CHANGELOG], true)) {
140+
&& !in_array($actorId, [Attendee::CLI_ACTOR_ID, Attendee::CHANGELOG_ACTOR_ID], true)) {
141141
if (isset($guestNames[$actorId])) {
142142
$displayName = $this->guestNames[$actorId];
143143
} else {
@@ -151,8 +151,8 @@ protected function getActorInformation(Message $message, string $actorType, stri
151151
} elseif ($actorType === Attendee::ACTOR_BOTS) {
152152
$displayName = $actorId . '-bot';
153153
$token = $message->getRoom()->getToken();
154-
if (str_starts_with($actorId, Attendee::ACTOR_BOT_PREFIX)) {
155-
$urlHash = substr($actorId, strlen(Attendee::ACTOR_BOT_PREFIX));
154+
if (str_starts_with($actorId, Attendee::BOT_ACTOR_PREFIX)) {
155+
$urlHash = substr($actorId, strlen(Attendee::BOT_ACTOR_PREFIX));
156156
$botName = $this->getBotNameByUrlHashForConversation($token, $urlHash);
157157
if ($botName) {
158158
$displayName = $botName . ' (Bot)';

lib/Chat/Parser/Changelog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public function handle(Event $event): void {
2929
}
3030

3131
if ($chatMessage->getActorType() !== Attendee::ACTOR_GUESTS ||
32-
$chatMessage->getActorId() !== Attendee::ACTOR_ID_CHANGELOG) {
32+
$chatMessage->getActorId() !== Attendee::CHANGELOG_ACTOR_ID) {
3333
return;
3434
}
3535

3636
$l = $chatMessage->getL10n();
37-
$chatMessage->setActor(Attendee::ACTOR_BOTS, Attendee::ACTOR_ID_CHANGELOG, $l->t('Talk updates ✅'));
37+
$chatMessage->setActor(Attendee::ACTOR_BOTS, Attendee::CHANGELOG_ACTOR_ID, $l->t('Talk updates ✅'));
3838
$event->stopPropagation();
3939
}
4040
}

lib/Chat/Parser/SystemMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ protected function parseMessage(Message $chatMessage): void {
156156
$participant->getAttendee()->getActorId() === $parsedParameters['actor']['id'];
157157
}
158158
$cliIsActor = $parsedParameters['actor']['type'] === 'guest' &&
159-
'guest/' . Attendee::ACTOR_ID_CLI === $parsedParameters['actor']['id'];
159+
'guest/' . Attendee::CLI_ACTOR_ID === $parsedParameters['actor']['id'];
160160

161161
if ($message === 'conversation_created') {
162162
$systemIsActor = $parsedParameters['actor']['type'] === 'guest' &&
163-
'guest/' . Attendee::ACTOR_ID_SYSTEM === $parsedParameters['actor']['id'];
163+
'guest/' . Attendee::SYSTEM_ACTOR_ID === $parsedParameters['actor']['id'];
164164

165165
$parsedMessage = $this->l->t('{actor} created the conversation');
166166
if ($currentUserIsActor) {
@@ -655,7 +655,7 @@ protected function parseMessage(Message $chatMessage): void {
655655
$parsedMessage = $this->l->t('Someone voted on the poll {poll}');
656656
unset($parsedParameters['actor']);
657657

658-
$chatMessage->setActor(Attendee::ACTOR_GUESTS, Attendee::ACTOR_ID_SYSTEM, '');
658+
$chatMessage->setActor(Attendee::ACTOR_GUESTS, Attendee::SYSTEM_ACTOR_ID, '');
659659
} else {
660660
throw new \OutOfBoundsException('Unknown subject');
661661
}
@@ -1015,7 +1015,7 @@ protected function getGuest(Room $room, string $actorType, string $actorId): arr
10151015
}
10161016

10171017
protected function getGuestName(Room $room, string $actorType, string $actorId): string {
1018-
if ($actorId === Attendee::ACTOR_ID_CLI) {
1018+
if ($actorId === Attendee::CLI_ACTOR_ID) {
10191019
return $this->l->t('Guest');
10201020
}
10211021

lib/Chat/SystemMessage/Listener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,15 @@ protected function sendSystemMessage(Room $room, string $message, array $paramet
428428
$actorId = $participant->getAttendee()->getActorId();
429429
} elseif ($forceSystemAsActor) {
430430
$actorType = Attendee::ACTOR_GUESTS;
431-
$actorId = Attendee::ACTOR_ID_SYSTEM;
431+
$actorId = Attendee::SYSTEM_ACTOR_ID;
432432
} else {
433433
$user = $this->userSession->getUser();
434434
if ($user instanceof IUser) {
435435
$actorType = Attendee::ACTOR_USERS;
436436
$actorId = $user->getUID();
437437
} elseif (\OC::$CLI || $this->session->exists('talk-overwrite-actor-cli')) {
438438
$actorType = Attendee::ACTOR_GUESTS;
439-
$actorId = Attendee::ACTOR_ID_CLI;
439+
$actorId = Attendee::CLI_ACTOR_ID;
440440
} elseif ($this->session->exists('talk-overwrite-actor-type')) {
441441
$actorType = $this->session->get('talk-overwrite-actor-type');
442442
$actorId = $this->session->get('talk-overwrite-actor-id');

lib/Controller/BotController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function sendMessage(string $token, string $message, string $referenceId
150150
$room = $this->manager->getRoomByToken($token);
151151

152152
$actorType = Attendee::ACTOR_BOTS;
153-
$actorId = Attendee::ACTOR_BOT_PREFIX . $bot->getBotServer()->getUrlHash();
153+
$actorId = Attendee::BOT_ACTOR_PREFIX . $bot->getBotServer()->getUrlHash();
154154

155155
$parent = null;
156156
if ($replyTo !== 0) {
@@ -209,7 +209,7 @@ public function react(string $token, int $messageId, string $reaction): DataResp
209209
$room = $this->manager->getRoomByToken($token);
210210

211211
$actorType = Attendee::ACTOR_BOTS;
212-
$actorId = Attendee::ACTOR_BOT_PREFIX . $bot->getBotServer()->getUrlHash();
212+
$actorId = Attendee::BOT_ACTOR_PREFIX . $bot->getBotServer()->getUrlHash();
213213

214214
try {
215215
$this->reactionManager->addReactionMessage(
@@ -262,7 +262,7 @@ public function deleteReaction(string $token, int $messageId, string $reaction):
262262
$room = $this->manager->getRoomByToken($token);
263263

264264
$actorType = Attendee::ACTOR_BOTS;
265-
$actorId = Attendee::ACTOR_BOT_PREFIX . $bot->getBotServer()->getUrlHash();
265+
$actorId = Attendee::BOT_ACTOR_PREFIX . $bot->getBotServer()->getUrlHash();
266266

267267
try {
268268
$this->reactionManager->deleteReactionMessage(

lib/Model/Attendee.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
* @method int getLastAttendeeActivity()
6060
*/
6161
class Attendee extends Entity {
62-
public const ACTOR_USERS = 'users';
62+
public const ACTOR_USERS = 'users';lib/Chat/SystemMessage/Listener.php
63+
6364
public const ACTOR_GROUPS = 'groups';
6465
public const ACTOR_GUESTS = 'guests';
6566
public const ACTOR_EMAILS = 'emails';
@@ -70,10 +71,10 @@ class Attendee extends Entity {
7071
public const ACTOR_PHONES = 'phones';
7172

7273
// Special actor IDs
73-
public const ACTOR_BOT_PREFIX = 'bot-';
74-
public const ACTOR_ID_CLI = 'cli';
75-
public const ACTOR_ID_SYSTEM = 'system';
76-
public const ACTOR_ID_CHANGELOG = 'changelog';
74+
public const BOT_ACTOR_PREFIX = 'bot-';
75+
public const CLI_ACTOR_ID = 'cli';
76+
public const SYSTEM_ACTOR_ID = 'system';
77+
public const CHANGELOG_ACTOR_ID = 'changelog';
7778

7879
public const PERMISSIONS_DEFAULT = 0;
7980
public const PERMISSIONS_CUSTOM = 1;

lib/Model/BotServer.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,34 @@
1212
use OCP\AppFramework\Db\Entity;
1313

1414
/**
15+
* @psalm-method int<1, max> getId()
1516
* @method void setName(string $name)
1617
* @method string getName()
18+
* @psalm-method non-empty-string getName()
1719
* @method void setUrl(string $url)
1820
* @method string getUrl()
21+
* @psalm-method non-empty-string getUrl()
1922
* @method void setUrlHash(string $urlHash)
2023
* @method string getUrlHash()
24+
* @psalm-method non-empty-string getUrlHash()
2125
* @method void setDescription(?string $description)
2226
* @method null|string getDescription()
2327
* @method void setSecret(string $secret)
2428
* @method string getSecret()
29+
* @psalm-method non-empty-string getSecret()
2530
* @method void setErrorCount(int $errorCount)
2631
* @method int getErrorCount()
32+
* @psalm-method int<0, max> getErrorCount()
2733
* @method void setLastErrorDate(?\DateTimeImmutable $lastErrorDate)
28-
* @method ?\DateTimeImmutable getLastErrorDate()
34+
* @method null|\DateTimeImmutable getLastErrorDate()
2935
* @method void setLastErrorMessage(string $lastErrorMessage)
3036
* @method string getLastErrorMessage()
3137
* @method void setState(int $state)
3238
* @method int getState()
39+
* @psalm-method Bot::STATE_* getState()
3340
* @method void setFeatures(int $features)
3441
* @method int getFeatures()
42+
* @psalm-method int-mask<1, 2> getFeatures()
3543
*
3644
* @psalm-import-type TalkBotWithDetailsAndSecret from ResponseDefinitions
3745
*/
@@ -72,7 +80,7 @@ public function jsonSerialize(): array {
7280
'description' => $this->getDescription(),
7381
'secret' => $this->getSecret(),
7482
'error_count' => $this->getErrorCount(),
75-
'last_error_date' => $this->getLastErrorDate() ? $this->getLastErrorDate()->getTimestamp() : 0,
83+
'last_error_date' => $this->getLastErrorDate() ? max(0, $this->getLastErrorDate()->getTimestamp()) : 0,
7684
'last_error_message' => $this->getLastErrorMessage(),
7785
'state' => $this->getState(),
7886
'features' => $this->getFeatures(),

lib/Model/Poll.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,37 @@
1313
use OCP\AppFramework\Db\Entity;
1414

1515
/**
16+
* @psalm-method int<1, max> getId()
1617
* @method void setRoomId(int $roomId)
1718
* @method int getRoomId()
1819
* @method void setQuestion(string $question)
1920
* @method string getQuestion()
21+
* @psalm-method non-empty-string getQuestion()
2022
* @method void setOptions(string $options)
2123
* @method string getOptions()
2224
* @method void setVotes(string $votes)
2325
* @method string getVotes()
2426
* @method void setNumVoters(int $numVoters)
2527
* @method int getNumVoters()
28+
* @psalm-method int<0, max> getNumVoters()
2629
* @method void setActorType(string $actorType)
2730
* @method string getActorType()
31+
* @psalm-method Attendee::ACTOR_* getActorType()
2832
* @method void setActorId(string $actorId)
2933
* @method string getActorId()
34+
* @psalm-method non-empty-string getActorId()
3035
* @method void setDisplayName(string $displayName)
3136
* @method string getDisplayName()
37+
* @psalm-method non-empty-string getDisplayName()
3238
* @method void setStatus(int $status)
3339
* @method int getStatus()
40+
* @psalm-method self::STATUS_* getStatus()
3441
* @method void setResultMode(int $resultMode)
3542
* @method int getResultMode()
43+
* @psalm-method self::MODE_* getResultMode()
3644
* @method void setMaxVotes(int $maxVotes)
3745
* @method int getMaxVotes()
46+
* @psalm-method int<0, max> getMaxVotes()
3847
*
3948
* @psalm-import-type TalkPoll from ResponseDefinitions
4049
*/
@@ -80,6 +89,7 @@ public function asArray(): array {
8089
// Because PHP is turning arrays with sequent numeric keys "{"0":x,"1":y,"2":z}" into "[x,y,z]"
8190
// when json_encode() is used we have to prefix the keys with a string,
8291
// to prevent breaking in the mobile apps.
92+
/** @var array<string, int<0, max>> $prefixedVotes */
8393
$prefixedVotes = [];
8494
foreach ($votes as $option => $count) {
8595
$prefixedVotes['option-' . $option] = $count;

lib/Model/Reminder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
/**
1515
* @method void setUserId(string $userId)
1616
* @method string getUserId()
17+
* @psalm-method non-empty-string getUserId()
1718
* @method void setToken(string $token)
1819
* @method string getToken()
20+
* @psalm-method non-empty-string getToken()
1921
* @method void setMessageId(int $messageId)
2022
* @method int getMessageId()
23+
* @psalm-method int<1, max> getMessageId()
2124
* @method void setDateTime(\DateTime $dateTime)
2225
* @method \DateTime getDateTime()
2326
*
@@ -44,7 +47,7 @@ public function jsonSerialize(): array {
4447
'userId' => $this->getUserId(),
4548
'token' => $this->getToken(),
4649
'messageId' => $this->getMessageId(),
47-
'timestamp' => $this->getDateTime()->getTimestamp(),
50+
'timestamp' => max(0, $this->getDateTime()->getTimestamp()),
4851
];
4952
}
5053
}

0 commit comments

Comments
 (0)