Profile picture setting and notifdications thereof.

pull/1/head
David Baker 2015-07-17 16:41:27 +01:00
parent 782234de6d
commit ff567faeaa
3 changed files with 44 additions and 2 deletions

View File

@ -20,11 +20,23 @@ var React = require('react');
var ChangeAvatarController = require("../../../../src/controllers/molecules/ChangeAvatar"); var ChangeAvatarController = require("../../../../src/controllers/molecules/ChangeAvatar");
var Loader = require("react-loader");
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'ChangeAvatar', displayName: 'ChangeAvatar',
mixins: [ChangeAvatarController], mixins: [ChangeAvatarController],
onFileSelected: function(ev) {
this.setAvatarFromFile(ev.target.files[0]);
},
onError: function(error) {
this.setState({
errorText: "Failed to set profile picture!"
});
},
render: function() { render: function() {
switch (this.state.phase) { switch (this.state.phase) {
case this.Phases.Display: case this.Phases.Display:
@ -33,7 +45,9 @@ module.exports = React.createClass({
<div> <div>
<img src={this.state.avatarUrl} /> <img src={this.state.avatarUrl} />
<div> <div>
<button>Upload new</button> Upload new:
<input type="file" onChange={this.onFileSelected}/>
{this.state.errorText}
<button onClick={this.props.onFinished}>Cancel</button> <button onClick={this.props.onFinished}>Cancel</button>
</div> </div>
</div> </div>

View File

@ -21,11 +21,18 @@ function textForMemberEvent(ev) {
return ev.getSender() + " set their display name to " + ev.getContent().displayname; return ev.getSender() + " set their display name to " + ev.getContent().displayname;
} else if (ev.getPrevContent().displayname && !ev.getContent().displayname) { } else if (ev.getPrevContent().displayname && !ev.getContent().displayname) {
return ev.getSender() + " removed their display name"; return ev.getSender() + " removed their display name";
} else if (ev.getPrevContent().avatar_url && !ev.getContent().avatar_url) {
return ev.getSender() + " removed their profile picture";
} else if (ev.getPrevContent().avatar_url && ev.getContent().avatar_url) {
return ev.getSender() + " changed their profile picture";
} else if (!ev.getPrevContent().avatar_url && ev.getContent().avatar_url) {
return ev.getSender() + " set a profile picture";
} }
} else { } else {
if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key); if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key);
return targetName + " joined the room."; return targetName + " joined the room.";
} }
return '';
case 'leave': case 'leave':
if (ev.getSender() === ev.getStateKey()) { if (ev.getSender() === ev.getStateKey()) {
return targetName + " left the room."; return targetName + " left the room.";

View File

@ -46,7 +46,28 @@ module.exports = {
} }
}, },
uploadNewAvatar: function() { setAvatarFromFile: function(file) {
var newUrl = null;
this.setState({
phase: this.Phases.Uploading
});
var self = this;
MatrixClientPeg.get().uploadContent(file).then(function(url) {
newUrl = url;
return MatrixClientPeg.get().setProfileInfo('avatar_url', {
avatar_url: url
});
}).done(function() {
self.setState({
phase: self.Phases.Display,
avatarUrl: MatrixClientPeg.get().mxcUrlToHttp(newUrl)
});
}, function(error) {
self.setState({
phase: this.Phases.Error
});
self.onError(error);
});
}, },
} }