зеркало из https://github.com/nextcloud/activity.git
Parse the messages from the new value
This commit is contained in:
Родитель
edf40a0435
Коммит
cbf9e63336
193
js/script.js
193
js/script.js
|
@ -194,7 +194,9 @@ $(function(){
|
|||
},
|
||||
|
||||
addActivity: function(activity) {
|
||||
if (activity.subject_prepared.toString().indexOf('<file') >= 0) {
|
||||
var parsedSubject = this.parseMessage(activity.subject_prepared);
|
||||
|
||||
if (parsedSubject.indexOf('<a') >= 0) {
|
||||
activity.link = '';
|
||||
}
|
||||
|
||||
|
@ -206,7 +208,7 @@ $(function(){
|
|||
|
||||
+ ' <div class="activitysubject">' + "\n"
|
||||
+ ((activity.link) ? ' <a href="' + activity.link + '">' + "\n" : '')
|
||||
+ ' ' + activity.subjectformatted.markup.trimmed + "\n"
|
||||
+ ' ' + parsedSubject + "\n"
|
||||
+ ((activity.link) ? ' </a>' + "\n" : '')
|
||||
+ ' </div>' + "\n"
|
||||
|
||||
|
@ -214,9 +216,9 @@ $(function(){
|
|||
+ ' ' + escapeHTML(OC.Util.relativeModifiedDate(activity.timestamp)) + "\n"
|
||||
+' </span>' + "\n";
|
||||
|
||||
if (activity.message) {
|
||||
if (activity.message_prepared) {
|
||||
content += '<div class="activitymessage">' + "\n"
|
||||
+ activity.messageformatted.markup.trimmed + "\n"
|
||||
+ this.parseMessage(activity.message_prepared) + "\n"
|
||||
+'</div>' + "\n";
|
||||
}
|
||||
|
||||
|
@ -238,6 +240,189 @@ $(function(){
|
|||
this.lastDateGroup.append($content);
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a message
|
||||
*
|
||||
* @param {String} message
|
||||
* @returns {String}
|
||||
*/
|
||||
parseMessage: function (message) {
|
||||
var parsedMessage = this.parseCollection(message);
|
||||
parsedMessage = this.parseParameters(parsedMessage, true);
|
||||
return parsedMessage;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a collection tag
|
||||
*
|
||||
* @param {String} message
|
||||
* @returns {String}
|
||||
*/
|
||||
parseCollection: function(message) {
|
||||
var self = this;
|
||||
|
||||
return message.replace(/<collection>(.*?)<\/collection>/g, function (match, parameterString, a, b, c, d, e, f) {
|
||||
var parameterList = parameterString.split('><'),
|
||||
parameterListLength = parameterList.length,
|
||||
parameters = [];
|
||||
|
||||
for (var i = 0; i < parameterListLength; i++) {
|
||||
var parameter = parameterList[i];
|
||||
if (i > 0) {
|
||||
parameter = '<' + parameter;
|
||||
}
|
||||
if (i + 1 < parameterListLength) {
|
||||
parameter = parameter + '>';
|
||||
}
|
||||
|
||||
if (parameterListLength > 5 && i > 2) {
|
||||
parameters.push(self.parseParameters(parameter, false));
|
||||
} else {
|
||||
parameters.push(self.parseParameters(parameter, true));
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters.length === 1) {
|
||||
return parameters.pop();
|
||||
} else if (parameters.length <= 5) {
|
||||
var lastParameter = parameters.pop();
|
||||
return t('activity', '{parameterList} and {lastParameter}', {
|
||||
parameterList: parameters.join(t('activity', ', ')),
|
||||
lastParameter: lastParameter
|
||||
}, undefined, {
|
||||
escape: false
|
||||
});
|
||||
} else {
|
||||
var firstParameters = parameters.slice(0, 3).join(t('activity', ', ')),
|
||||
otherParameters = parameters.slice(3).join(t('activity', ', ')),
|
||||
listLength = parameters.length;
|
||||
|
||||
return n('activity',
|
||||
'{parameterList} and {linkStart}%n more{linkEnd}',
|
||||
'{parameterList} and {linkStart}%n more{linkEnd}',
|
||||
listLength - 3,
|
||||
{
|
||||
parameterList: firstParameters,
|
||||
linkStart: '<strong class="has-tooltip" title="' + otherParameters + '">',
|
||||
linkEnd: '</strong>'
|
||||
},
|
||||
{
|
||||
escape: false
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses parameters
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {boolean} useHtml
|
||||
* @returns {String}
|
||||
*/
|
||||
parseParameters: function (message, useHtml) {
|
||||
message = this.parseUntypedParameters(message, useHtml);
|
||||
message = this.parseUserParameters(message, useHtml);
|
||||
message = this.parseFederatedCloudIDParameters(message, useHtml);
|
||||
message = this.parseFileParameters(message, useHtml);
|
||||
|
||||
return message;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a parameter tag
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {boolean} useHtml
|
||||
* @returns {String}
|
||||
*/
|
||||
parseUntypedParameters: function(message, useHtml) {
|
||||
return message.replace(/<parameter>(.*?)<\/parameter>/g, function (match, parameter) {
|
||||
if (useHtml) {
|
||||
return '<strong>' + parameter + '</strong>';
|
||||
} else {
|
||||
return parameter;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a user tag
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {boolean} useHtml
|
||||
* @returns {String}
|
||||
*/
|
||||
parseUserParameters: function(message, useHtml) {
|
||||
return message.replace(/<user\ display\-name=\"(.*?)\">(.*?)<\/user>/g, function (match, displayName, userId) {
|
||||
if (useHtml) {
|
||||
var userString = '<strong>' + displayName + '</strong>';
|
||||
// TODO if (avatars are disabled) {
|
||||
userString = '<div class="avatar" data-user="' + userId + '" data-user-display-name="' + displayName + '"></div>' + userString;
|
||||
// TODO }
|
||||
|
||||
return userString;
|
||||
} else {
|
||||
return displayName;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a federated cloud id tag
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {boolean} useHtml
|
||||
* @returns {String}
|
||||
*/
|
||||
parseFederatedCloudIDParameters: function(message, useHtml) {
|
||||
return message.replace(/<federated-cloud-id\ display\-name=\"(.*?)\"\ user=\"(.*?)\"\ server=\"(.*?)\">(.*?)<\/federated-cloud-id>/g, function (match, displayName, userId, server, cloudId) {
|
||||
if (displayName === cloudId) {
|
||||
// No display name from contacts, use a short version of the id in the UI
|
||||
displayName = userId + '@…';
|
||||
}
|
||||
|
||||
if (useHtml) {
|
||||
return '<strong class="has-tooltip" title="' + cloudId + '">' + displayName + '</strong>';
|
||||
} else {
|
||||
return displayName;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a file tag
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {boolean} useHtml
|
||||
* @returns {String}
|
||||
*/
|
||||
parseFileParameters: function(message, useHtml) {
|
||||
return message.replace(/<file\ link=\"(.*?)\"\ id=\"(.*?)\">(.*?)<\/file>/g, function (match, link, fileId, path) {
|
||||
var title = '',
|
||||
displayPath = path,
|
||||
lastSlashPosition = path.lastIndexOf('/');
|
||||
|
||||
|
||||
if (lastSlashPosition > 0) {
|
||||
var dirPath = path.substring(0, lastSlashPosition);
|
||||
displayPath = path.substring(lastSlashPosition + 1);
|
||||
|
||||
// No display name from contacts, use a short version of the id in the UI
|
||||
title = '" title="' + escapeHTML(t('activity', 'in {directory}', {
|
||||
directory: dirPath
|
||||
}));
|
||||
}
|
||||
|
||||
if (useHtml) {
|
||||
return '<a class="filename has-tooltip" href="' + link + title + '">' + displayPath + '</a>';
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
processElements: function ($element) {
|
||||
$element.find('.avatar').each(function() {
|
||||
var element = $(this);
|
||||
|
|
Загрузка…
Ссылка в новой задаче