attach message_sent and replies to file uploads

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-02-19 23:42:04 +00:00
parent 34b427d15e
commit 7048d85246
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E
3 changed files with 26 additions and 23 deletions

View file

@ -275,13 +275,13 @@ class ContentMessages {
this.nextId = 0; this.nextId = 0;
} }
sendContentToRoom(file, roomId, matrixClient) { sendContentToRoom(file, roomId, matrixClient, baseContent) {
const content = { const content = Object.assign({}, baseContent, {
body: file.name || 'Attachment', body: file.name || 'Attachment',
info: { info: {
size: file.size, size: file.size,
}, },
}; });
// if we have a mime type for the file, add it to the message metadata // if we have a mime type for the file, add it to the message metadata
if (file.type) { if (file.type) {

View file

@ -45,6 +45,7 @@ import { KeyCode, isOnlyCtrlOrCmdKeyEvent } from '../../Keyboard';
import RoomViewStore from '../../stores/RoomViewStore'; import RoomViewStore from '../../stores/RoomViewStore';
import RoomScrollStateStore from '../../stores/RoomScrollStateStore'; import RoomScrollStateStore from '../../stores/RoomScrollStateStore';
import SettingsStore from "../../settings/SettingsStore"; import SettingsStore from "../../settings/SettingsStore";
import Reply from "../views/elements/Reply";
const DEBUG = false; const DEBUG = false;
let debuglog = function() {}; let debuglog = function() {};
@ -895,11 +896,17 @@ module.exports = React.createClass({
return; return;
} }
const baseContent = Reply.getMRelatesTo(RoomViewStore.getQuotingEvent());
ContentMessages.sendContentToRoom( ContentMessages.sendContentToRoom(
file, this.state.room.roomId, MatrixClientPeg.get(), file, this.state.room.roomId, MatrixClientPeg.get(), baseContent,
).done(undefined, (error) => { ).done(() => {
dis.dispatch({
action: 'message_sent',
});
}, (error) => {
if (error.name === "UnknownDeviceError") { if (error.name === "UnknownDeviceError") {
// Let the staus bar handle this // Let the status bar handle this
return; return;
} }
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");

View file

@ -56,7 +56,7 @@ export default class Reply extends React.Component {
componentWillMount() { componentWillMount() {
this.unmounted = false; this.unmounted = false;
this.room = this.getRoom(this.props.parentEv.getRoomId()); this.room = MatrixClientPeg.get().getRoom(this.props.parentEv.getRoomId());
this.initialize(); this.initialize();
} }
@ -67,8 +67,12 @@ export default class Reply extends React.Component {
async initialize() { async initialize() {
const {parentEv} = this.props; const {parentEv} = this.props;
const inReplyTo = Reply.getInReplyTo(parentEv); 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 (this.unmounted) return;
if (ev) { if (ev) {
@ -81,18 +85,18 @@ export default class Reply extends React.Component {
} }
async loadNextEvent() { async loadNextEvent() {
if (this.unmounted) return;
const ev = this.state.events[0]; const ev = this.state.events[0];
const inReplyTo = Reply.getInReplyTo(ev); const inReplyTo = Reply.getInReplyTo(ev);
if (!inReplyTo) { if (!inReplyTo) {
if (this.unmounted) return;
this.setState({ this.setState({
loading: false, loading: false,
}, this.props.onWidgetLoad); }, this.props.onWidgetLoad);
return; 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 (this.unmounted) return;
if (loadedEv) { if (loadedEv) {
@ -102,23 +106,14 @@ export default class Reply extends React.Component {
} }
} }
getRoom(id) { static async getEvent(room, eventId) {
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) {
const event = room.findEventById(eventId); const event = room.findEventById(eventId);
if (event) return event; if (event) return event;
try { try {
await MatrixClientPeg.get().getEventTimeline(room.getUnfilteredTimelineSet(), eventId); await MatrixClientPeg.get().getEventTimeline(room.getUnfilteredTimelineSet(), eventId);
} catch (e) { } catch (e) {
return; return null;
} }
return room.findEventById(eventId); 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 { return {
'm.relates_to': { 'm.relates_to': {
'm.in_reply_to': { 'm.in_reply_to': {
@ -155,7 +151,7 @@ export default class Reply extends React.Component {
} }
static getQuote(parentEv, onWidgetLoad) { 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 <div />;
return <Reply parentEv={parentEv} onWidgetLoad={onWidgetLoad} />; return <Reply parentEv={parentEv} onWidgetLoad={onWidgetLoad} />;
} }