Make ChangeAvatar support room avatars and tweak RoomAvatar respond to componentWillReceiveProps

pull/21833/head
David Baker 2015-10-23 17:34:11 +01:00
parent 03dfd57a79
commit 5a760b71d0
3 changed files with 31 additions and 5 deletions

View File

@ -34,13 +34,24 @@ module.exports = {
}, },
getInitialState: function() { getInitialState: function() {
this.urlList = this.getUrlList(); this._update();
this.urlListIndex = -1;
return { return {
imageUrl: this._nextUrl() imageUrl: this._nextUrl()
}; };
}, },
componentWillReceiveProps: function(nextProps) {
this._update();
this.setState({
imageUrl: this._nextUrl()
});
},
_update: function() {
this.urlList = this.getUrlList();
this.urlListIndex = -1;
},
_nextUrl: function() { _nextUrl: function() {
do { do {
++this.urlListIndex; ++this.urlListIndex;

View File

@ -19,7 +19,8 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
module.exports = { module.exports = {
propTypes: { propTypes: {
initialAvatarUrl: React.PropTypes.string.isRequired, initialAvatarUrl: React.PropTypes.string,
room: React.PropTypes.object,
}, },
Phases: { Phases: {
@ -44,7 +45,16 @@ module.exports = {
var self = this; var self = this;
MatrixClientPeg.get().uploadContent(file).then(function(url) { MatrixClientPeg.get().uploadContent(file).then(function(url) {
newUrl = url; newUrl = url;
return MatrixClientPeg.get().setAvatarUrl(url); if (self.props.room) {
return MatrixClientPeg.get().sendStateEvent(
self.props.room.roomId,
'm.room.avatar',
{url: url},
''
);
} else {
return MatrixClientPeg.get().setAvatarUrl(url);
}
}).done(function() { }).done(function() {
self.setState({ self.setState({
phase: self.Phases.Display, phase: self.Phases.Display,
@ -52,7 +62,7 @@ module.exports = {
}); });
}, function(error) { }, function(error) {
self.setState({ self.setState({
phase: this.Phases.Error phase: self.Phases.Error
}); });
self.onError(error); self.onError(error);
}); });

View File

@ -28,6 +28,7 @@ module.exports = {
cli.on("Room", this.onRoom); cli.on("Room", this.onRoom);
cli.on("Room.timeline", this.onRoomTimeline); cli.on("Room.timeline", this.onRoomTimeline);
cli.on("Room.name", this.onRoomName); cli.on("Room.name", this.onRoomName);
cli.on("RoomState.events", this.onRoomStateEvents);
var rooms = this.getRoomList(); var rooms = this.getRoomList();
this.setState({ this.setState({
@ -84,6 +85,10 @@ module.exports = {
this.refreshRoomList(); this.refreshRoomList();
}, },
onRoomStateEvents: function(ev, state) {
this.refreshRoomList();
},
refreshRoomList: function() { refreshRoomList: function() {
var rooms = this.getRoomList(); var rooms = this.getRoomList();
this.setState({ this.setState({