Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into feature-autocomplete

pull/21833/head
Aviral Dasgupta 2016-06-21 04:09:22 +05:30
commit 442291c0a4
7 changed files with 122 additions and 23 deletions

View File

@ -16,21 +16,13 @@ limitations under the License.
module.exports = { module.exports = {
/** /**
* Given a room object, return the canonical alias for it * Given a room object, return the alias we should use for it,
* if there is one. Otherwise return null; * if any. This could be the canonical alias if one exists, otherwise
* an alias selected arbitrarily but deterministically from the list
* of aliases. Otherwise return null;
*/ */
getCanonicalAliasForRoom: function(room) { getDisplayAliasForRoom: function(room) {
var aliasEvents = room.currentState.getStateEvents( return room.getCanonicalAlias() || room.getAliases()[0];
"m.room.aliases"
);
// Canonical aliases aren't implemented yet, so just return the first
for (var j = 0; j < aliasEvents.length; j++) {
var aliases = aliasEvents[j].getContent().aliases;
if (aliases && aliases.length) {
return aliases[0];
}
}
return null;
}, },
/** /**

View File

@ -539,7 +539,7 @@ module.exports = React.createClass({
var presentedId = roomAlias || roomId; var presentedId = roomAlias || roomId;
var room = MatrixClientPeg.get().getRoom(roomId); var room = MatrixClientPeg.get().getRoom(roomId);
if (room) { if (room) {
var theAlias = MatrixTools.getCanonicalAliasForRoom(room); var theAlias = MatrixTools.getDisplayAliasForRoom(room);
if (theAlias) presentedId = theAlias; if (theAlias) presentedId = theAlias;
// No need to do this given RoomView triggers it itself... // No need to do this given RoomView triggers it itself...
@ -631,7 +631,7 @@ module.exports = React.createClass({
var presentedId = self.state.currentRoomId; var presentedId = self.state.currentRoomId;
var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId); var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId);
if (room) { if (room) {
var theAlias = MatrixTools.getCanonicalAliasForRoom(room); var theAlias = MatrixTools.getDisplayAliasForRoom(room);
if (theAlias) presentedId = theAlias; if (theAlias) presentedId = theAlias;
} }

View File

@ -20,7 +20,7 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
var Modal = require('../../Modal'); var Modal = require('../../Modal');
var dis = require("../../dispatcher"); var dis = require("../../dispatcher");
var q = require('q'); var q = require('q');
var version = require('../../../package.json').version; var package_json = require('../../../package.json');
var UserSettingsStore = require('../../UserSettingsStore'); var UserSettingsStore = require('../../UserSettingsStore');
var GeminiScrollbar = require('react-gemini-scrollbar'); var GeminiScrollbar = require('react-gemini-scrollbar');
var Email = require('../../email'); var Email = require('../../email');
@ -37,6 +37,11 @@ const LABS_FEATURES = [
} }
]; ];
// if this looks like a release, use the 'version' from package.json; else use
// the git sha.
const REACT_SDK_VERSION =
'dist' in package_json ? package_json.version : package_json.gitHead || "<local>";
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'UserSettings', displayName: 'UserSettings',
@ -57,7 +62,6 @@ module.exports = React.createClass({
return { return {
avatarUrl: null, avatarUrl: null,
threePids: [], threePids: [],
clientVersion: version,
phase: "UserSettings.LOADING", // LOADING, DISPLAY phase: "UserSettings.LOADING", // LOADING, DISPLAY
email_add_pending: false, email_add_pending: false,
}; };
@ -465,7 +469,7 @@ module.exports = React.createClass({
Identity Server is { MatrixClientPeg.get().getIdentityServerUrl() } Identity Server is { MatrixClientPeg.get().getIdentityServerUrl() }
</div> </div>
<div className="mx_UserSettings_advanced"> <div className="mx_UserSettings_advanced">
matrix-react-sdk version: {this.state.clientVersion}<br/> matrix-react-sdk version: {REACT_SDK_VERSION}<br/>
vector-web version: {this.props.version}<br/> vector-web version: {this.props.version}<br/>
</div> </div>
</div> </div>

View File

@ -25,8 +25,15 @@ module.exports = React.createClass({
}, },
onVerifyClick: function() { onVerifyClick: function() {
MatrixClientPeg.get().setDeviceVerified(this.props.userId, MatrixClientPeg.get().setDeviceVerified(
this.props.device.id); this.props.userId, this.props.device.id, true
);
},
onUnverifyClick: function() {
MatrixClientPeg.get().setDeviceVerified(
this.props.userId, this.props.device.id, false
);
}, },
render: function() { render: function() {
@ -35,9 +42,15 @@ module.exports = React.createClass({
indicator = ( indicator = (
<div className="mx_MemberDeviceInfo_verified">&#x2714;</div> <div className="mx_MemberDeviceInfo_verified">&#x2714;</div>
); );
button = (
<div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_unverify"
onClick={this.onUnverifyClick}>
Unverify
</div>
);
} else { } else {
button = ( button = (
<div className="mx_MemberDeviceInfo_textButton" <div className="mx_MemberDeviceInfo_textButton mx_MemberDeviceInfo_verify"
onClick={this.onVerifyClick}> onClick={this.onVerifyClick}>
Verify Verify
</div> </div>

View File

@ -0,0 +1,73 @@
var React = require('react');
var expect = require('expect');
var sinon = require('sinon');
var ReactDOM = require("react-dom");
var sdk = require('matrix-react-sdk');
var RoomView = sdk.getComponent('structures.RoomView');
var peg = require('../../../src/MatrixClientPeg');
var test_utils = require('../../test-utils');
var q = require('q');
var Skinner = require("../../../src/Skinner");
var stubComponent = require('../../components/stub-component.js');
describe('RoomView', function () {
var sandbox;
var parentDiv;
beforeEach(function() {
sandbox = test_utils.stubClient();
parentDiv = document.createElement('div');
this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel');
this.oldRoomHeader = Skinner.getComponent('views.rooms.RoomHeader');
Skinner.addComponent('structures.TimelinePanel', stubComponent());
Skinner.addComponent('views.rooms.RoomHeader', stubComponent());
peg.get().credentials = { userId: "@test:example.com" };
});
afterEach(function() {
sandbox.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel);
Skinner.addComponent('views.rooms.RoomHeader', this.oldRoomHeader);
});
it('resolves a room alias to a room id', function (done) {
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
var onRoomIdResolved = sinon.spy();
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
process.nextTick(function() {
// These expect()s don't read very well and don't give very good failure
// messages, but expect's toHaveBeenCalled only takes an expect spy object,
// not a sinon spy object.
expect(onRoomIdResolved.called).toExist();
done();
});
});
it('joins by alias if given an alias', function (done) {
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
peg.get().getProfileInfo.returns(q({displayname: "foo"}));
var parentDiv = document.createElement('div');
var roomView = ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" />, parentDiv);
peg.get().joinRoom = sinon.spy();
process.nextTick(function() {
roomView.onJoinButtonClicked();
process.nextTick(function() {
expect(peg.get().joinRoom.calledWith('#alias:ser.ver')).toExist();
done();
});
});
});
});

View File

@ -29,6 +29,7 @@ components['views.elements.Spinner'] = stubComponent({displayName: 'Spinner'});
components['views.messages.DateSeparator'] = stubComponent({displayName: 'DateSeparator'}); components['views.messages.DateSeparator'] = stubComponent({displayName: 'DateSeparator'});
components['views.messages.MessageTimestamp'] = stubComponent({displayName: 'MessageTimestamp'}); components['views.messages.MessageTimestamp'] = stubComponent({displayName: 'MessageTimestamp'});
components['views.messages.SenderProfile'] = stubComponent({displayName: 'SenderProfile'}); components['views.messages.SenderProfile'] = stubComponent({displayName: 'SenderProfile'});
components['views.rooms.SearchBar'] = stubComponent();
sdk.loadSkin(skin); sdk.loadSkin(skin);

View File

@ -34,13 +34,16 @@ module.exports.stubClient = function() {
getIdentityServerUrl: sinon.stub(), getIdentityServerUrl: sinon.stub(),
getPushActionsForEvent: sinon.stub(), getPushActionsForEvent: sinon.stub(),
getRoom: sinon.stub(), getRoom: sinon.stub().returns(this.mkStubRoom()),
getRooms: sinon.stub().returns([]),
loginFlows: sinon.stub(), loginFlows: sinon.stub(),
on: sinon.stub(), on: sinon.stub(),
removeListener: sinon.stub(), removeListener: sinon.stub(),
paginateEventTimeline: sinon.stub().returns(q()), paginateEventTimeline: sinon.stub().returns(q()),
sendReadReceipt: sinon.stub().returns(q()), sendReadReceipt: sinon.stub().returns(q()),
getRoomIdForAlias: sinon.stub().returns(q()),
getProfileInfo: sinon.stub().returns(q({})),
}; };
// stub out the methods in MatrixClientPeg // stub out the methods in MatrixClientPeg
@ -169,3 +172,16 @@ module.exports.mkMessage = function(opts) {
}; };
return module.exports.mkEvent(opts); return module.exports.mkEvent(opts);
}; };
module.exports.mkStubRoom = function() {
return {
getReceiptsForEvent: sinon.stub().returns([]),
getMember: sinon.stub().returns({}),
getJoinedMembers: sinon.stub().returns([]),
currentState: {
getStateEvents: sinon.stub(),
members: [],
},
};
};