Add Reply in thread
button to the right-click message context-menu (#9004)
This commit is contained in:
parent
dfa844a035
commit
787ace9dc5
13 changed files with 236 additions and 56 deletions
|
@ -16,12 +16,13 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { createRef } from 'react';
|
||||
import React, { createRef, useContext } from 'react';
|
||||
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
|
||||
import { Relations } from 'matrix-js-sdk/src/models/relations';
|
||||
import { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
|
||||
import { M_POLL_START } from "matrix-events-sdk";
|
||||
import { Thread } from "matrix-js-sdk/src/models/thread";
|
||||
|
||||
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
||||
import dis from '../../../dispatcher/dispatcher';
|
||||
|
@ -58,6 +59,59 @@ import { OpenReportEventDialogPayload } from "../../../dispatcher/payloads/OpenR
|
|||
import { createMapSiteLinkFromEvent } from '../../../utils/location';
|
||||
import { getForwardableEvent } from '../../../events/forward/getForwardableEvent';
|
||||
import { getShareableLocationEvent } from '../../../events/location/getShareableLocationEvent';
|
||||
import { ShowThreadPayload } from "../../../dispatcher/payloads/ShowThreadPayload";
|
||||
import { CardContext } from "../right_panel/context";
|
||||
import { UserTab } from "../dialogs/UserTab";
|
||||
|
||||
interface IReplyInThreadButton {
|
||||
mxEvent: MatrixEvent;
|
||||
closeMenu: () => void;
|
||||
}
|
||||
|
||||
const ReplyInThreadButton = ({ mxEvent, closeMenu }: IReplyInThreadButton) => {
|
||||
const context = useContext(CardContext);
|
||||
const relationType = mxEvent?.getRelation()?.rel_type;
|
||||
|
||||
// Can't create a thread from an event with an existing relation
|
||||
if (Boolean(relationType) && relationType !== RelationType.Thread) return;
|
||||
|
||||
const onClick = (): void => {
|
||||
if (!localStorage.getItem("mx_seen_feature_thread")) {
|
||||
localStorage.setItem("mx_seen_feature_thread", "true");
|
||||
}
|
||||
|
||||
if (!SettingsStore.getValue("feature_thread")) {
|
||||
dis.dispatch({
|
||||
action: Action.ViewUserSettings,
|
||||
initialTabId: UserTab.Labs,
|
||||
});
|
||||
} else if (mxEvent.getThread() && !mxEvent.isThreadRoot) {
|
||||
dis.dispatch<ShowThreadPayload>({
|
||||
action: Action.ShowThread,
|
||||
rootEvent: mxEvent.getThread().rootEvent,
|
||||
initialEvent: mxEvent,
|
||||
scroll_into_view: true,
|
||||
highlighted: true,
|
||||
push: context.isCard,
|
||||
});
|
||||
} else {
|
||||
dis.dispatch<ShowThreadPayload>({
|
||||
action: Action.ShowThread,
|
||||
rootEvent: mxEvent,
|
||||
push: context.isCard,
|
||||
});
|
||||
}
|
||||
closeMenu();
|
||||
};
|
||||
|
||||
return (
|
||||
<IconizedContextMenuOption
|
||||
iconClassName="mx_MessageContextMenu_iconReplyInThread"
|
||||
label={_t("Reply in thread")}
|
||||
onClick={onClick}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
interface IProps extends IPosition {
|
||||
chevronFace: ChevronFace;
|
||||
|
@ -582,6 +636,23 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
|
|||
);
|
||||
}
|
||||
|
||||
let replyInThreadButton: JSX.Element;
|
||||
if (
|
||||
rightClick &&
|
||||
contentActionable &&
|
||||
canSendMessages &&
|
||||
SettingsStore.getValue("feature_thread") &&
|
||||
Thread.hasServerSideSupport &&
|
||||
timelineRenderingType !== TimelineRenderingType.Thread
|
||||
) {
|
||||
replyInThreadButton = (
|
||||
<ReplyInThreadButton
|
||||
mxEvent={mxEvent}
|
||||
closeMenu={this.closeMenu}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
let reactButton;
|
||||
if (rightClick && contentActionable && canReact) {
|
||||
reactButton = (
|
||||
|
@ -621,6 +692,7 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
|
|||
<IconizedContextMenuOptionList>
|
||||
{ reactButton }
|
||||
{ replyButton }
|
||||
{ replyInThreadButton }
|
||||
{ editButton }
|
||||
</IconizedContextMenuOptionList>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue