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

pull/21833/head
Jaiwanth 2021-07-02 16:58:04 +05:30
commit 8c6f801486
5 changed files with 38 additions and 27 deletions

View File

@ -15,6 +15,7 @@ limitations under the License.
*/ */
import classNames from 'classnames'; import classNames from 'classnames';
import { SERVICE_TYPES } from 'matrix-js-sdk/src/service-types';
import { MatrixClientPeg } from './MatrixClientPeg'; import { MatrixClientPeg } from './MatrixClientPeg';
import * as sdk from '.'; import * as sdk from '.';
@ -32,7 +33,7 @@ export class Service {
* @param {string} baseUrl The Base URL of the service (ie. before '/_matrix') * @param {string} baseUrl The Base URL of the service (ie. before '/_matrix')
* @param {string} accessToken The user's access token for the service * @param {string} accessToken The user's access token for the service
*/ */
constructor(public serviceType: string, public baseUrl: string, public accessToken: string) { constructor(public serviceType: SERVICE_TYPES, public baseUrl: string, public accessToken: string) {
} }
} }

View File

@ -19,6 +19,7 @@ import React from 'react';
import { Filter } from 'matrix-js-sdk/src/filter'; import { Filter } from 'matrix-js-sdk/src/filter';
import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set"; import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set";
import { Direction } from "matrix-js-sdk/src/models/event-timeline";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from 'matrix-js-sdk/src/models/room'; import { Room } from 'matrix-js-sdk/src/models/room';
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window'; import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
@ -129,7 +130,7 @@ class FilePanel extends React.Component<IProps, IState> {
} }
} }
public async fetchFileEventsServer(room: Room): Promise<void> { public async fetchFileEventsServer(room: Room): Promise<EventTimelineSet> {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const filter = new Filter(client.credentials.userId); const filter = new Filter(client.credentials.userId);
@ -153,7 +154,11 @@ class FilePanel extends React.Component<IProps, IState> {
return timelineSet; return timelineSet;
} }
private onPaginationRequest = (timelineWindow: TimelineWindow, direction: string, limit: number): void => { private onPaginationRequest = (
timelineWindow: TimelineWindow,
direction: Direction,
limit: number,
): Promise<boolean> => {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const eventIndex = EventIndexPeg.get(); const eventIndex = EventIndexPeg.get();
const roomId = this.props.roomId; const roomId = this.props.roomId;

View File

@ -16,11 +16,13 @@ limitations under the License.
import React, { createRef, ReactNode, SyntheticEvent } from 'react'; import React, { createRef, ReactNode, SyntheticEvent } from 'react';
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { Room } from "matrix-js-sdk/src/models/room"; import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { TimelineSet } from "matrix-js-sdk/src/models/event-timeline-set"; import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set";
import { EventTimeline } from "matrix-js-sdk/src/models/event-timeline"; import { Direction, EventTimeline } from "matrix-js-sdk/src/models/event-timeline";
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window"; import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { SyncState } from 'matrix-js-sdk/src/sync.api';
import SettingsStore from "../../settings/SettingsStore"; import SettingsStore from "../../settings/SettingsStore";
import { Layout } from "../../settings/Layout"; import { Layout } from "../../settings/Layout";
@ -39,10 +41,8 @@ import { UIFeature } from "../../settings/UIFeature";
import { replaceableComponent } from "../../utils/replaceableComponent"; import { replaceableComponent } from "../../utils/replaceableComponent";
import { arrayFastClone } from "../../utils/arrays"; import { arrayFastClone } from "../../utils/arrays";
import MessagePanel from "./MessagePanel"; import MessagePanel from "./MessagePanel";
import { SyncState } from 'matrix-js-sdk/src/sync.api';
import { IScrollState } from "./ScrollPanel"; import { IScrollState } from "./ScrollPanel";
import { ActionPayload } from "../../dispatcher/payloads"; import { ActionPayload } from "../../dispatcher/payloads";
import { EventType } from 'matrix-js-sdk/src/@types/event';
import ResizeNotifier from "../../utils/ResizeNotifier"; import ResizeNotifier from "../../utils/ResizeNotifier";
import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks"; import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
import Spinner from "../views/elements/Spinner"; import Spinner from "../views/elements/Spinner";
@ -65,7 +65,7 @@ interface IProps {
// representing. This may or may not have a room, depending on what it's // representing. This may or may not have a room, depending on what it's
// a timeline representing. If it has a room, we maintain RRs etc for // a timeline representing. If it has a room, we maintain RRs etc for
// that room. // that room.
timelineSet: TimelineSet; timelineSet: EventTimelineSet;
showReadReceipts?: boolean; showReadReceipts?: boolean;
// Enable managing RRs and RMs. These require the timelineSet to have a room. // Enable managing RRs and RMs. These require the timelineSet to have a room.
manageReadReceipts?: boolean; manageReadReceipts?: boolean;
@ -388,7 +388,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
private onPaginationRequest = ( private onPaginationRequest = (
timelineWindow: TimelineWindow, timelineWindow: TimelineWindow,
direction: string, direction: Direction,
size: number, size: number,
): Promise<boolean> => { ): Promise<boolean> => {
if (this.props.onPaginationRequest) { if (this.props.onPaginationRequest) {
@ -579,7 +579,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
}); });
}; };
private onRoomTimelineReset = (room: Room, timelineSet: TimelineSet): void => { private onRoomTimelineReset = (room: Room, timelineSet: EventTimelineSet): void => {
if (timelineSet !== this.props.timelineSet) return; if (timelineSet !== this.props.timelineSet) return;
if (this.messagePanel.current && this.messagePanel.current.isAtBottom()) { if (this.messagePanel.current && this.messagePanel.current.isAtBottom()) {
@ -792,8 +792,8 @@ class TimelinePanel extends React.Component<IProps, IState> {
// that sending an RR for the latest message will set our notif counter // that sending an RR for the latest message will set our notif counter
// to zero: it may not do this if we send an RR for somewhere before the end. // to zero: it may not do this if we send an RR for somewhere before the end.
if (this.isAtEndOfLiveTimeline()) { if (this.isAtEndOfLiveTimeline()) {
this.props.timelineSet.room.setUnreadNotificationCount('total', 0); this.props.timelineSet.room.setUnreadNotificationCount(NotificationCountType.Total, 0);
this.props.timelineSet.room.setUnreadNotificationCount('highlight', 0); this.props.timelineSet.room.setUnreadNotificationCount(NotificationCountType.Highlight, 0);
dis.dispatch({ dis.dispatch({
action: 'on_room_read', action: 'on_room_read',
roomId: this.props.timelineSet.room.roomId, roomId: this.props.timelineSet.room.roomId,
@ -1416,7 +1416,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
}); });
} }
private getRelationsForEvent = (...args) => this.props.timelineSet.getRelationsForEvent(...args); private getRelationsForEvent = (
eventId: string,
relationType: RelationType,
eventType: EventType | string,
) => this.props.timelineSet.getRelationsForEvent(eventId, relationType, eventType);
render() { render() {
// just show a spinner while the timeline loads. // just show a spinner while the timeline loads.

View File

@ -17,17 +17,19 @@ limitations under the License.
import React, { ClipboardEvent, createRef, KeyboardEvent } from 'react'; import React, { ClipboardEvent, createRef, KeyboardEvent } from 'react';
import EMOJI_REGEX from 'emojibase-regex'; import EMOJI_REGEX from 'emojibase-regex';
import { IContent, MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { IContent, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { DebouncedFunc, throttle } from 'lodash';
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
import dis from '../../../dispatcher/dispatcher'; import dis from '../../../dispatcher/dispatcher';
import EditorModel from '../../../editor/model'; import EditorModel from '../../../editor/model';
import { import {
htmlSerializeIfNeeded,
textSerialize,
containsEmote, containsEmote,
stripEmoteCommand, htmlSerializeIfNeeded,
unescapeMessage,
startsWith, startsWith,
stripEmoteCommand,
stripPrefix, stripPrefix,
textSerialize,
unescapeMessage,
} from '../../../editor/serialize'; } from '../../../editor/serialize';
import { CommandPartCreator, Part, PartCreator, SerializedPart } from '../../../editor/parts'; import { CommandPartCreator, Part, PartCreator, SerializedPart } from '../../../editor/parts';
import BasicMessageComposer from "./BasicMessageComposer"; import BasicMessageComposer from "./BasicMessageComposer";
@ -52,7 +54,6 @@ import { Room } from 'matrix-js-sdk/src/models/room';
import ErrorDialog from "../dialogs/ErrorDialog"; import ErrorDialog from "../dialogs/ErrorDialog";
import QuestionDialog from "../dialogs/QuestionDialog"; import QuestionDialog from "../dialogs/QuestionDialog";
import { ActionPayload } from "../../../dispatcher/payloads"; import { ActionPayload } from "../../../dispatcher/payloads";
import { DebouncedFunc, throttle } from 'lodash';
function addReplyToMessageContent( function addReplyToMessageContent(
content: IContent, content: IContent,
@ -258,12 +259,12 @@ export default class SendMessageComposer extends React.Component<IProps> {
const events = timeline.getEvents(); const events = timeline.getEvents();
const reaction = this.model.parts[1].text; const reaction = this.model.parts[1].text;
for (let i = events.length - 1; i >= 0; i--) { for (let i = events.length - 1; i >= 0; i--) {
if (events[i].getType() === "m.room.message") { if (events[i].getType() === EventType.RoomMessage) {
let shouldReact = true; let shouldReact = true;
const lastMessage = events[i]; const lastMessage = events[i];
const userId = MatrixClientPeg.get().getUserId(); const userId = MatrixClientPeg.get().getUserId();
const messageReactions = this.props.room.getUnfilteredTimelineSet() const messageReactions = this.props.room.getUnfilteredTimelineSet()
.getRelationsForEvent(lastMessage.getId(), "m.annotation", "m.reaction"); .getRelationsForEvent(lastMessage.getId(), RelationType.Annotation, EventType.Reaction);
// if we have already sent this reaction, don't redact but don't re-send // if we have already sent this reaction, don't redact but don't re-send
if (messageReactions) { if (messageReactions) {
@ -274,9 +275,9 @@ export default class SendMessageComposer extends React.Component<IProps> {
shouldReact = !myReactionKeys.includes(reaction); shouldReact = !myReactionKeys.includes(reaction);
} }
if (shouldReact) { if (shouldReact) {
MatrixClientPeg.get().sendEvent(lastMessage.getRoomId(), "m.reaction", { MatrixClientPeg.get().sendEvent(lastMessage.getRoomId(), EventType.Reaction, {
"m.relates_to": { "m.relates_to": {
"rel_type": "m.annotation", "rel_type": RelationType.Annotation,
"event_id": lastMessage.getId(), "event_id": lastMessage.getId(),
"key": reaction, "key": reaction,
}, },

View File

@ -16,7 +16,7 @@ limitations under the License.
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { RoomMember } from 'matrix-js-sdk/src/models/room-member'; import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline'; import { Direction, EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
import { Room } from 'matrix-js-sdk/src/models/room'; import { Room } from 'matrix-js-sdk/src/models/room';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set'; import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set';
@ -109,7 +109,7 @@ export default class EventIndex extends EventEmitter {
// our message crawler. // our message crawler.
await Promise.all(encryptedRooms.map(async (room) => { await Promise.all(encryptedRooms.map(async (room) => {
const timeline = room.getLiveTimeline(); const timeline = room.getLiveTimeline();
const token = timeline.getPaginationToken("b"); const token = timeline.getPaginationToken(Direction.Backward);
const backCheckpoint: ICrawlerCheckpoint = { const backCheckpoint: ICrawlerCheckpoint = {
roomId: room.roomId, roomId: room.roomId,
@ -371,7 +371,7 @@ export default class EventIndex extends EventEmitter {
if (!room) return; if (!room) return;
const timeline = room.getLiveTimeline(); const timeline = room.getLiveTimeline();
const token = timeline.getPaginationToken("b"); const token = timeline.getPaginationToken(Direction.Backward);
if (!token) { if (!token) {
// The room doesn't contain any tokens, meaning the live timeline // The room doesn't contain any tokens, meaning the live timeline
@ -862,7 +862,7 @@ export default class EventIndex extends EventEmitter {
* @returns {Promise<boolean>} Resolves to a boolean which is true if more * @returns {Promise<boolean>} Resolves to a boolean which is true if more
* events were successfully retrieved. * events were successfully retrieved.
*/ */
public paginateTimelineWindow(room: Room, timelineWindow: TimelineWindow, direction: string, limit: number) { public paginateTimelineWindow(room: Room, timelineWindow: TimelineWindow, direction: Direction, limit: number) {
const tl = timelineWindow.getTimelineIndex(direction); const tl = timelineWindow.getTimelineIndex(direction);
if (!tl) return Promise.resolve(false); if (!tl) return Promise.resolve(false);