Files
gerrit/polygerrit-ui/app/elements/change/gr-message/gr-message.js
Logan Hanks 1682a0707e Display real author if differs from author
Actions can be taken on a change by one user on behalf of another user.
This is indicated in ChangeMessageInfo by the real_author property.
When this property is present and indicates a different account than
author, then we modify the heading of the message to read:

  <Real Author> on behalf of <Author>

Bug: Issue 5801
Change-Id: Ia9ef4eb410f1f637bce97c7acbfa97c91b8d3882
2017-03-23 16:53:42 -07:00

195 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
(function() {
'use strict';
Polymer({
is: 'gr-message',
/**
* Fired when this message's permalink is tapped.
*
* @event scroll-to
*/
/**
* Fired when this message's reply link is tapped.
*
* @event reply
*/
listeners: {
'tap': '_handleTap',
},
properties: {
changeNum: Number,
message: Object,
author: {
type: Object,
computed: '_computeAuthor(message)',
},
comments: {
type: Object,
observer: '_commentsChanged',
},
config: Object,
hideAutomated: {
type: Boolean,
value: false,
},
hidden: {
type: Boolean,
computed: '_computeIsHidden(hideAutomated, isAutomated)',
reflectToAttribute: true,
},
isAutomated: {
type: Boolean,
computed: '_computeIsAutomated(message)',
},
showAvatar: {
type: Boolean,
computed: '_computeShowAvatar(author, config)',
},
showOnBehalfOf: {
type: Boolean,
computed: '_computeShowOnBehalfOf(message)',
},
showReplyButton: {
type: Boolean,
computed: '_computeShowReplyButton(message, _loggedIn)',
},
projectConfig: Object,
// Computed property needed to trigger Polymer value observing.
_expanded: {
type: Object,
computed: '_computeExpanded(message.expanded)',
},
_loggedIn: {
type: Boolean,
value: false,
},
},
observers: [
'_updateExpandedClass(message.expanded)',
],
ready: function() {
this.$.restAPI.getConfig().then(function(config) {
this.config = config;
}.bind(this));
this.$.restAPI.getLoggedIn().then(function(loggedIn) {
this._loggedIn = loggedIn;
}.bind(this));
},
_updateExpandedClass: function(expanded) {
if (expanded) {
this.classList.add('expanded');
} else {
this.classList.remove('expanded');
}
},
_computeAuthor: function(message) {
return message.author || message.updated_by;
},
_computeShowAvatar: function(author, config) {
return !!(author && config && config.plugin && config.plugin.has_avatars);
},
_computeShowOnBehalfOf: function(message) {
var author = message.author || message.updated_by;
return !!(author && message.real_author &&
author._account_id != message.real_author._account_id);
},
_computeShowReplyButton: function(message, loggedIn) {
return !!message.message && loggedIn;
},
_computeExpanded: function(expanded) {
return expanded;
},
/**
* If there is no value set on the message object as to whether _expanded
* should be true or not, then _expanded is set to true if there are
* inline comments (otherwise false).
*/
_commentsChanged: function(value) {
if (this.message && this.message.expanded === undefined) {
this.set('message.expanded', Object.keys(value || {}).length > 0);
}
},
_handleTap: function(e) {
if (this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', true);
},
_handleAuthorTap: function(e) {
if (!this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', false);
},
_computeIsAutomated: function(message) {
return !!(message.reviewer ||
(message.tag && message.tag.indexOf('autogenerated') === 0));
},
_computeIsHidden: function(hideAutomated, isAutomated) {
return hideAutomated && isAutomated;
},
_computeIsReviewerUpdate: function(event) {
return event.type === 'REVIEWER_UPDATE';
},
_computeClass: function(expanded, showAvatar) {
var classes = [];
classes.push(expanded ? 'expanded' : 'collapsed');
classes.push(showAvatar ? 'showAvatar' : 'hideAvatar');
return classes.join(' ');
},
_computeMessageHash: function(message) {
return '#message-' + message.id;
},
_handleLinkTap: function(e) {
e.preventDefault();
this.fire('scroll-to', {message: this.message}, {bubbles: false});
var hash = this._computeMessageHash(this.message);
// Don't add the hash to the window history if it's already there.
// Otherwise you mess up expected back button behavior.
if (window.location.hash == hash) { return; }
// Change the URL but dont trigger a nav event. Otherwise it will
// reload the page.
page.show(window.location.pathname + hash, null, false);
},
_handleReplyTap: function(e) {
e.preventDefault();
this.fire('reply', {message: this.message});
},
});
})();