Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cancel message when an order maker cancels it #601

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ const saveUserReview = async (targetUser, rating) => {
const cancelAddInvoice = async (ctx, order, job) => {
try {
let userAction = false;
let userTgId = false;
if (!job) {
ctx.deleteMessage();
ctx.scene.leave();
userAction = true;
userTgId = ctx.from.id;
if (!order) {
const orderId = !!ctx && ctx.update.callback_query.message.text;
if (!orderId) return;
Expand All @@ -258,6 +260,9 @@ const cancelAddInvoice = async (ctx, order, job) => {
return await messages.genericErrorMessage(ctx, user, i18nCtx);

const sellerUser = await User.findOne({ _id: order.seller_id });
const buyerUser = await User.findOne({ _id: order.buyer_id });
const sellerTgId = sellerUser.tg_id;
// If order creator cancels it, it will not be republished
if (order.creator_id === order.buyer_id) {
order.status = 'CLOSED';
await order.save();
Expand All @@ -269,6 +274,21 @@ const cancelAddInvoice = async (ctx, order, job) => {
order,
i18nCtxSeller
);
} else if (order.creator_id === order.seller_id && userTgId == sellerTgId) {
order.status = 'CLOSED';
await order.save();
await messages.successCancelOrderMessage(
ctx,
sellerUser,
order,
i18nCtx
);
await messages.counterPartyCancelOrderMessage(
ctx,
buyerUser,
order,
i18nCtx
);
} else {
// Re-publish order
if (userAction) {
Expand Down Expand Up @@ -315,20 +335,7 @@ const cancelAddInvoice = async (ctx, order, job) => {
order,
i18nCtx
);
} else {
await messages.successCancelOrderMessage(
ctx,
sellerUser,
order,
i18nCtx
);
await messages.counterPartyCancelOrderMessage(
ctx,
user,
order,
i18nCtx
);
}
}
} else {
await messages.successCancelOrderMessage(ctx, user, order, i18nCtx);
}
Expand Down Expand Up @@ -408,10 +415,12 @@ const showHoldInvoice = async (ctx, bot, order) => {
const cancelShowHoldInvoice = async (ctx, order, job) => {
try {
let userAction = false;
let userTgId = false;
if (!job) {
ctx.deleteMessage();
ctx.scene.leave();
userAction = true;
userTgId = ctx.from.id;
if (!order) {
const orderId = !!ctx && ctx.update.callback_query.message.text;
if (!orderId) return;
Expand All @@ -431,6 +440,9 @@ const cancelShowHoldInvoice = async (ctx, order, job) => {
return await messages.genericErrorMessage(ctx, user, i18nCtx);

const buyerUser = await User.findOne({ _id: order.buyer_id });
const sellerUser = await User.findOne({ _id: order.seller_id });
const buyerTgId = buyerUser.tg_id;
// If order creator cancels it, it will not be republished
if (order.creator_id === order.seller_id) {
order.status = 'CLOSED';
await order.save();
Expand All @@ -441,6 +453,22 @@ const cancelShowHoldInvoice = async (ctx, order, job) => {
order,
i18nCtx
);
} else if (order.creator_id === order.buyer_id && userTgId == buyerTgId) {
order.status = 'CLOSED';
await order.save();
await messages.successCancelOrderMessage(
ctx,
buyerUser,
order,
i18nCtx
);
await messages.counterPartyCancelOrderMessage(
ctx,
sellerUser,
order,
i18nCtx
);

} else {
// Re-publish order
if (userAction) {
Expand Down Expand Up @@ -488,20 +516,7 @@ const cancelShowHoldInvoice = async (ctx, order, job) => {
order,
i18nCtx
);
} else {
await messages.successCancelOrderMessage(
ctx,
buyerUser,
order,
i18nCtx
);
await messages.counterPartyCancelOrderMessage(
ctx,
user,
order,
i18nCtx
);
}
}
} else {
await messages.successCancelOrderMessage(ctx, user, order, i18nCtx);
}
Expand Down
Loading