show displayname not uid in commit mentions
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
5d98ab83e9
commit
0e926efc9b
|
@ -35,7 +35,8 @@
|
||||||
'creationDateTime': '{' + NS_OWNCLOUD + '}creationDateTime',
|
'creationDateTime': '{' + NS_OWNCLOUD + '}creationDateTime',
|
||||||
'objectType': '{' + NS_OWNCLOUD + '}objectType',
|
'objectType': '{' + NS_OWNCLOUD + '}objectType',
|
||||||
'objectId': '{' + NS_OWNCLOUD + '}objectId',
|
'objectId': '{' + NS_OWNCLOUD + '}objectId',
|
||||||
'isUnread': '{' + NS_OWNCLOUD + '}isUnread'
|
'isUnread': '{' + NS_OWNCLOUD + '}isUnread',
|
||||||
|
'mentions': '{' + NS_OWNCLOUD + '}mentions'
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function(data) {
|
parse: function(data) {
|
||||||
|
@ -48,8 +49,30 @@
|
||||||
creationDateTime: data.creationDateTime,
|
creationDateTime: data.creationDateTime,
|
||||||
objectType: data.objectType,
|
objectType: data.objectType,
|
||||||
objectId: data.objectId,
|
objectId: data.objectId,
|
||||||
isUnread: (data.isUnread === 'true')
|
isUnread: (data.isUnread === 'true'),
|
||||||
|
mentions: this._parseMentions(data.mentions)
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
_parseMentions: function(mentions) {
|
||||||
|
if(_.isUndefined(mentions)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
var result = {};
|
||||||
|
for(var i in mentions) {
|
||||||
|
var mention = mentions[i];
|
||||||
|
if(_.isUndefined(mention.localName) || mention.localName !== 'mention') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[i] = {};
|
||||||
|
for (var child = mention.firstChild; child; child = child.nextSibling) {
|
||||||
|
if(_.isUndefined(child.localName) || !child.localName.startsWith('mention')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[i][child.localName] = child.textContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
date: OC.Util.relativeModifiedDate(timestamp),
|
date: OC.Util.relativeModifiedDate(timestamp),
|
||||||
altDate: OC.Util.formatDate(timestamp),
|
altDate: OC.Util.formatDate(timestamp),
|
||||||
formattedMessage: this._formatMessage(commentModel.get('message'))
|
formattedMessage: this._formatMessage(commentModel.get('message'), commentModel.get('mentions'))
|
||||||
}, commentModel.attributes);
|
}, commentModel.attributes);
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
@ -251,8 +251,17 @@
|
||||||
* Convert a message to be displayed in HTML,
|
* Convert a message to be displayed in HTML,
|
||||||
* converts newlines to <br> tags.
|
* converts newlines to <br> tags.
|
||||||
*/
|
*/
|
||||||
_formatMessage: function(message) {
|
_formatMessage: function(message, mentions) {
|
||||||
return escapeHTML(message).replace(/\n/g, '<br/>');
|
message = escapeHTML(message).replace(/\n/g, '<br/>');
|
||||||
|
|
||||||
|
for(var i in mentions) {
|
||||||
|
var mention = '@' + mentions[i].mentionId;
|
||||||
|
mention = mention.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
var displayName = '<b>'+ _.escape(mentions[i].mentionDisplayName)+'</b>';
|
||||||
|
message = message.replace(new RegExp(mention, 'g'), displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
},
|
},
|
||||||
|
|
||||||
nextPage: function() {
|
nextPage: function() {
|
||||||
|
@ -359,6 +368,42 @@
|
||||||
this.nextPage();
|
this.nextPage();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onSubmitSuccess: function(model, $form, commentId) {
|
||||||
|
var self = this;
|
||||||
|
var $submit = $form.find('.submit');
|
||||||
|
var $loading = $form.find('.submitLoading');
|
||||||
|
var $textArea = $form.find('.message');
|
||||||
|
|
||||||
|
model.fetch({
|
||||||
|
success: function(model) {
|
||||||
|
$submit.removeClass('hidden');
|
||||||
|
$loading.addClass('hidden');
|
||||||
|
if(!_.isUndefined(commentId)) {
|
||||||
|
var $row = $form.closest('.comment');
|
||||||
|
$row.data('commentEl')
|
||||||
|
.removeClass('hidden')
|
||||||
|
.find('.message')
|
||||||
|
.html(self._formatMessage(model.get('message'), model.get('mentions')));
|
||||||
|
$row.remove();
|
||||||
|
} else {
|
||||||
|
var $row = $form.closest('.comments');
|
||||||
|
console.log($form);
|
||||||
|
$('.commentsTabView .comments').find('li:first')
|
||||||
|
.find('.message')
|
||||||
|
.html(self._formatMessage(model.get('message'), model.get('mentions')));
|
||||||
|
$textArea.val('').prop('disabled', false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
$submit.removeClass('hidden');
|
||||||
|
$loading.addClass('hidden');
|
||||||
|
$textArea.prop('disabled', false);
|
||||||
|
|
||||||
|
OC.Notification.showTemporary(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
_onSubmitComment: function(e) {
|
_onSubmitComment: function(e) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var $form = $(e.target);
|
var $form = $(e.target);
|
||||||
|
@ -385,14 +430,7 @@
|
||||||
message: $textArea.val()
|
message: $textArea.val()
|
||||||
}, {
|
}, {
|
||||||
success: function(model) {
|
success: function(model) {
|
||||||
var $row = $form.closest('.comment');
|
self._onSubmitSuccess(model, $form, commentId);
|
||||||
$submit.removeClass('hidden');
|
|
||||||
$loading.addClass('hidden');
|
|
||||||
$row.data('commentEl')
|
|
||||||
.removeClass('hidden')
|
|
||||||
.find('.message')
|
|
||||||
.html(self._formatMessage(model.get('message')));
|
|
||||||
$row.remove();
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
$submit.removeClass('hidden');
|
$submit.removeClass('hidden');
|
||||||
|
@ -414,10 +452,8 @@
|
||||||
at: 0,
|
at: 0,
|
||||||
// wait for real creation before adding
|
// wait for real creation before adding
|
||||||
wait: true,
|
wait: true,
|
||||||
success: function() {
|
success: function(model) {
|
||||||
$submit.removeClass('hidden');
|
self._onSubmitSuccess(model, $form);
|
||||||
$loading.addClass('hidden');
|
|
||||||
$textArea.val('').prop('disabled', false);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
$submit.removeClass('hidden');
|
$submit.removeClass('hidden');
|
||||||
|
|
Loading…
Reference in New Issue