fix: sendMessage with quoted message id (#3260)

* fix: sendMessage with quoted message id

Now using `window.Store.Msg.getMessagesById` instead of `window.Store.Msg.get`

* refactor: apply message retrievement to all appropriate places

* chore: ignore ide's dirs

* fix: set proper variable

---------

Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
Alwin Lubbers 2024-09-15 00:44:07 +02:00 • committed by GitHub
commit 951ff7bfca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 37 deletions

View file

@ -4,7 +4,7 @@ exports.LoadUtils = () => {
window.WWebJS = {};
window.WWebJS.forwardMessage = async (chatId, msgId) => {
let msg = window.Store.Msg.get(msgId);
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
let chat = window.Store.Chat.get(chatId);
if (window.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')) {
@ -44,7 +44,13 @@ exports.LoadUtils = () => {
}
let quotedMsgOptions = {};
if (options.quotedMessageId) {
let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
let quotedMessage = await window.Store.Msg.getMessagesById([options.quotedMessageId]);
if (quotedMessage['messages'].length != 1) {
throw new Error('Could not get the quoted message.');
}
quotedMessage = quotedMessage['messages'][0];
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
const canReply = window.Store.ReplyUtils ?
@ -433,14 +439,13 @@ exports.LoadUtils = () => {
return msg;
};
window.WWebJS.getPollVoteModel = (vote) => {
window.WWebJS.getPollVoteModel = async (vote) => {
const _vote = vote.serialize();
if (vote.parentMsgKey) {
const msg = window.Store.Msg.get(vote.parentMsgKey);
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
return _vote;
}
return null;
if (!vote.parentMsgKey) return null;
const msg =
window.Store.Msg.get(vote.parentMsgKey) || (await window.Store.Msg.getMessagesById([vote.parentMsgKey]))?.messages?.[0];
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
return _vote;
};
window.WWebJS.getChatModel = async chat => {
@ -458,7 +463,9 @@ exports.LoadUtils = () => {
res.lastMessage = null;
if (res.msgs && res.msgs.length) {
const lastMessage = chat.lastReceivedKey ? window.Store.Msg.get(chat.lastReceivedKey._serialized) : null;
const lastMessage = chat.lastReceivedKey
? window.Store.Msg.get(chat.lastReceivedKey._serialized) || (await window.Store.Msg.getMessagesById([chat.lastReceivedKey._serialized]))?.messages?.[0]
: null;
if (lastMessage) {
res.lastMessage = window.WWebJS.getMessageModel(lastMessage);
}
@ -1001,11 +1008,10 @@ exports.LoadUtils = () => {
};
window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
const message = window.Store.Msg.get(msgId);
const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
if (!message) return false;
const response = await window.Store.pinUnpinMsg(message, action, duration);
if (response.messageSendResult === 'OK') return true;
return false;
return response.messageSendResult === 'OK';
};
};

View file

@ -49,7 +49,7 @@ class InterfaceController {
*/
async openChatWindowAt(msgId) {
await this.pupPage.evaluate(async msgId => {
let msg = await window.Store.Msg.get(msgId);
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
let chat = await window.Store.Chat.find(msg.id.remote);
let searchContext = await window.Store.SearchContext(chat,msg);
await window.Store.Cmd.openChatAt(chat, searchContext);
@ -62,7 +62,7 @@ class InterfaceController {
*/
async openMessageDrawer(msgId) {
await this.pupPage.evaluate(async msgId => {
let msg = await window.Store.Msg.get(msgId);
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
await window.Store.Cmd.msgInfoDrawer(msg);
}, msgId);
}