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:
parent
22af9df3d0
commit
951ff7bfca
5 changed files with 46 additions and 37 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -74,3 +74,7 @@ typings/
|
||||||
|
|
||||||
# local version cache
|
# local version cache
|
||||||
.wwebjs_cache/
|
.wwebjs_cache/
|
||||||
|
|
||||||
|
# IDE's
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
@ -720,8 +720,8 @@ class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);});
|
window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);});
|
||||||
window.Store.PollVote.on('add', (vote) => {
|
window.Store.PollVote.on('add', async (vote) => {
|
||||||
const pollVoteModel = window.WWebJS.getPollVoteModel(vote);
|
const pollVoteModel = await window.WWebJS.getPollVoteModel(vote);
|
||||||
pollVoteModel && window.onPollVoteEvent(pollVoteModel);
|
pollVoteModel && window.onPollVoteEvent(pollVoteModel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -311,9 +311,9 @@ class Message extends Base {
|
||||||
* @returns {Promise<Message>}
|
* @returns {Promise<Message>}
|
||||||
*/
|
*/
|
||||||
async reload() {
|
async reload() {
|
||||||
const newData = await this.client.pupPage.evaluate((msgId) => {
|
const newData = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
const msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
if(!msg) return null;
|
if (!msg) return null;
|
||||||
return window.WWebJS.getMessageModel(msg);
|
return window.WWebJS.getMessageModel(msg);
|
||||||
}, this.id._serialized);
|
}, this.id._serialized);
|
||||||
|
|
||||||
|
|
@ -370,8 +370,8 @@ class Message extends Base {
|
||||||
async getQuotedMessage() {
|
async getQuotedMessage() {
|
||||||
if (!this.hasQuotedMsg) return undefined;
|
if (!this.hasQuotedMsg) return undefined;
|
||||||
|
|
||||||
const quotedMsg = await this.client.pupPage.evaluate((msgId) => {
|
const quotedMsg = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
const msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
const quotedMsg = window.Store.QuotedMsg.getQuotedMsgObj(msg);
|
const quotedMsg = window.Store.QuotedMsg.getQuotedMsgObj(msg);
|
||||||
return window.WWebJS.getMessageModel(quotedMsg);
|
return window.WWebJS.getMessageModel(quotedMsg);
|
||||||
}, this.id._serialized);
|
}, this.id._serialized);
|
||||||
|
|
@ -409,9 +409,10 @@ class Message extends Base {
|
||||||
*/
|
*/
|
||||||
async react(reaction){
|
async react(reaction){
|
||||||
await this.client.pupPage.evaluate(async (messageId, reaction) => {
|
await this.client.pupPage.evaluate(async (messageId, reaction) => {
|
||||||
if (!messageId) { return undefined; }
|
if (!messageId) return null;
|
||||||
|
const msg =
|
||||||
const msg = await window.Store.Msg.get(messageId);
|
window.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0];
|
||||||
|
if(!msg) return null;
|
||||||
await window.Store.sendReactionToMsg(msg, reaction);
|
await window.Store.sendReactionToMsg(msg, reaction);
|
||||||
}, this.id._serialized, reaction);
|
}, this.id._serialized, reaction);
|
||||||
}
|
}
|
||||||
|
|
@ -448,9 +449,9 @@ class Message extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
const msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
if (!msg || !msg.mediaData) {
|
if (!msg || !msg.mediaData) {
|
||||||
return undefined;
|
return null;
|
||||||
}
|
}
|
||||||
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
||||||
// try to resolve media
|
// try to resolve media
|
||||||
|
|
@ -500,7 +501,7 @@ class Message extends Base {
|
||||||
*/
|
*/
|
||||||
async delete(everyone) {
|
async delete(everyone) {
|
||||||
await this.client.pupPage.evaluate(async (msgId, everyone) => {
|
await this.client.pupPage.evaluate(async (msgId, everyone) => {
|
||||||
let msg = 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 chat = await window.Store.Chat.find(msg.id.remote);
|
||||||
|
|
||||||
const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
||||||
|
|
@ -521,8 +522,7 @@ class Message extends Base {
|
||||||
*/
|
*/
|
||||||
async star() {
|
async star() {
|
||||||
await this.client.pupPage.evaluate(async (msgId) => {
|
await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
let msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
|
|
||||||
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
||||||
let chat = await window.Store.Chat.find(msg.id.remote);
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
||||||
return window.Store.Cmd.sendStarMsgs(chat, [msg], false);
|
return window.Store.Cmd.sendStarMsgs(chat, [msg], false);
|
||||||
|
|
@ -535,8 +535,7 @@ class Message extends Base {
|
||||||
*/
|
*/
|
||||||
async unstar() {
|
async unstar() {
|
||||||
await this.client.pupPage.evaluate(async (msgId) => {
|
await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
let msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
|
|
||||||
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
||||||
let chat = await window.Store.Chat.find(msg.id.remote);
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
||||||
return window.Store.Cmd.sendUnstarMsgs(chat, [msg], false);
|
return window.Store.Cmd.sendUnstarMsgs(chat, [msg], false);
|
||||||
|
|
@ -583,7 +582,7 @@ class Message extends Base {
|
||||||
*/
|
*/
|
||||||
async getInfo() {
|
async getInfo() {
|
||||||
const info = await this.client.pupPage.evaluate(async (msgId) => {
|
const info = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
const msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
if (!msg || !msg.id.fromMe) return null;
|
if (!msg || !msg.id.fromMe) return null;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
@ -617,7 +616,7 @@ class Message extends Base {
|
||||||
async getPayment() {
|
async getPayment() {
|
||||||
if (this.type === MessageTypes.PAYMENT) {
|
if (this.type === MessageTypes.PAYMENT) {
|
||||||
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
const msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
if(!msg) return null;
|
if(!msg) return null;
|
||||||
return msg.serialize();
|
return msg.serialize();
|
||||||
}, this.id._serialized);
|
}, this.id._serialized);
|
||||||
|
|
@ -692,11 +691,11 @@ class Message extends Base {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const messageEdit = await this.client.pupPage.evaluate(async (msgId, message, options) => {
|
const messageEdit = await this.client.pupPage.evaluate(async (msgId, message, options) => {
|
||||||
let msg = window.Store.Msg.get(msgId);
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
if (!msg) return null;
|
if (!msg) return null;
|
||||||
|
|
||||||
let catEdit = window.Store.MsgActionChecks.canEditText(msg) || window.Store.MsgActionChecks.canEditCaption(msg);
|
let canEdit = window.Store.MsgActionChecks.canEditText(msg) || window.Store.MsgActionChecks.canEditCaption(msg);
|
||||||
if (catEdit) {
|
if (canEdit) {
|
||||||
const msgEdit = await window.WWebJS.editMessage(msg, message, options);
|
const msgEdit = await window.WWebJS.editMessage(msg, message, options);
|
||||||
return msgEdit.serialize();
|
return msgEdit.serialize();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ exports.LoadUtils = () => {
|
||||||
window.WWebJS = {};
|
window.WWebJS = {};
|
||||||
|
|
||||||
window.WWebJS.forwardMessage = async (chatId, msgId) => {
|
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);
|
let chat = window.Store.Chat.get(chatId);
|
||||||
|
|
||||||
if (window.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')) {
|
if (window.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')) {
|
||||||
|
|
@ -44,7 +44,13 @@ exports.LoadUtils = () => {
|
||||||
}
|
}
|
||||||
let quotedMsgOptions = {};
|
let quotedMsgOptions = {};
|
||||||
if (options.quotedMessageId) {
|
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
|
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
|
||||||
const canReply = window.Store.ReplyUtils ?
|
const canReply = window.Store.ReplyUtils ?
|
||||||
|
|
@ -433,14 +439,13 @@ exports.LoadUtils = () => {
|
||||||
return msg;
|
return msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.getPollVoteModel = (vote) => {
|
window.WWebJS.getPollVoteModel = async (vote) => {
|
||||||
const _vote = vote.serialize();
|
const _vote = vote.serialize();
|
||||||
if (vote.parentMsgKey) {
|
if (!vote.parentMsgKey) return null;
|
||||||
const msg = window.Store.Msg.get(vote.parentMsgKey);
|
const msg =
|
||||||
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
|
window.Store.Msg.get(vote.parentMsgKey) || (await window.Store.Msg.getMessagesById([vote.parentMsgKey]))?.messages?.[0];
|
||||||
return _vote;
|
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
|
||||||
}
|
return _vote;
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.getChatModel = async chat => {
|
window.WWebJS.getChatModel = async chat => {
|
||||||
|
|
@ -458,7 +463,9 @@ exports.LoadUtils = () => {
|
||||||
|
|
||||||
res.lastMessage = null;
|
res.lastMessage = null;
|
||||||
if (res.msgs && res.msgs.length) {
|
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) {
|
if (lastMessage) {
|
||||||
res.lastMessage = window.WWebJS.getMessageModel(lastMessage);
|
res.lastMessage = window.WWebJS.getMessageModel(lastMessage);
|
||||||
}
|
}
|
||||||
|
|
@ -1001,11 +1008,10 @@ exports.LoadUtils = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
|
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;
|
if (!message) return false;
|
||||||
const response = await window.Store.pinUnpinMsg(message, action, duration);
|
const response = await window.Store.pinUnpinMsg(message, action, duration);
|
||||||
if (response.messageSendResult === 'OK') return true;
|
return response.messageSendResult === 'OK';
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class InterfaceController {
|
||||||
*/
|
*/
|
||||||
async openChatWindowAt(msgId) {
|
async openChatWindowAt(msgId) {
|
||||||
await this.pupPage.evaluate(async 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 chat = await window.Store.Chat.find(msg.id.remote);
|
||||||
let searchContext = await window.Store.SearchContext(chat,msg);
|
let searchContext = await window.Store.SearchContext(chat,msg);
|
||||||
await window.Store.Cmd.openChatAt(chat, searchContext);
|
await window.Store.Cmd.openChatAt(chat, searchContext);
|
||||||
|
|
@ -62,7 +62,7 @@ class InterfaceController {
|
||||||
*/
|
*/
|
||||||
async openMessageDrawer(msgId) {
|
async openMessageDrawer(msgId) {
|
||||||
await this.pupPage.evaluate(async 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);
|
await window.Store.Cmd.msgInfoDrawer(msg);
|
||||||
}, msgId);
|
}, msgId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue