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
|
||||
.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.PollVote.on('add', (vote) => {
|
||||
const pollVoteModel = window.WWebJS.getPollVoteModel(vote);
|
||||
window.Store.PollVote.on('add', async (vote) => {
|
||||
const pollVoteModel = await window.WWebJS.getPollVoteModel(vote);
|
||||
pollVoteModel && window.onPollVoteEvent(pollVoteModel);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -311,9 +311,9 @@ class Message extends Base {
|
|||
* @returns {Promise<Message>}
|
||||
*/
|
||||
async reload() {
|
||||
const newData = await this.client.pupPage.evaluate((msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId);
|
||||
if(!msg) return null;
|
||||
const newData = await this.client.pupPage.evaluate(async (msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
if (!msg) return null;
|
||||
return window.WWebJS.getMessageModel(msg);
|
||||
}, this.id._serialized);
|
||||
|
||||
|
|
@ -370,8 +370,8 @@ class Message extends Base {
|
|||
async getQuotedMessage() {
|
||||
if (!this.hasQuotedMsg) return undefined;
|
||||
|
||||
const quotedMsg = await this.client.pupPage.evaluate((msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId);
|
||||
const quotedMsg = await this.client.pupPage.evaluate(async (msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
const quotedMsg = window.Store.QuotedMsg.getQuotedMsgObj(msg);
|
||||
return window.WWebJS.getMessageModel(quotedMsg);
|
||||
}, this.id._serialized);
|
||||
|
|
@ -409,9 +409,10 @@ class Message extends Base {
|
|||
*/
|
||||
async react(reaction){
|
||||
await this.client.pupPage.evaluate(async (messageId, reaction) => {
|
||||
if (!messageId) { return undefined; }
|
||||
|
||||
const msg = await window.Store.Msg.get(messageId);
|
||||
if (!messageId) return null;
|
||||
const msg =
|
||||
window.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0];
|
||||
if(!msg) return null;
|
||||
await window.Store.sendReactionToMsg(msg, reaction);
|
||||
}, this.id._serialized, reaction);
|
||||
}
|
||||
|
|
@ -448,9 +449,9 @@ class Message extends Base {
|
|||
}
|
||||
|
||||
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) {
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
||||
// try to resolve media
|
||||
|
|
@ -500,7 +501,7 @@ class Message extends Base {
|
|||
*/
|
||||
async delete(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);
|
||||
|
||||
const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
||||
|
|
@ -521,8 +522,7 @@ class Message extends Base {
|
|||
*/
|
||||
async star() {
|
||||
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)) {
|
||||
let chat = await window.Store.Chat.find(msg.id.remote);
|
||||
return window.Store.Cmd.sendStarMsgs(chat, [msg], false);
|
||||
|
|
@ -535,8 +535,7 @@ class Message extends Base {
|
|||
*/
|
||||
async unstar() {
|
||||
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)) {
|
||||
let chat = await window.Store.Chat.find(msg.id.remote);
|
||||
return window.Store.Cmd.sendUnstarMsgs(chat, [msg], false);
|
||||
|
|
@ -583,7 +582,7 @@ class Message extends Base {
|
|||
*/
|
||||
async getInfo() {
|
||||
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;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
|
@ -617,7 +616,7 @@ class Message extends Base {
|
|||
async getPayment() {
|
||||
if (this.type === MessageTypes.PAYMENT) {
|
||||
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;
|
||||
return msg.serialize();
|
||||
}, this.id._serialized);
|
||||
|
|
@ -692,11 +691,11 @@ class Message extends Base {
|
|||
return null;
|
||||
}
|
||||
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;
|
||||
|
||||
let catEdit = window.Store.MsgActionChecks.canEditText(msg) || window.Store.MsgActionChecks.canEditCaption(msg);
|
||||
if (catEdit) {
|
||||
let canEdit = window.Store.MsgActionChecks.canEditText(msg) || window.Store.MsgActionChecks.canEditCaption(msg);
|
||||
if (canEdit) {
|
||||
const msgEdit = await window.WWebJS.editMessage(msg, message, options);
|
||||
return msgEdit.serialize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue