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

Commit cb3145b

Browse files
authored
Revert "Move reaction message previews out of labs (#10601)"
This reverts commit 4dd2145.
1 parent 82e3203 commit cb3145b

File tree

8 files changed

+45
-167
lines changed

8 files changed

+45
-167
lines changed

src/components/views/context_menus/MessageContextMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ interface IProps extends MenuProps {
114114
// True if the menu is being used as a right click menu
115115
rightClick?: boolean;
116116
// The Relations model from the JS SDK for reactions to `mxEvent`
117-
reactions?: Relations | null;
117+
reactions?: Relations | null | undefined;
118118
// A permalink to this event or an href of an anchor element the user has clicked
119119
link?: string;
120120

@@ -556,7 +556,7 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
556556
}
557557

558558
let jumpToRelatedEventButton: JSX.Element | undefined;
559-
const relatedEventId = mxEvent.relationEventId;
559+
const relatedEventId = mxEvent.getWireContent()?.["m.relates_to"]?.event_id;
560560
if (relatedEventId && SettingsStore.getValue("developerMode")) {
561561
jumpToRelatedEventButton = (
562562
<IconizedContextMenuOption

src/i18n/strings/en_EN.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@
916916
"%(senderName)s is calling": "%(senderName)s is calling",
917917
"* %(senderName)s %(emote)s": "* %(senderName)s %(emote)s",
918918
"%(senderName)s: %(message)s": "%(senderName)s: %(message)s",
919-
"You reacted %(reaction)s to %(message)s": "You reacted %(reaction)s to %(message)s",
920-
"%(sender)s reacted %(reaction)s to %(message)s": "%(sender)s reacted %(reaction)s to %(message)s",
919+
"%(senderName)s: %(reaction)s": "%(senderName)s: %(reaction)s",
921920
"%(senderName)s: %(stickerName)s": "%(senderName)s: %(stickerName)s",
922921
"Threads": "Threads",
923922
"Back to chat": "Back to chat",
@@ -939,6 +938,7 @@
939938
"Voice & Video": "Voice & Video",
940939
"Moderation": "Moderation",
941940
"Analytics": "Analytics",
941+
"Message Previews": "Message Previews",
942942
"Themes": "Themes",
943943
"Encryption": "Encryption",
944944
"Experimental": "Experimental",
@@ -964,6 +964,8 @@
964964
"New ways to ignore people": "New ways to ignore people",
965965
"Currently experimental.": "Currently experimental.",
966966
"Support adding custom themes": "Support adding custom themes",
967+
"Show message previews for reactions in DMs": "Show message previews for reactions in DMs",
968+
"Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms",
967969
"Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices",
968970
"Show current avatar and name for users in message history": "Show current avatar and name for users in message history",
969971
"Show HTML representation of room topics": "Show HTML representation of room topics",

src/settings/Settings.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export enum LabGroup {
8484
VoiceAndVideo,
8585
Moderation,
8686
Analytics,
87+
MessagePreviews,
8788
Themes,
8889
Encryption,
8990
Experimental,
@@ -104,6 +105,7 @@ export const labGroupNames: Record<LabGroup, string> = {
104105
[LabGroup.VoiceAndVideo]: _td("Voice & Video"),
105106
[LabGroup.Moderation]: _td("Moderation"),
106107
[LabGroup.Analytics]: _td("Analytics"),
108+
[LabGroup.MessagePreviews]: _td("Message Previews"),
107109
[LabGroup.Themes]: _td("Themes"),
108110
[LabGroup.Encryption]: _td("Encryption"),
109111
[LabGroup.Experimental]: _td("Experimental"),
@@ -296,6 +298,22 @@ export const SETTINGS: { [setting: string]: ISetting } = {
296298
supportedLevels: LEVELS_FEATURE,
297299
default: false,
298300
},
301+
"feature_roomlist_preview_reactions_dms": {
302+
isFeature: true,
303+
labsGroup: LabGroup.MessagePreviews,
304+
displayName: _td("Show message previews for reactions in DMs"),
305+
supportedLevels: LEVELS_FEATURE,
306+
default: false,
307+
// this option is a subset of `feature_roomlist_preview_reactions_all` so disable it when that one is enabled
308+
controller: new IncompatibleController("feature_roomlist_preview_reactions_all"),
309+
},
310+
"feature_roomlist_preview_reactions_all": {
311+
isFeature: true,
312+
labsGroup: LabGroup.MessagePreviews,
313+
displayName: _td("Show message previews for reactions in all rooms"),
314+
supportedLevels: LEVELS_FEATURE,
315+
default: false,
316+
},
299317
"feature_dehydration": {
300318
isFeature: true,
301319
labsGroup: LabGroup.Encryption,

src/stores/room-list/previews/ReactionEventPreview.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,37 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1818

1919
import { IPreview } from "./IPreview";
2020
import { TagID } from "../models";
21-
import { getSenderName, isSelf } from "./utils";
21+
import { getSenderName, isSelf, shouldPrefixMessagesIn } from "./utils";
2222
import { _t } from "../../../languageHandler";
23-
import { MatrixClientPeg } from "../../../MatrixClientPeg";
24-
import { MessagePreviewStore } from "../MessagePreviewStore";
23+
import SettingsStore from "../../../settings/SettingsStore";
24+
import DMRoomMap from "../../../utils/DMRoomMap";
2525

2626
export class ReactionEventPreview implements IPreview {
2727
public getTextFor(event: MatrixEvent, tagId?: TagID, isThread?: boolean): string | null {
28+
const showDms = SettingsStore.getValue("feature_roomlist_preview_reactions_dms");
29+
const showAll = SettingsStore.getValue("feature_roomlist_preview_reactions_all");
30+
2831
const roomId = event.getRoomId();
2932
if (!roomId) return null; // not a room event
3033

34+
// If we're not showing all reactions, see if we're showing DMs instead
35+
if (!showAll) {
36+
// If we're not showing reactions on DMs, or we are and the room isn't a DM, skip
37+
if (!(showDms && DMRoomMap.shared().getUserIdForRoomId(roomId))) {
38+
return null;
39+
}
40+
}
41+
3142
const relation = event.getRelation();
3243
if (!relation) return null; // invalid reaction (probably redacted)
3344

3445
const reaction = relation.key;
3546
if (!reaction) return null; // invalid reaction (unknown format)
3647

37-
const cli = MatrixClientPeg.get();
38-
const room = cli?.getRoom(roomId);
39-
const relatedEvent = relation.event_id ? room?.findEventById(relation.event_id) : null;
40-
if (!relatedEvent) return null;
41-
42-
const message = MessagePreviewStore.instance.generatePreviewForEvent(relatedEvent);
43-
if (isSelf(event)) {
44-
return _t("You reacted %(reaction)s to %(message)s", {
45-
reaction,
46-
message,
47-
});
48+
if (isThread || isSelf(event) || !shouldPrefixMessagesIn(roomId, tagId)) {
49+
return reaction;
50+
} else {
51+
return _t("%(senderName)s: %(reaction)s", { senderName: getSenderName(event), reaction });
4852
}
49-
50-
return _t("%(sender)s reacted %(reaction)s to %(message)s", {
51-
sender: getSenderName(event),
52-
reaction,
53-
message,
54-
});
5553
}
5654
}

src/stores/room-list/previews/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg";
2020
import { DefaultTagID, TagID } from "../models";
2121

2222
export function isSelf(event: MatrixEvent): boolean {
23-
const selfUserId = MatrixClientPeg.get().getSafeUserId();
23+
const selfUserId = MatrixClientPeg.get().getUserId();
2424
if (event.getType() === "m.room.member") {
2525
return event.getStateKey() === selfUserId;
2626
}
@@ -37,5 +37,5 @@ export function shouldPrefixMessagesIn(roomId: string, tagId?: TagID): boolean {
3737
}
3838

3939
export function getSenderName(event: MatrixEvent): string {
40-
return event.sender?.name ?? event.getSender() ?? "";
40+
return event.sender ? event.sender.name : event.getSender() || "";
4141
}

test/components/views/settings/tabs/user/LabsUserSettingsTab-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("<LabsUserSettingsTab />", () => {
7070
const { container } = render(getComponent());
7171

7272
const labsSections = container.getElementsByClassName("mx_SettingsTab_section");
73-
expect(labsSections).toHaveLength(11);
73+
expect(labsSections).toHaveLength(12);
7474
});
7575

7676
it("allow setting a labs flag which requires unstable support once support is confirmed", async () => {

test/stores/room-list/previews/PollStartEventPreview-test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { makePollStartEvent } from "../../../test-utils";
2222

2323
jest.spyOn(MatrixClientPeg, "get").mockReturnValue({
2424
getUserId: () => "@me:example.com",
25-
getSafeUserId: () => "@me:example.com",
2625
} as unknown as MatrixClient);
2726

2827
describe("PollStartEventPreview", () => {

test/stores/room-list/previews/ReactionEventPreview-test.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)