QuickReply & Up Key: Do not attempt to edit/reply to logged deleted message
This commit is contained in:
parent
8378638ee4
commit
8c47b7080d
2 changed files with 15 additions and 3 deletions
|
@ -209,6 +209,11 @@ export default definePlugin({
|
||||||
" m" +
|
" m" +
|
||||||
")" +
|
")" +
|
||||||
".update($3"
|
".update($3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// fix up key (edit last message) attempting to edit a deleted message
|
||||||
|
match: /(?<=getLastEditableMessage=.{0,200}\.find\(\(function\((\i)\)\{)return/,
|
||||||
|
replace: "return !$1.deleted &&"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -111,7 +111,7 @@ function jumpIfOffScreen(channelId: string, messageId: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextMessage(isUp: boolean, isReply: boolean) {
|
function getNextMessage(isUp: boolean, isReply: boolean) {
|
||||||
let messages: Message[] = MessageStore.getMessages(SelectedChannelStore.getChannelId())._array;
|
let messages: Array<Message & { deleted?: boolean; }> = MessageStore.getMessages(SelectedChannelStore.getChannelId())._array;
|
||||||
if (!isReply) { // we are editing so only include own
|
if (!isReply) { // we are editing so only include own
|
||||||
const meId = UserStore.getCurrentUser().id;
|
const meId = UserStore.getCurrentUser().id;
|
||||||
messages = messages.filter(m => m.author.id === meId);
|
messages = messages.filter(m => m.author.id === meId);
|
||||||
|
@ -121,11 +121,18 @@ function getNextMessage(isUp: boolean, isReply: boolean) {
|
||||||
? Math.min(messages.length - 1, i + 1)
|
? Math.min(messages.length - 1, i + 1)
|
||||||
: Math.max(-1, i - 1);
|
: Math.max(-1, i - 1);
|
||||||
|
|
||||||
|
const findNextNonDeleted = (i: number) => {
|
||||||
|
do {
|
||||||
|
i = mutate(i);
|
||||||
|
} while (i !== -1 && messages[messages.length - i - 1]?.deleted === true);
|
||||||
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
let i: number;
|
let i: number;
|
||||||
if (isReply)
|
if (isReply)
|
||||||
replyIdx = i = mutate(replyIdx);
|
replyIdx = i = findNextNonDeleted(replyIdx);
|
||||||
else
|
else
|
||||||
editIdx = i = mutate(editIdx);
|
editIdx = i = findNextNonDeleted(editIdx);
|
||||||
|
|
||||||
return i === - 1 ? undefined : messages[messages.length - i - 1];
|
return i === - 1 ? undefined : messages[messages.length - i - 1];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue