Skip to content
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
36 changes: 36 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@
'url' => '/',
'verb' => 'GET',
],

/**
* Previews
*/
[
'name' => 'Preview#getPreviewByFileId',
'url' => '/attachment/{token}/{fileId}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
],

'ocs' => [
/**
* Signaling
Expand Down Expand Up @@ -139,6 +153,28 @@
],
],

/**
* Files
*/
[
'name' => 'Attachment#copyFileToAttachment',
'url' => '/api/{apiVersion}/chat/{token}/file',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Attachment#copyAttachmentToFile',
'url' => '/api/{apiVersion}/chat/{token}/attachment/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],

/**
* Room
*/
Expand Down
63 changes: 48 additions & 15 deletions js/views/chatview.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,25 @@
var defaultIconUrl = OC.imagePath('core', 'filetypes/file');
var previewUrl = defaultIconUrl;
if ($filePreview.data('preview-available') === 'yes') {
previewUrl = OC.generateUrl(
'/core/preview?fileId={fileId}&x={width}&y={height}',
{
fileId: $filePreview.data('file-id'),
width: previewSize,
height: previewSize
});
if ($filePreview.data('type') === 'talk-attachment') {
previewSize *= 2;
previewUrl = OC.generateUrl(
'/apps/spreed/attachment/{conversation}/{fileId}?x={width}&y={height}',
{
conversation: this.model.get('token'),
fileId: $filePreview.data('file-id'),
width: previewSize,
height: previewSize
});
} else {
previewUrl = OC.generateUrl(
'/core/preview?fileId={fileId}&x={width}&y={height}',
{
fileId: $filePreview.data('file-id'),
width: previewSize,
height: previewSize
});
}
} else {
previewUrl = OC.MimeType.getIconUrl($filePreview.data('mimetype'));
}
Expand Down Expand Up @@ -1078,19 +1090,27 @@
var $shareButton = $form.find('.share');
var $shareLoadingIcon = $form.find('.shareLoading');

OC.dialogs.filepicker(t('spreed', 'File to share'), function(targetPath) {
OC.dialogs.filepicker(t('spreed', 'File to share'), function(targetPath, clickType) {
$shareButton.addClass('hidden');
$shareLoadingIcon.removeClass('hidden');

var url = OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares';
var data = {
shareType: OC.Share.SHARE_TYPE_ROOM,
path: targetPath,
shareWith: self.collection.token
};
if (clickType === 'attach') {
url = OC.linkToOCS('apps/spreed/api/v1/chat', 2) + self.collection.token + '/file';
data = {
path: targetPath
};
}
$.ajax({
type: 'POST',
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares',
url: url,
dataType: 'json',
data: {
shareType: OC.Share.SHARE_TYPE_ROOM,
path: targetPath,
shareWith: self.collection.token
}
data: data
}).always(function() {
$shareLoadingIcon.addClass('hidden');
$shareButton.removeClass('hidden');
Expand All @@ -1107,7 +1127,20 @@

OC.Notification.showTemporary(message);
});
}, false, ['*', 'httpd/unix-directory'], true, OC.dialogs.FILEPICKER_TYPE_CHOOSE);
}, false, ['*', 'httpd/unix-directory'], true, OC.dialogs.FILEPICKER_TYPE_CUSTOM, '', {
buttons: [
{
text: t('spreed', 'Share'),
type: 'share',
defaultButton: false
},
{
text: t('spreed', 'Attach'),
type: 'attach',
defaultButton: true
}
]
});
},

});
Expand Down
11 changes: 11 additions & 0 deletions js/views/richobjectstringparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@

return this.callTemplate(parameter);

case 'talk-attachment':
parameter.link = 'https://nextcloud18.local/';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

if (parameter['preview-available'] === 'yes' && (
parameter.mimetype.indexOf('image/') === 0 ||
parameter.mimetype.indexOf('video/') === 0)) {
if (!this.mediaTemplate) {
this.mediaTemplate = OCA.Talk.Views.Templates['richobjectstringparser_talkattachment_media'];
}
return this.mediaTemplate(parameter);
}

case 'file':
if (!this.filePreviewTemplate) {
this.filePreviewTemplate = OCA.Talk.Views.Templates['richobjectstringparser_filepreview'];
Expand Down
17 changes: 17 additions & 0 deletions js/views/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="{{link}}" class="filePreviewContainer" target="_blank" rel="noopener noreferrer">
<span class="filePreview" data-file-id="{{id}}" data-mimetype="{{mimetype}}" data-preview-available="{{preview-available}}"></span>
<span class="filePreview" data-file-id="{{id}}" data-type="{{type}}" data-mimetype="{{mimetype}}" data-preview-available="{{preview-available}}"></span>
<strong>{{name}}</strong>
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="{{link}}" class="filePreviewContainer" target="_blank" rel="noopener noreferrer">
<span class="filePreview" data-file-id="{{id}}" data-type="{{type}}" data-mimetype="{{mimetype}}" data-preview-available="{{preview-available}}"></span>
</a>
64 changes: 62 additions & 2 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
namespace OCA\Talk\Chat\Parser;


use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\GuestManager;
use OCA\Talk\Model\Message;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Share\RoomShareProvider;
use OCP\Comments\IComment;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IPreview as IPreviewManager;
use OCP\IURLGenerator;
Expand All @@ -42,6 +44,8 @@

class SystemMessage {

/** @var string */
protected $appName;
/** @var IUserManager */
protected $userManager;
/** @var GuestManager */
Expand All @@ -50,6 +54,8 @@ class SystemMessage {
protected $previewManager;
/** @var RoomShareProvider */
protected $shareProvider;
/** @var IConfig */
protected $config;
/** @var IRootFolder */
protected $rootFolder;
/** @var IURLGenerator */
Expand All @@ -62,16 +68,20 @@ class SystemMessage {
/** @var string[] */
protected $guestNames = [];

public function __construct(IUserManager $userManager,
public function __construct(string $appName,
IUserManager $userManager,
GuestManager $guestManager,
IPreviewManager $previewManager,
RoomShareProvider $shareProvider,
IConfig $config,
IRootFolder $rootFolder,
IURLGenerator $url) {
$this->appName = $appName;
$this->userManager = $userManager;
$this->guestManager = $guestManager;
$this->previewManager = $previewManager;
$this->shareProvider = $shareProvider;
$this->config = $config;
$this->rootFolder = $rootFolder;
$this->url = $url;
}
Expand Down Expand Up @@ -243,6 +253,17 @@ public function parseMessage(Message $chatMessage): void {
$parsedMessage = $this->l->t('You shared a file which is no longer available');
}
}
} else if ($message === 'attachment') {
try {
$parsedParameters['attachment'] = $this->getAttachment($chatMessage->getRoom(), (int) $parameters['fileId']);
$parsedMessage = '{attachment}';
$chatMessage->setMessageType('comment');
} catch (\Exception $e) {
$parsedMessage = $this->l->t('{actor} shared a file which is no longer available');
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You shared a file which is no longer available');
}
}
} else {
throw new \OutOfBoundsException('Unknown subject');
}
Expand Down Expand Up @@ -306,6 +327,45 @@ protected function getFileFromShare(Participant $participant, string $shareId):
];
}

/**
* @param Room $room
* @param int $fileId
* @return array
* @throws NotFoundException
*/
protected function getAttachment(Room $room, int $fileId): array {
$file = $this->getConversationFile($room, $fileId);
return [
'type' => 'talk-attachment',
'id' => $file->getId(),
'name' => $file->getName(),
'conversation' => $room->getToken(),
'mimetype' => $file->getMimeType(),
'preview-available' => $this->previewManager->isMimeSupported($file->getMimeType()) ? 'yes' : 'no',
];
}

/**
* @param Room $room
* @param int $fileId
* @return File
* @throws NotFoundException
*/
protected function getConversationFile(Room $room, int $fileId): File {
$instanceId = $this->config->getSystemValueString('instanceid');
$appDataFolderName = 'appdata_' . $instanceId . '/talk'; // FIXME appId

/** @var Folder $folder */
$folder = $this->rootFolder->get($appDataFolderName . '/' . $room->getToken());
$nodes = $folder->getById($fileId);

if (empty($nodes)) {
throw new NotFoundException('File not found in conversation');
}

return array_pop($nodes);
}

protected function getActor(IComment $comment): array {
if ($comment->getActorType() === 'guests') {
return $this->getGuest($comment->getActorId());
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/AEnvironmentAwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Controller;

abstract class AEnvironmentAwareController extends OCSController {
abstract class AEnvironmentAwareController extends Controller implements IEnvironmentAwareController {

/** @var Room */
protected $room;
Expand Down
56 changes: 56 additions & 0 deletions lib/Controller/AEnvironmentAwareOCSController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
*
* @author Lukas Reschke <[email protected]>
* @author Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Controller;

use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\OCSController;

abstract class AEnvironmentAwareOCSController extends OCSController implements IEnvironmentAwareController {

/** @var Room */
protected $room;
/** @var Participant */
protected $participant;

public function setRoom(Room $room): void {
$this->room = $room;
}

public function getRoom(): ?Room {
return $this->room;
}

public function setParticipant(Participant $participant): void {
$this->participant = $participant;
}

public function getParticipant(): ?Participant {
return $this->participant;
}

}
Loading