Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 20, 2017
1 parent 3117a55 commit bacf34c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Comments\IComment;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserManager;

class ChatController extends OCSController {
Expand Down Expand Up @@ -137,7 +139,7 @@ public function sendMessage($token, $message) {
// fits (except if there is no session, as the actorId should be
// empty in that case but sha1('') would generate a hash too
// instead of returning an empty string).
$actorId = $actorId? sha1($actorId): $actorId;
$actorId = $actorId ? sha1($actorId) : $actorId;
} else {
$actorType = 'users';
$actorId = $this->userId;
Expand All @@ -149,7 +151,7 @@ public function sendMessage($token, $message) {

$creationDateTime = new \DateTime('now', new \DateTimeZone('UTC'));

$this->chatManager->sendMessage(strval($room->getId()), $actorType, $actorId, $message, $creationDateTime);
$this->chatManager->sendMessage((string) $room->getId(), $actorType, $actorId, $message, $creationDateTime);

return new DataResponse([], Http::STATUS_CREATED);
}
Expand All @@ -175,10 +177,10 @@ public function sendMessage($token, $message) {
* sent.
*
* @param string $token the room token
* @param int offset optional, the first N messages to ignore
* @param int notOlderThanTimestamp optional, timestamp in seconds and UTC
* @param int $offset optional, the first N messages to ignore
* @param int $notOlderThanTimestamp optional, timestamp in seconds and UTC
* time zone
* @param int timeout optional, the number of seconds to wait for new
* @param int $timeout optional, the number of seconds to wait for new
* messages (30 by default, 60 at most)
* @return DataResponse an array of chat messages, or "404 Not found" if the
* room token was not valid; each chat message is an array with
Expand All @@ -196,23 +198,21 @@ public function receiveMessages($token, $offset = 0, $notOlderThanTimestamp = 0,
if ($notOlderThanTimestamp > 0) {
$notOlderThan = new \DateTime();
$notOlderThan->setTimestamp($notOlderThanTimestamp);
$notOlderThan->setTimeZone(new \DateTimeZone('UTC'));
$notOlderThan->setTimezone(new \DateTimeZone('UTC'));
}

$maximumTimeout = 60;
if ($timeout > $maximumTimeout) {
$timeout = $maximumTimeout;
}

$comments = $this->chatManager->receiveMessages(strval($room->getId()), $timeout, $offset, $notOlderThan);
$comments = $this->chatManager->receiveMessages((string) $room->getId(), $timeout, $offset, $notOlderThan);

$userManager = $this->userManager;

return new DataResponse(array_map(function($comment) use ($token, $userManager) {
return new DataResponse(array_map(function(IComment $comment) use ($token) {
$displayName = null;
if ($comment->getActorType() === 'users') {
$user = $userManager->get($comment->getActorId());
$displayName = is_null($user) ? null : $user->getDisplayName();
$user = $this->userManager->get($comment->getActorId());
$displayName = $user instanceof IUser ? $user->getDisplayName() : null;
}

return [
Expand Down

0 comments on commit bacf34c

Please sign in to comment.