Merge branch 'develop' into luke/feature-mention-pill

This commit is contained in:
Luke Barnard 2017-07-19 17:22:03 +01:00 committed by GitHub
commit 5d1b33d2a8
5 changed files with 24 additions and 26 deletions

View file

@ -178,27 +178,27 @@ module.exports = React.createClass({
const href = node.getAttribute("href");
// HtmlUtils transforms `matrix.to` links to local links, so match against
// user or room app links.
const match = /^#\/(user|room)\/(.*)$/.exec(href);
if (match) {
const match = /^#\/(user|room)\/(.*)$/.exec(href) || [];
const resourceType = match[1]; // "user" or "room"
const resourceId = match[2]; // user ID or room ID
if (match && resourceType && resourceId) {
let avatar;
let roomId;
let room;
let userId;
let member;
switch (match[1]) {
switch (resourceType) {
case "user":
roomId = this.props.mxEvent.getRoomId();
room = MatrixClientPeg.get().getRoom(roomId);
userId = match[2];
member = room.getMember(userId) ||
new RoomMember(null, userId);
avatar = <MemberAvatar member={member} width={16} height={16} name={match[2]}/>;
member = room.getMember(resourceId) ||
new RoomMember(null, resourceId);
avatar = <MemberAvatar member={member} width={16} height={16} name={resourceId}/>;
break;
case "room":
room = match[2][0] === '#' ?
room = resourceId[0] === '#' ?
MatrixClientPeg.get().getRooms().find((r) => {
return r.getCanonicalAlias() === match[2];
}) : MatrixClientPeg.get().getRoom(match[2]);
return r.getCanonicalAlias() === resourceId;
}) : MatrixClientPeg.get().getRoom(resourceId);
if (room) {
avatar = <RoomAvatar room={room} width={16} height={16}/>;
}

View file

@ -535,16 +535,19 @@ export default class MessageComposerInput extends React.Component {
if (this.state.isRichtextEnabled) {
// These are block types, not handled by RichUtils by default.
const blockCommands = ['code-block', 'blockquote', 'unordered-list-item', 'ordered-list-item'];
const currentBlockType = RichUtils.getCurrentBlockType(this.state.editorState);
if (blockCommands.includes(command)) {
this.setState({
editorState: RichUtils.toggleBlockType(this.state.editorState, command),
});
newState = RichUtils.toggleBlockType(this.state.editorState, command);
} else if (command === 'strike') {
// this is the only inline style not handled by Draft by default
this.setState({
editorState: RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH'),
});
newState = RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH');
} else if (command === 'backspace' && currentBlockType !== 'unstyled') {
const currentStartOffset = this.state.editorState.getSelection().getStartOffset();
if (currentStartOffset === 0) {
// Toggle current block type (setting it to 'unstyled')
newState = RichUtils.toggleBlockType(this.state.editorState, currentBlockType);
}
}
} else {
let contentState = this.state.editorState.getCurrentContent();
@ -651,6 +654,7 @@ export default class MessageComposerInput extends React.Component {
// By returning false, we allow the default draft-js key binding to occur,
// which in this case invokes "split-block". This creates a new block of the
// same type, allowing the user to delete it with backspace.
// See handleKeyCommand (when command === 'backspace')
return false;
}