Merge pull request #1519 from nextcloud/better-comments-in-activity-sidebar

Better comments in activity sidebar
This commit is contained in:
Morris Jobke 2016-10-05 23:56:10 +02:00 committed by GitHub
commit fe2116ecf7
4 changed files with 71 additions and 17 deletions

View File

@ -32,6 +32,7 @@ $eventDispatcher->addListener(
\OCP\Util::addScript('comments', 'commentsummarymodel');
\OCP\Util::addScript('comments', 'commentstabview');
\OCP\Util::addScript('comments', 'filesplugin');
\OCP\Util::addScript('comments', 'activitytabviewplugin');
\OCP\Util::addStyle('comments', 'comments');
}
);

View File

@ -59,35 +59,39 @@
line-height: 32px;
}
#activityTabView li.comment.collapsed .activitymessage,
#commentsTabView .comment.collapsed .message {
white-space: pre-wrap;
}
#activityTabView li.comment.collapsed .activitymessage,
#commentsTabView .comment.collapsed .message {
max-height: 70px;
overflow: hidden;
}
#activityTabView li.comment .message-overlay,
#commentsTabView .comment .message-overlay {
display: none;
}
#activityTabView li.comment.collapsed .message-overlay,
#commentsTabView .comment.collapsed .message-overlay {
display: block;
position: absolute;
position: absolute;
z-index: 2;
height: 50px;
pointer-events: none;
height: 50px;
pointer-events: none;
left: 0;
right: 0;
bottom: 0;
bottom: 0;
background: -moz-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1));
background: -webkit-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1));
background: -o-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1));
background: -ms-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1));
background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#00FFFFFF', endColorstr='#FFFFFFFF');
background-repeat: no-repeat;
background-repeat: no-repeat;
}
#commentsTabView .authorRow>div {

View File

@ -0,0 +1,59 @@
/*
* @author Joas Schilling <coding@schilljs.com>
* Copyright (c) 2016
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*/
(function() {
OCA.Comments.ActivityTabViewPlugin = {
/**
* Prepare activity for display
*
* @param {OCA.Activity.ActivityModel} model for this activity
* @param {jQuery} $el jQuery handle for this activity
* @param {string} view The view that displayes this activity
*/
prepareModelForDisplay: function (model, $el, view) {
if (model.get('app') !== 'comments' || model.get('type') !== 'comments') {
return;
}
if (view === 'ActivityTabView') {
$el.addClass('comment');
if (this._isLong(model.get('message_prepared'))) {
$el.addClass('collapsed');
var $overlay = $('<div>').addClass('message-overlay');
$el.find('.activitymessage').after($overlay);
$el.on('click', this._onClickCollapsedComment);
}
}
},
/*
* Copy of CommentsTabView._onClickComment()
*/
_onClickCollapsedComment: function(ev) {
var $row = $(ev.target);
if (!$row.is('.comment')) {
$row = $row.closest('.comment');
}
$row.removeClass('collapsed');
},
/*
* Copy of CommentsTabView._isLong()
*/
_isLong: function(message) {
return message.length > 250 || (message.match(/\n/g) || []).length > 1;
}
};
})();
OC.Plugins.register('OCA.Activity.RenderingPlugins', OCA.Comments.ActivityTabViewPlugin);

View File

@ -159,7 +159,7 @@ class Extension implements IExtension {
}
return (string) $l->t('%1$s commented', $params);
case self::ADD_COMMENT_MESSAGE:
return $this->convertParameterToComment($params[0], 120);
return $this->convertParameterToComment($params[0]);
}
return false;
@ -196,7 +196,6 @@ class Extension implements IExtension {
try {
return strip_tags($user) === $this->activityManager->getCurrentUserId();
} catch (\UnexpectedValueException $e) {
// FIXME this is awkward, but we have no access to the current user in emails
return false;
}
}
@ -301,21 +300,12 @@ class Extension implements IExtension {
* @param string $parameter
* @return string
*/
protected function convertParameterToComment($parameter, $maxLength = 0) {
protected function convertParameterToComment($parameter) {
if (preg_match('/^\<parameter\>(\d*)\<\/parameter\>$/', $parameter, $matches)) {
try {
$comment = $this->commentsManager->get((int) $matches[1]);
$message = $comment->getMessage();
$message = str_replace("\n", '<br />', str_replace(['<', '>'], ['&lt;', '&gt;'], $message));
if ($maxLength && isset($message[$maxLength + 20])) {
$findSpace = strpos($message, ' ', $maxLength);
if ($findSpace !== false && $findSpace < $maxLength + 20) {
return substr($message, 0, $findSpace) . '…';
}
return substr($message, 0, $maxLength + 20) . '…';
}
return $message;
} catch (NotFoundException $e) {
return '';