From 7048d85246200aefa04dfa4bfbc8d1aa8b31836a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Feb 2018 23:42:04 +0000 Subject: [PATCH] attach message_sent and replies to file uploads Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/ContentMessages.js | 6 +++--- src/components/structures/RoomView.js | 13 ++++++++--- src/components/views/elements/Reply.js | 30 +++++++++++--------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index 8d40b65124..f0e8736aba 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -275,13 +275,13 @@ class ContentMessages { this.nextId = 0; } - sendContentToRoom(file, roomId, matrixClient) { - const content = { + sendContentToRoom(file, roomId, matrixClient, baseContent) { + const content = Object.assign({}, baseContent, { body: file.name || 'Attachment', info: { size: file.size, }, - }; + }); // if we have a mime type for the file, add it to the message metadata if (file.type) { diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 5304f38901..869dffcf9b 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -45,6 +45,7 @@ import { KeyCode, isOnlyCtrlOrCmdKeyEvent } from '../../Keyboard'; import RoomViewStore from '../../stores/RoomViewStore'; import RoomScrollStateStore from '../../stores/RoomScrollStateStore'; import SettingsStore from "../../settings/SettingsStore"; +import Reply from "../views/elements/Reply"; const DEBUG = false; let debuglog = function() {}; @@ -895,11 +896,17 @@ module.exports = React.createClass({ return; } + const baseContent = Reply.getMRelatesTo(RoomViewStore.getQuotingEvent()); + ContentMessages.sendContentToRoom( - file, this.state.room.roomId, MatrixClientPeg.get(), - ).done(undefined, (error) => { + file, this.state.room.roomId, MatrixClientPeg.get(), baseContent, + ).done(() => { + dis.dispatch({ + action: 'message_sent', + }); + }, (error) => { if (error.name === "UnknownDeviceError") { - // Let the staus bar handle this + // Let the status bar handle this return; } const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); diff --git a/src/components/views/elements/Reply.js b/src/components/views/elements/Reply.js index 67e6b9d9ca..5b213690cc 100644 --- a/src/components/views/elements/Reply.js +++ b/src/components/views/elements/Reply.js @@ -56,7 +56,7 @@ export default class Reply extends React.Component { componentWillMount() { this.unmounted = false; - this.room = this.getRoom(this.props.parentEv.getRoomId()); + this.room = MatrixClientPeg.get().getRoom(this.props.parentEv.getRoomId()); this.initialize(); } @@ -67,8 +67,12 @@ export default class Reply extends React.Component { async initialize() { const {parentEv} = this.props; const inReplyTo = Reply.getInReplyTo(parentEv); + if (!inReplyTo) { + this.setState({err: true}); + return; + } - const ev = await this.getEvent(this.room, inReplyTo['event_id']); + const ev = await Reply.getEvent(this.room, inReplyTo['event_id']); if (this.unmounted) return; if (ev) { @@ -81,18 +85,18 @@ export default class Reply extends React.Component { } async loadNextEvent() { + if (this.unmounted) return; const ev = this.state.events[0]; const inReplyTo = Reply.getInReplyTo(ev); if (!inReplyTo) { - if (this.unmounted) return; this.setState({ loading: false, }, this.props.onWidgetLoad); return; } - const loadedEv = await this.getEvent(this.room, inReplyTo['event_id']); + const loadedEv = await Reply.getEvent(this.room, inReplyTo['event_id']); if (this.unmounted) return; if (loadedEv) { @@ -102,23 +106,14 @@ export default class Reply extends React.Component { } } - getRoom(id) { - const cli = MatrixClientPeg.get(); - if (id[0] === '!') return cli.getRoom(id); - - return cli.getRooms().find((r) => { - return r.getAliases().includes(id); - }); - } - - async getEvent(room, eventId) { + static async getEvent(room, eventId) { const event = room.findEventById(eventId); if (event) return event; try { await MatrixClientPeg.get().getEventTimeline(room.getUnfilteredTimelineSet(), eventId); } catch (e) { - return; + return null; } return room.findEventById(eventId); } @@ -144,7 +139,8 @@ export default class Reply extends React.Component { } } - static getRelationship(ev) { + static getMRelatesTo(ev) { + if (!ev) return {}; return { 'm.relates_to': { 'm.in_reply_to': { @@ -155,7 +151,7 @@ export default class Reply extends React.Component { } static getQuote(parentEv, onWidgetLoad) { - if (!SettingsStore.isFeatureEnabled("feature_rich_quoting") || !Reply.getInReplyTo(parentEv)) return null; + if (!SettingsStore.isFeatureEnabled("feature_rich_quoting") || !Reply.getInReplyTo(parentEv)) return
; return ; }