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

Fix: Missing option to set user's avatar from a url #9229

Merged
merged 1 commit into from
Dec 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
margin-right: 10px;
margin-bottom: 10px;

&.disabled {
opacity: 0.4;
}

cursor: pointer;

& .avatar {
Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-ui-account/client/accountProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ <h2 style="flex: 1 1; white-space: nowrap;">{{_ "Profile"}}</h2>
</label>
<input type="file" name="" value="" id="upload-avatar" style="display:none;">
</div>
<div class="rc-select-avatar__list-item rc-tooltip js-select-avatar-url {{selectUrl}}" aria-label="{{_ "Use_url_for_avatar" }}">
<label class="rc-select-avatar__upload-label avatar">
{{> icon block="rc-select-avatar__upload-icon" icon="permalink"}}
</label>
</div>
{{#each service in services}}
{{ > avatarService service}}
{{/each}}
<div class="rc-input">

<label class="rc-input__label">
<div class="rc-input__title">{{_ "Use_url_for_avatar"}}</div>
<div class="rc-input__wrapper">
<input name="avatar_url" class="rc-input__element js-avatar-url-input" placeholder="{{_ "Use_url_for_avatar"}}">
</div>
</label>
</div>
</div>
{{else}}
<div class="rc-select-avatar__loading">
Expand Down
28 changes: 27 additions & 1 deletion packages/rocketchat-ui-account/client/accountProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Template.accountProfile.helpers({
nameInvalid() {
return !validateName(Template.instance().realname.get());
},
selectUrl() {
return Template.instance().url.get().trim() ? '' : 'disabled';
},
services() {
const suggestions = Template.instance().suggestions.get();
return ['gravatar', 'facebook', 'google', 'github', 'gitlab', 'linkedIn', 'twitter']
Expand Down Expand Up @@ -153,6 +156,7 @@ Template.accountProfile.onCreated(function() {
self.password = new ReactiveVar;
self.suggestions = new ReactiveVar;
self.avatar = new ReactiveVar;
self.url = new ReactiveVar('');
self.usernameAvaliable = new ReactiveVar(true);

RocketChat.Notifications.onLogged('updateAvatar', () => self.avatar.set());
Expand Down Expand Up @@ -185,7 +189,12 @@ Template.accountProfile.onCreated(function() {
this.save = function(typedPassword, cb) {
const avatar = self.avatar.get();
if (avatar) {
Meteor.call('setAvatarFromService', avatar.blob, avatar.contentType, avatar.service, function(err) {
const params = [avatar.blob];

params.push(avatar.contentType);

params.push(avatar.service);
Meteor.call('setAvatarFromService', ...params, function(err) {
if (err && err.details && err.details.timeToReset) {
toastr.error(t('error-too-many-requests', {
seconds: parseInt(err.details.timeToReset / 1000)
Expand Down Expand Up @@ -295,6 +304,23 @@ Template.accountProfile.events({
}
});
},
'click .js-select-avatar-url'(e, instance, ...args) {
const url = instance.url.get().trim();
if (!url) {
return;
}
setAvatar.apply({
suggestion: {
service: 'url',
blob: url,
contentType: ''
}
}, [e, instance, ...args]);
},
'input .js-avatar-url-input'(e, instance) {
const text = e.target.value;
instance.url.set(text);
},
'click .js-select-avatar'(...args) {
this.suggestion ? setAvatar.apply(this, args) : loginWith.apply(this, args);
},
Expand Down