Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Don't show edit button for hidden edit events (#7226)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 1, 2021
1 parent 82c125c commit 5ba2d16
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/EventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixEvent, EventStatus } from 'matrix-js-sdk/src/models/event';
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';

import { MatrixClientPeg } from '../MatrixClientPeg';
import shouldHideEvent from "../shouldHideEvent";
import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile";
import SettingsStore from "../settings/SettingsStore";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
import { MatrixClient } from 'matrix-js-sdk/src/client';
import { Thread } from 'matrix-js-sdk/src/models/thread';
import { logger } from 'matrix-js-sdk/src/logger';
Expand Down Expand Up @@ -55,14 +55,17 @@ export function isContentActionable(mxEvent: MatrixEvent): boolean {
}

export function canEditContent(mxEvent: MatrixEvent): boolean {
if (mxEvent.status === EventStatus.CANCELLED || mxEvent.getType() !== "m.room.message" || mxEvent.isRedacted()) {
if (mxEvent.status === EventStatus.CANCELLED ||
mxEvent.getType() !== EventType.RoomMessage ||
mxEvent.isRedacted() ||
mxEvent.isRelation(RelationType.Replace) ||
mxEvent.getSender() !== MatrixClientPeg.get().getUserId()
) {
return false;
}
const content = mxEvent.getOriginalContent();
const { msgtype } = content;
return (msgtype === "m.text" || msgtype === "m.emote") &&
content.body && typeof content.body === 'string' &&
mxEvent.getSender() === MatrixClientPeg.get().getUserId();

const { msgtype, body } = mxEvent.getOriginalContent();
return (msgtype === MsgType.Text || msgtype === MsgType.Emote) && body && typeof body === 'string';
}

export function canEditOwnEvent(mxEvent: MatrixEvent): boolean {
Expand Down

0 comments on commit 5ba2d16

Please sign in to comment.