78 if (!$this->diskFile instanceof
File)
88 if ($this->diskFileId)
107 public function getCopy(?Storage $storage =
null): ?self
109 $userId = $this->getContext()->getUserId();
110 $storage = $storage ?? Driver::getInstance()->getStorageByUserId($userId);
112 if ($storage ===
null)
117 $folder = $storage->getFolderForUploadedFiles();
119 if ($folder ===
null)
126 if ($diskFile ===
null)
131 $copy =
$diskFile->copyTo($folder, $userId,
true);
133 if (!$copy instanceof
File)
138 return new static($copy, $this->
getChatId());
143 if (!Loader::includeModule(
'disk'))
148 $folder = $chat->getOrCreateDiskFolder();
151 if (!($folder instanceof Folder) ||
$diskFile ===
null)
156 $newFileModel =
$diskFile->copyTo($folder, $chat->getContext()->getUserId(),
true);
158 if (!($newFileModel instanceof
File))
165 $newFileModel->changeCode(\
Bitrix\Im\V2\
Link\
File\FileItem::MEDIA_ORIGINAL_CODE);
168 $newFileModel->increaseGlobalContentVersion();
170 return new static($newFileModel, $chat->getId());
184 'date' => $diskFile->getCreateTime()->format(
'c'),
186 'name' => $diskFile->
getName(),
189 'image' => $this->getPreviewSizes() ??
false,
190 'status' =>
$diskFile->getGlobalContentVersion() > 1?
'done':
'upload',
191 'progress' =>
$diskFile->getGlobalContentVersion() > 1? 100: -1,
192 'authorId' => (int)
$diskFile->getCreatedBy(),
193 'authorName' => \Bitrix\Im\User::formatFullNameFromDatabase(
$diskFile->getCreateUser()),
194 'urlPreview' => $this->getPreviewLink(),
195 'urlShow' => $this->getShowLink(),
196 'urlDownload' => $this->getDownloadLink(),
197 'viewerAttrs' => $this->getViewerAttributes(),
208 if (isset($this->contentType))
218 $diskTypeFile = $this->
getDiskFile()->getTypeFile();
220 switch ($diskTypeFile)
222 case TypeFile::IMAGE:
224 case TypeFile::VIDEO:
226 case TypeFile::AUDIO:
240 private function getPreviewSizes(): ?array
242 $previewParameters = [];
247 $previewParameters =
$diskFile->getFile();
251 $previewParameters =
$diskFile->getView()->getPreviewData();
254 if (empty($previewParameters))
260 'height' => (int)$previewParameters[
'HEIGHT'],
261 'width' => (
int)$previewParameters[
'WIDTH'],
265 private function getPreviewLink(): string
267 $urlManager = UrlManager::getInstance();
270 if ($diskFile->getView()->getPreviewData())
272 $linkType =
'disk.api.file.showPreview';
273 $fileName =
'preview.jpg';
277 $linkType =
'disk.api.file.showImage';
285 return \Bitrix\Im\Common::getPublicDomain() . $urlManager->create($linkType, [
289 'signature' => \
Bitrix\Disk\Security\ParameterSigner::getImageSignature(
$diskFile->getId(), 640, 640),
291 'fileName' => $fileName
295 private function getShowLink(): string
297 $urlManager = UrlManager::getInstance();
302 $linkType =
'disk.api.file.showImage';
306 $linkType =
'disk.api.file.download';
309 return \Bitrix\Im\Common::getPublicDomain() . $urlManager->create($linkType, [
316 private function getDownloadLink(): string
318 $urlManager = UrlManager::getInstance();
321 return \Bitrix\Im\Common::getPublicDomain() . $urlManager->create(
'disk.api.file.download', [
328 private function getViewerAttributes(): ?array
333 $viewerType = FileAttributes::buildByFileData(
$diskFile->getFile() ?? [], $this->getDownloadLink())
335 ->setGroupBy($this->
getChatId() ?? $diskFile->getParentId())
336 ->setAttribute(
'data-im-chat-id', $this->
getChatId())
337 ->setTitle($diskFile->
getName())
339 'type' =>
'download',
342 'type' =>
'copyToMe',
344 'action' =>
'BXIM.disk.saveToDiskAction',
348 'extension' =>
'disk.viewer.actions',
349 'buttonIconClass' =>
'ui-btn-icon-cloud',
353 if ($viewerType->getTypeClass() === FileAttributes::JS_TYPE_CLASS_ONLYOFFICE)
355 $viewerType->setTypeClass(
'BX.Messenger.Integration.Viewer.OnlyOfficeChatItem');
357 $diskFile->getCode() === CreateDocumentByCallTemplateScenario::CODE_RESUME
358 ||
$diskFile->getRealObject()->getCode() === CreateDocumentByCallTemplateScenario::CODE_RESUME
361 $viewerType->setTypeClass(
'BX.Messenger.Integration.Viewer.OnlyOfficeResumeItem');
364 $viewerType->setExtension(
'im.integration.viewer');
366 if ($viewerType->getViewerType() !== \
Bitrix\Main\UI\Viewer\Renderer\Renderer::JS_TYPE_UNKNOWN)
368 return $viewerType->toDataSet();
371 catch (\
Bitrix\Main\ArgumentException $exception)
static getMessage($code, $replace=null, $language=null)