Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render display name in new annotations #545

Merged
merged 2 commits into from
Sep 15, 2017
Merged
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
8 changes: 6 additions & 2 deletions src/sidebar/components/annotation-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ function AnnotationHeaderController(groups, settings, serviceUrl) {
return self.annotation.user;
};

this.username = function () {
return persona.username(self.annotation.user);
this.displayName = () => {
var userInfo = this.annotation.user_info;
if (userInfo && userInfo.display_name) {
return userInfo.display_name;
}
return persona.username(this.annotation.user);
};

this.isThirdPartyUser = function () {
Expand Down
4 changes: 4 additions & 0 deletions src/sidebar/components/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ function AnnotationController(

// New annotations (just created locally by the client, rather then
// received from the server) have some fields missing. Add them.
//
// FIXME: This logic should go in the `addAnnotations` Redux action once all
// required state is in the store.
self.annotation.user = self.annotation.user || session.state.userid;
self.annotation.user_info = self.annotation.user_info || session.state.user_info;
self.annotation.group = self.annotation.group || groups.focused().id;
if (!self.annotation.permissions) {
self.annotation.permissions = permissions.default(self.annotation.user,
Expand Down
23 changes: 22 additions & 1 deletion src/sidebar/components/test/annotation-header-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var fakeDocumentMeta = {
titleText: 'Dummy title',
};

describe('annotationHeader', function () {
describe('sidebar.components.annotation-header', function () {
var $componentController;
var fakeGroups;
var fakeSettings;
Expand Down Expand Up @@ -72,5 +72,26 @@ describe('annotationHeader', function () {
assert.deepEqual(ctrl.documentMeta(), fakeDocumentMeta);
});
});

describe('#displayName', () => {
it('returns the username if no display name is set', () => {
var ann = fixtures.defaultAnnotation();
var ctrl = $componentController('annotationHeader', {}, {
annotation: ann,
});
assert.deepEqual(ctrl.displayName(), 'bill');
});

it('returns the display name if set', () => {
var ann = fixtures.defaultAnnotation();
ann.user_info = {
display_name: 'Bill Jones',
};
var ctrl = $componentController('annotationHeader', {}, {
annotation: ann,
});
assert.deepEqual(ctrl.displayName(), 'Bill Jones');
});
});
});
});
6 changes: 6 additions & 0 deletions src/sidebar/components/test/annotation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,16 @@ describe('annotation', function() {
var annotation = fixtures.newAnnotation();
annotation.user = undefined;
fakeSession.state.userid = 'acct:bill@localhost';
fakeSession.state.user_info = {
display_name: 'Bill Jones',
};

createDirective(annotation);

assert.equal(annotation.user, 'acct:bill@localhost');
assert.deepEqual(annotation.user_info, {
display_name: 'Bill Jones',
});
});

it('sets the permissions of new annotations', function() {
Expand Down
4 changes: 2 additions & 2 deletions src/sidebar/templates/annotation-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
target="_blank"
ng-if="!vm.isThirdPartyUser()"
ng-href="{{vm.serviceUrl('user',{user:vm.user()})}}"
>{{vm.username()}}</a>
>{{vm.displayName()}}</a>
<span class="annotation-header__user"
ng-if="vm.isThirdPartyUser()"
>{{vm.username()}}</span>
>{{vm.displayName()}}</span>
<span class="annotation-collapsed-replies">
<a class="annotation-link" href=""
ng-click="vm.onReplyCountClick()"
Expand Down