Handle no match cases and modify textForEvent to handle redacted messages

This commit is contained in:
Jaiwanth 2021-06-22 12:12:37 +05:30
parent c58abd9582
commit 8a1cd77ef4
2 changed files with 13 additions and 9 deletions

View file

@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MatrixClientPeg} from './MatrixClientPeg'; import { MatrixClientPeg } from './MatrixClientPeg';
import { _t } from './languageHandler'; import { _t } from './languageHandler';
import * as Roles from './Roles'; import * as Roles from './Roles';
import {isValid3pidInvite} from "./RoomInvite"; import { isValid3pidInvite } from "./RoomInvite";
import SettingsStore from "./settings/SettingsStore"; import SettingsStore from "./settings/SettingsStore";
import {ALL_RULE_TYPES, ROOM_RULE_TYPES, SERVER_RULE_TYPES, USER_RULE_TYPES} from "./mjolnir/BanList"; import { ALL_RULE_TYPES, ROOM_RULE_TYPES, SERVER_RULE_TYPES, USER_RULE_TYPES } from "./mjolnir/BanList";
import {WIDGET_LAYOUT_EVENT_TYPE} from "./stores/widgets/WidgetLayoutStore"; import { WIDGET_LAYOUT_EVENT_TYPE } from "./stores/widgets/WidgetLayoutStore";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
// These functions are frequently used just to check whether an event has // These functions are frequently used just to check whether an event has
// any text to display at all. For this reason they return deferred values // any text to display at all. For this reason they return deferred values
@ -235,11 +236,13 @@ function textForServerACLEvent(ev): () => string | null {
return getText; return getText;
} }
function textForMessageEvent(ev): () => string | null { function textForMessageEvent(ev: MatrixEvent): () => string | null {
return () => { return () => {
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
const isRedacted = ev.isRedacted();
let message = ev.getContent().body; let message = ev.getContent().body;
if (ev.getContent().msgtype === "m.emote") { if (isRedacted) message = "Message Deleted";
else if (ev.getContent().msgtype === "m.emote") {
message = "* " + senderDisplayName + " " + message; message = "* " + senderDisplayName + " " + message;
} else if (ev.getContent().msgtype === "m.image") { } else if (ev.getContent().msgtype === "m.image") {
message = _t('%(senderDisplayName)s sent an image.', {senderDisplayName}); message = _t('%(senderDisplayName)s sent an image.', {senderDisplayName});

View file

@ -35,12 +35,13 @@ export default class PlainTextExporter extends Exporter {
const match = REPLY_REGEX.exec(content.body); const match = REPLY_REGEX.exec(content.body);
if (!match) return content.body;
let rplSource: string; let rplSource: string;
const rplName = match[1]; const rplName = match[1];
const rplText = match[3]; const rplText = match[3];
const sourceMatch = REPLY_REGEX.exec(content.body);
rplSource = sourceMatch && sourceMatch.length === 4 ? sourceMatch[3] : content.body; rplSource = match[2].substring(1, REPLY_SOURCE_MAX_LENGTH);
rplSource = rplSource.substring(0, REPLY_SOURCE_MAX_LENGTH);
// Get the first non-blank line from the source. // Get the first non-blank line from the source.
const lines = rplSource.split('\n').filter((line) => !/^\s*$/.test(line)) const lines = rplSource.split('\n').filter((line) => !/^\s*$/.test(line))
if (lines.length > 0) { if (lines.length > 0) {