mirror of https://github.com/vector-im/riot-web
Fix export of redacted polls (#8118)
* Move RequiresClient from MatrixCapabilities to ElementWidgetCapabilities Signed-off-by: Robin Kouwenhoven <r.kouwenhoven@outlook.com> * Fix export of redacted polls * Fix ESLint error * Add test cases for poll events * Add test cases for message events * Fix lint errors * Fix i18n error * Revert "Move RequiresClient from MatrixCapabilities to ElementWidgetCapabilities" This reverts commit 920f80a2d4385656925987ccc9d37420255405c1. Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Kerry <kerrya@element.io>pull/21833/head
parent
94385169f1
commit
7ba991cd8c
|
@ -317,16 +317,7 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null {
|
|||
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
||||
let message = ev.getContent().body;
|
||||
if (ev.isRedacted()) {
|
||||
message = _t("Message deleted");
|
||||
const unsigned = ev.getUnsigned();
|
||||
const redactedBecauseUserId = unsigned?.redacted_because?.sender;
|
||||
if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) {
|
||||
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
|
||||
const sender = room?.getMember(redactedBecauseUserId);
|
||||
message = _t("Message deleted by %(name)s", {
|
||||
name: sender?.name || redactedBecauseUserId,
|
||||
});
|
||||
}
|
||||
message = textForRedactedPollAndMessageEvent(ev);
|
||||
}
|
||||
|
||||
if (SettingsStore.isEnabled("feature_extensible_events")) {
|
||||
|
@ -727,11 +718,38 @@ export function textForLocationEvent(event: MatrixEvent): () => string | null {
|
|||
});
|
||||
}
|
||||
|
||||
function textForRedactedPollAndMessageEvent(ev: MatrixEvent): string {
|
||||
let message = _t("Message deleted");
|
||||
const unsigned = ev.getUnsigned();
|
||||
const redactedBecauseUserId = unsigned?.redacted_because?.sender;
|
||||
if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) {
|
||||
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
|
||||
const sender = room?.getMember(redactedBecauseUserId);
|
||||
message = _t("Message deleted by %(name)s", {
|
||||
name: sender?.name || redactedBecauseUserId,
|
||||
});
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
function textForPollStartEvent(event: MatrixEvent): () => string | null {
|
||||
return () => _t("%(senderName)s has started a poll - %(pollQuestion)s", {
|
||||
senderName: getSenderName(event),
|
||||
pollQuestion: (event.unstableExtensibleEvent as PollStartEvent)?.question?.text,
|
||||
});
|
||||
return () => {
|
||||
let message = '';
|
||||
|
||||
if (event.isRedacted()) {
|
||||
message = textForRedactedPollAndMessageEvent(event);
|
||||
const senderDisplayName = event.sender?.name ?? event.getSender();
|
||||
message = senderDisplayName + ': ' + message;
|
||||
} else {
|
||||
message = _t("%(senderName)s has started a poll - %(pollQuestion)s", {
|
||||
senderName: getSenderName(event),
|
||||
pollQuestion: (event.unstableExtensibleEvent as PollStartEvent)?.question?.text,
|
||||
});
|
||||
}
|
||||
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
function textForPollEndEvent(event: MatrixEvent): () => string | null {
|
||||
|
|
|
@ -525,8 +525,6 @@
|
|||
"%(senderDisplayName)s set the server ACLs for this room.": "%(senderDisplayName)s set the server ACLs for this room.",
|
||||
"%(senderDisplayName)s changed the server ACLs for this room.": "%(senderDisplayName)s changed the server ACLs for this room.",
|
||||
"🎉 All servers are banned from participating! This room can no longer be used.": "🎉 All servers are banned from participating! This room can no longer be used.",
|
||||
"Message deleted": "Message deleted",
|
||||
"Message deleted by %(name)s": "Message deleted by %(name)s",
|
||||
"%(senderDisplayName)s sent an image.": "%(senderDisplayName)s sent an image.",
|
||||
"%(senderDisplayName)s sent a sticker.": "%(senderDisplayName)s sent a sticker.",
|
||||
"%(senderName)s set the main address for this room to %(address)s.": "%(senderName)s set the main address for this room to %(address)s.",
|
||||
|
@ -575,6 +573,8 @@
|
|||
"%(senderName)s changed a rule that was banning servers matching %(oldGlob)s to matching %(newGlob)s for %(reason)s": "%(senderName)s changed a rule that was banning servers matching %(oldGlob)s to matching %(newGlob)s for %(reason)s",
|
||||
"%(senderName)s updated a ban rule that was matching %(oldGlob)s to matching %(newGlob)s for %(reason)s": "%(senderName)s updated a ban rule that was matching %(oldGlob)s to matching %(newGlob)s for %(reason)s",
|
||||
"%(senderName)s has shared their location": "%(senderName)s has shared their location",
|
||||
"Message deleted": "Message deleted",
|
||||
"Message deleted by %(name)s": "Message deleted by %(name)s",
|
||||
"%(senderName)s has started a poll - %(pollQuestion)s": "%(senderName)s has started a poll - %(pollQuestion)s",
|
||||
"%(senderName)s has ended a poll": "%(senderName)s has ended a poll",
|
||||
"Light": "Light",
|
||||
|
|
|
@ -379,4 +379,64 @@ describe('TextForEvent', () => {
|
|||
expect(textForEvent(event)).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe("textForPollStartEvent()", () => {
|
||||
let pollEvent;
|
||||
|
||||
beforeEach(() => {
|
||||
pollEvent = new MatrixEvent({
|
||||
type: 'org.matrix.msc3381.poll.start',
|
||||
sender: '@a',
|
||||
content: {
|
||||
'org.matrix.msc3381.poll.start': {
|
||||
answers: [
|
||||
{ 'org.matrix.msc1767.text': 'option1' },
|
||||
{ 'org.matrix.msc1767.text': 'option2' },
|
||||
],
|
||||
question: {
|
||||
'body': 'Test poll name',
|
||||
'msgtype': 'm.text',
|
||||
'org.matrix.msc1767.text': 'Test poll name',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns correct message for redacted poll start", () => {
|
||||
pollEvent.makeRedacted(pollEvent);
|
||||
|
||||
expect(textForEvent(pollEvent)).toEqual('@a: Message deleted');
|
||||
});
|
||||
|
||||
it("returns correct message for normal poll start", () => {
|
||||
expect(textForEvent(pollEvent)).toEqual('@a has started a poll - ');
|
||||
});
|
||||
});
|
||||
|
||||
describe("textForMessageEvent()", () => {
|
||||
let messageEvent;
|
||||
|
||||
beforeEach(() => {
|
||||
messageEvent = new MatrixEvent({
|
||||
type: 'm.room.message',
|
||||
sender: '@a',
|
||||
content: {
|
||||
'body': 'test message',
|
||||
'msgtype': 'm.text',
|
||||
'org.matrix.msc1767.text': 'test message',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns correct message for redacted message", () => {
|
||||
messageEvent.makeRedacted(messageEvent);
|
||||
|
||||
expect(textForEvent(messageEvent)).toEqual('@a: Message deleted');
|
||||
});
|
||||
|
||||
it("returns correct message for normal message", () => {
|
||||
expect(textForEvent(messageEvent)).toEqual('@a: test message');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue