mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-21 21:30:08 +00:00
Add MessageAction::pushAttachment()
This commit is contained in:
parent
5fce0c092c
commit
8856cfcd8e
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2010-2018 Tim Düsterhus.
|
||||
* Copyright (c) 2010-2020 Tim Düsterhus.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License
|
||||
* included in the LICENSE file.
|
||||
*
|
||||
* Change Date: 2024-10-20
|
||||
* Change Date: 2024-11-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source
|
||||
* License, use of this software will be governed by version 2
|
||||
@ -17,6 +17,7 @@
|
||||
use \chat\data\command\CommandCache;
|
||||
use \chat\data\room\RoomCache;
|
||||
use \wcf\data\object\type\ObjectTypeCache;
|
||||
use \wcf\system\attachment\AttachmentHandler;
|
||||
use \wcf\system\exception\PermissionDeniedException;
|
||||
use \wcf\system\exception\UserInputException;
|
||||
use \wcf\system\user\activity\point\UserActivityPointHandler;
|
||||
@ -304,4 +305,51 @@ public function push() {
|
||||
$processor->validate($this->parameters['parameters'], $room);
|
||||
$processor->execute($this->parameters['parameters'], $room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates parameters and permissions.
|
||||
*/
|
||||
public function validatePushAttachment() {
|
||||
$this->readInteger('roomID');
|
||||
|
||||
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
|
||||
if ($room === null) throw new UserInputException('roomID');
|
||||
if (!$room->canSee($user = null, $reason)) throw $reason;
|
||||
$user = new \chat\data\user\User(WCF::getUser());
|
||||
if (!$user->isInRoom($room)) throw new PermissionDeniedException();
|
||||
|
||||
$this->readString('tmpHash');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a new attachment into the given room.
|
||||
*/
|
||||
public function pushAttachment() {
|
||||
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.attachment');
|
||||
if (!$objectTypeID) throw new \LogicException('Missing object type');
|
||||
|
||||
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
|
||||
if ($room === null) throw new UserInputException('roomID');
|
||||
|
||||
$attachmentHandler = new AttachmentHandler('be.bastelstu.chat.message', 0, $this->parameters['tmpHash'], $room->roomID);
|
||||
$attachments = $attachmentHandler->getAttachmentList();
|
||||
$attachmentIDs = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
$attachmentIDs[] = $attachment->attachmentID;
|
||||
}
|
||||
|
||||
/** @var Message $message */
|
||||
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID
|
||||
, 'userID' => WCF::getUser()->userID
|
||||
, 'username' => WCF::getUser()->username
|
||||
, 'time' => TIME_NOW
|
||||
, 'objectTypeID' => $objectTypeID
|
||||
, 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs ])
|
||||
]
|
||||
]
|
||||
)
|
||||
)->executeAction()['returnValues'];
|
||||
|
||||
$attachmentHandler->updateObjectID($message->messageID);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user