-
Notifications
You must be signed in to change notification settings - Fork 116
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
Block exchanges between user A to B #630
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||
import { CustomContext } from './customContext'; | ||||||
|
||||||
const { User, Block, Order } = require('../../../models'); | ||||||
const messages = require('./messages'); | ||||||
const globalMessages = require('../../messages'); | ||||||
|
||||||
const block = async (ctx: CustomContext, username: string): Promise<void> => { | ||||||
const userToBlock = await User.findOne({ username }); | ||||||
const user = ctx.user; | ||||||
|
||||||
if (!userToBlock) { | ||||||
await globalMessages.notFoundUserMessage(ctx); | ||||||
return; | ||||||
} | ||||||
|
||||||
const areExistingOrders = await Order.exists({ | ||||||
$or: [ | ||||||
{ seller_id: user.id, buyer_id: userToBlock.id }, | ||||||
{ seller_id: userToBlock.id, buyer_id: user.id }, | ||||||
], | ||||||
status: { | ||||||
$nin: [ | ||||||
'PENDING', | ||||||
'CLOSED', | ||||||
'CANCELED_BY_ADMIN', | ||||||
'EXPIRED', | ||||||
'COMPLETED_BY_ADMIN', | ||||||
], | ||||||
}, | ||||||
}); | ||||||
|
||||||
if (areExistingOrders) { | ||||||
await messages.ordersInProcess(ctx); | ||||||
return; | ||||||
} | ||||||
|
||||||
const isAlreadyBlocked = await Block.exists({ | ||||||
blocker_tg_id: user.tg_id, | ||||||
blocked_tg_id: userToBlock.tg_id, | ||||||
}); | ||||||
if (isAlreadyBlocked) { | ||||||
await messages.userAlreadyBlocked(ctx); | ||||||
return; | ||||||
} | ||||||
|
||||||
const block = new Block({ | ||||||
blocker_tg_id: user.tg_id, | ||||||
blocked_tg_id: userToBlock.tg_id, | ||||||
}); | ||||||
await block.save(); | ||||||
await messages.userBlocked(ctx); | ||||||
}; | ||||||
|
||||||
const unblock = async (ctx: CustomContext, username: string): Promise<void> => { | ||||||
const userToUnblock = await User.findOne({ username }); | ||||||
const user = ctx.user; | ||||||
|
||||||
const result = await Block.deleteOne({ | ||||||
blocker_tg_id: user.tg_id, | ||||||
blocked_tg_id: userToUnblock.tg_id, | ||||||
}); | ||||||
|
||||||
if (result.deletedCount === 1) { | ||||||
await messages.userUnblocked(ctx); | ||||||
} else { | ||||||
await globalMessages.notFoundUserMessage(ctx); | ||||||
} | ||||||
}; | ||||||
Comment on lines
+54
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation and improve error handling. The function needs improvements in several areas:
Apply this diff to improve the function: const unblock = async (ctx: CustomContext, username: string): Promise<void> => {
+ if (!username?.match(/^[a-zA-Z0-9_]{5,32}$/)) {
+ await messages.invalidUsernameMessage(ctx);
+ return;
+ }
+
const userToUnblock = await User.findOne({ username });
+ if (!userToUnblock) {
+ await globalMessages.notFoundUserMessage(ctx);
+ return;
+ }
+
const user = ctx.user;
+ const session = await mongoose.startSession();
+ try {
+ await session.withTransaction(async () => {
const result = await Block.deleteOne({
blocker_tg_id: user.tg_id,
blocked_tg_id: userToUnblock.tg_id,
- });
+ }).session(session);
if (result.deletedCount === 1) {
await messages.userUnblocked(ctx);
} else {
- await globalMessages.notFoundUserMessage(ctx);
+ await messages.userNotBlockedMessage(ctx);
}
+ });
+ } catch (error) {
+ logger.error(error);
+ await messages.databaseErrorMessage(ctx);
+ } finally {
+ session.endSession();
+ }
};
|
||||||
|
||||||
const blocklist = async (ctx: CustomContext): Promise<void> => { | ||||||
const blocks = await Block.find({ blocker_tg_id: ctx.user.tg_id }); | ||||||
const tgIdBlocks = blocks.map(blocked => blocked.blocked_tg_id); | ||||||
|
||||||
if (!tgIdBlocks.length) { | ||||||
await messages.blocklistEmptyMessage(ctx); | ||||||
return; | ||||||
} | ||||||
|
||||||
const usersBlocked = await User.find({ tg_id: { $in: tgIdBlocks } }); | ||||||
await messages.blocklistMessage(ctx, usersBlocked); | ||||||
}; | ||||||
Comment on lines
+70
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add pagination and improve error handling. The function needs improvements in several areas:
Apply this diff to improve the function: -const blocklist = async (ctx: CustomContext): Promise<void> => {
+const blocklist = async (ctx: CustomContext, page: number = 1): Promise<void> => {
+ const PAGE_SIZE = 50;
+ const skip = (page - 1) * PAGE_SIZE;
+
+ const session = await mongoose.startSession();
+ try {
+ await session.withTransaction(async () => {
+ const totalBlocks = await Block.countDocuments({ blocker_tg_id: ctx.user.tg_id });
+ const totalPages = Math.ceil(totalBlocks / PAGE_SIZE);
+
+ if (totalBlocks === 0) {
+ await messages.blocklistEmptyMessage(ctx);
+ return;
+ }
+
const blocks = await Block.find({ blocker_tg_id: ctx.user.tg_id })
+ .skip(skip)
+ .limit(PAGE_SIZE)
+ .session(session);
+
const tgIdBlocks = blocks.map(blocked => blocked.blocked_tg_id);
-
- if (!tgIdBlocks.length) {
- await messages.blocklistEmptyMessage(ctx);
- return;
- }
-
- const usersBlocked = await User.find({ tg_id: { $in: tgIdBlocks } });
+ const usersBlocked = await User.find({ tg_id: { $in: tgIdBlocks } })
+ .session(session);
+
await messages.blocklistMessage(ctx, usersBlocked);
+
+ if (totalPages > 1) {
+ await messages.paginationMessage(ctx, page, totalPages);
+ }
+ });
+ } catch (error) {
+ logger.error(error);
+ await messages.databaseErrorMessage(ctx);
+ } finally {
+ session.endSession();
+ }
};
|
||||||
|
||||||
module.exports = { block, unblock, blocklist }; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update exports to use ES6 syntax. The module uses TypeScript but still uses CommonJS exports. Apply this diff to improve the exports: -module.exports = { block, unblock, blocklist };
+export { block, unblock, blocklist }; 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||
import { Context } from 'telegraf'; | ||||||||||
|
||||||||||
export interface CustomContext extends Context { | ||||||||||
user?: { | ||||||||||
id: string; | ||||||||||
tg_id: string; | ||||||||||
}, | ||||||||||
i18n?: any; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace Using - i18n?: any;
+ i18n?: {
+ t: (key: string, params?: Record<string, unknown>) => string;
+ }; 📝 Committable suggestion
Suggested change
|
||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||||||||||||||||||||||||||||||||||||||
import { Telegraf } from 'telegraf'; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const commands = require('./commands'); | ||||||||||||||||||||||||||||||||||||||||||
const { userMiddleware } = require('../../middleware/user'); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
exports.configure = (bot: Telegraf) => { | ||||||||||||||||||||||||||||||||||||||||||
bot.command('block', userMiddleware, async (ctx, next) => { | ||||||||||||||||||||||||||||||||||||||||||
const args = ctx.message.text.split(' ') || []; | ||||||||||||||||||||||||||||||||||||||||||
if (args.length !== 2) return next(); | ||||||||||||||||||||||||||||||||||||||||||
commands.block(ctx, args[1]); | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and input validation. The command handler should:
- bot.command('block', userMiddleware, async (ctx, next) => {
+ bot.command('block', userMiddleware, rateLimiter, async (ctx: CustomContext, next) => {
const args = ctx.message.text.split(' ') || [];
if (args.length !== 2) return next();
- commands.block(ctx, args[1]);
+ const username = args[1];
+ if (!username.match(/^@?[\w\d]{5,32}$/)) {
+ await ctx.reply(ctx.i18n?.t('invalid_username_format') ?? 'Invalid username format');
+ return;
+ }
+ try {
+ await commands.block(ctx, username);
+ } catch (error) {
+ console.error('Error in block command:', error);
+ await ctx.reply(ctx.i18n?.t('block_error') ?? 'Failed to block user');
+ }
});
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
bot.command('unblock', userMiddleware, async (ctx, next) => { | ||||||||||||||||||||||||||||||||||||||||||
const args = ctx.message.text.split(' ') || []; | ||||||||||||||||||||||||||||||||||||||||||
if (args.length !== 2) return next(); | ||||||||||||||||||||||||||||||||||||||||||
commands.unblock(ctx, args[1]); | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and input validation to unblock command. Apply the same improvements as the block command. - bot.command('unblock', userMiddleware, async (ctx, next) => {
+ bot.command('unblock', userMiddleware, rateLimiter, async (ctx: CustomContext, next) => {
const args = ctx.message.text.split(' ') || [];
if (args.length !== 2) return next();
- commands.unblock(ctx, args[1]);
+ const username = args[1];
+ if (!username.match(/^@?[\w\d]{5,32}$/)) {
+ await ctx.reply(ctx.i18n?.t('invalid_username_format') ?? 'Invalid username format');
+ return;
+ }
+ try {
+ await commands.unblock(ctx, username);
+ } catch (error) {
+ console.error('Error in unblock command:', error);
+ await ctx.reply(ctx.i18n?.t('unblock_error') ?? 'Failed to unblock user');
+ }
}); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
bot.command('blocklist', userMiddleware, commands.blocklist); | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling to blocklist command. Wrap the command execution in try-catch. - bot.command('blocklist', userMiddleware, commands.blocklist);
+ bot.command('blocklist', userMiddleware, rateLimiter, async (ctx: CustomContext) => {
+ try {
+ await commands.blocklist(ctx);
+ } catch (error) {
+ console.error('Error in blocklist command:', error);
+ await ctx.reply(ctx.i18n?.t('blocklist_error') ?? 'Failed to fetch block list');
+ }
+ }); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||||||||||||||
import { CustomContext } from './customContext'; | ||||||||||||||||||||
|
||||||||||||||||||||
const { logger } = require('../../../logger'); | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
const ordersInProcess = async (ctx: CustomContext) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
ctx.reply(ctx.i18n.t('orders_in_process')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const userAlreadyBlocked = async (ctx: CustomContext) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
ctx.reply(ctx.i18n.t('user_already_blocked')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const userBlocked = async (ctx: CustomContext) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
ctx.reply(ctx.i18n.t('user_blocked')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const userUnblocked = async (ctx: CustomContext) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
ctx.reply(ctx.i18n.t('user_unblocked')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const blocklistMessage = async (ctx: CustomContext, usersBlocked) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
const userList = usersBlocked.map(block => block.username); | ||||||||||||||||||||
ctx.reply(userList.join('\n')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
Comment on lines
+38
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Handle edge cases in the blocklist message. The function needs improvements to handle:
Apply this diff to improve edge case handling: const blocklistMessage = async (ctx: CustomContext, usersBlocked) => {
try {
+ if (!usersBlocked?.length) {
+ return await messages.blocklistEmptyMessage(ctx);
+ }
+
const userList = usersBlocked.map(block => block.username);
+ const validUserList = userList.filter(Boolean);
+
+ if (!validUserList.length) {
+ return await messages.blocklistEmptyMessage(ctx);
+ }
+
+ // Split long lists into chunks of 50 usernames
+ const chunkSize = 50;
+ for (let i = 0; i < validUserList.length; i += chunkSize) {
+ const chunk = validUserList.slice(i, i + chunkSize);
ctx.reply(userList.join('\n'));
+ }
} catch (error) {
logger.error(error);
+ await ctx.reply(ctx.i18n.t('error_sending_message')).catch(() => {});
}
};
|
||||||||||||||||||||
|
||||||||||||||||||||
const blocklistEmptyMessage = async (ctx: CustomContext) => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
ctx.reply(ctx.i18n.t('blocklist_empty')); | ||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||
logger.error(error); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
module.exports = { userAlreadyBlocked, userBlocked, userUnblocked, blocklistMessage, blocklistEmptyMessage, ordersInProcess } | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update exports to use ES6 syntax and include missing function.
Apply this diff to improve the exports: -module.exports = { userAlreadyBlocked, userBlocked, userUnblocked, blocklistMessage, blocklistEmptyMessage, ordersInProcess }
+export {
+ userAlreadyBlocked,
+ userBlocked,
+ userUnblocked,
+ blocklistMessage,
+ blocklistEmptyMessage,
+ ordersInProcess
+}; 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||
// @ts-check | ||||||||||||||||||||||||||||||||||||||
const { logger } = require('../../../logger'); | ||||||||||||||||||||||||||||||||||||||
const { Order } = require('../../../models'); | ||||||||||||||||||||||||||||||||||||||
const { Order, Block, User } = require('../../../models'); | ||||||||||||||||||||||||||||||||||||||
const { deleteOrderFromChannel } = require('../../../util'); | ||||||||||||||||||||||||||||||||||||||
const messages = require('../../messages'); | ||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||
|
@@ -48,6 +48,18 @@ exports.takebuy = async (ctx, bot, orderId) => { | |||||||||||||||||||||||||||||||||||||
if (!(await validateObjectId(ctx, orderId))) return; | ||||||||||||||||||||||||||||||||||||||
const order = await Order.findOne({ _id: orderId }); | ||||||||||||||||||||||||||||||||||||||
if (!order) return; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const userOffer = await User.findOne({_id: order.buyer_id}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const userOfferIsBlocked = await Block.exists({ blocker_tg_id: user.tg_id, blocked_tg_id: userOffer.tg_id }); | ||||||||||||||||||||||||||||||||||||||
const takerIsBlocked = await Block.exists({blocker_tg_id: userOffer.tg_id, blocked_tg_id: user.tg_id}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if (userOfferIsBlocked) | ||||||||||||||||||||||||||||||||||||||
return await messages.userOrderIsBlockedByUserTaker(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if (takerIsBlocked) | ||||||||||||||||||||||||||||||||||||||
return await messages.userTakerIsBlockedByUserOrder(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Comment on lines
+51
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Extract blocking checks into a reusable function. The blocking checks are duplicated in both Create a new function to handle blocking checks: +const checkBlockingStatus = async (ctx, user, otherUser) => {
+ const userIsBlocked = await Block.exists({ blocker_tg_id: user.tg_id, blocked_tg_id: otherUser.tg_id });
+ if (userIsBlocked) {
+ await messages.userOrderIsBlockedByUserTaker(ctx, user);
+ return true;
+ }
+
+ const takerIsBlocked = await Block.exists({ blocker_tg_id: otherUser.tg_id, blocked_tg_id: user.tg_id });
+ if (takerIsBlocked) {
+ await messages.userTakerIsBlockedByUserOrder(ctx, user);
+ return true;
+ }
+
+ return false;
+}; Then update the const userOffer = await User.findOne({_id: order.buyer_id});
- const userOfferIsBlocked = await Block.exists({ blocker_tg_id: user.tg_id, blocked_tg_id: userOffer.tg_id });
- const takerIsBlocked = await Block.exists({blocker_tg_id: userOffer.tg_id, blocked_tg_id: user.tg_id});
-
- if (userOfferIsBlocked)
- return await messages.userOrderIsBlockedByUserTaker(ctx, user);
-
- if (takerIsBlocked)
- return await messages.userTakerIsBlockedByUserOrder(ctx, user);
+ if (await checkBlockingStatus(ctx, user, userOffer)) {
+ return;
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
// We verify if the user is not banned on this community | ||||||||||||||||||||||||||||||||||||||
if (await isBannedFromCommunity(user, order.community_id)) | ||||||||||||||||||||||||||||||||||||||
return await messages.bannedUserErrorMessage(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
@@ -74,6 +86,17 @@ exports.takesell = async (ctx, bot, orderId) => { | |||||||||||||||||||||||||||||||||||||
if (!orderId) return; | ||||||||||||||||||||||||||||||||||||||
const order = await Order.findOne({ _id: orderId }); | ||||||||||||||||||||||||||||||||||||||
if (!order) return; | ||||||||||||||||||||||||||||||||||||||
const seller = await User.findOne({_id: order.seller_id}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const sellerIsBlocked = await Block.exists({ blocker_tg_id: user.tg_id, blocked_tg_id: seller.tg_id }); | ||||||||||||||||||||||||||||||||||||||
const buyerIsBlocked = await Block.exists({blocker_tg_id: seller.tg_id, blocked_tg_id: user.tg_id}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if (sellerIsBlocked) | ||||||||||||||||||||||||||||||||||||||
return await messages.userOrderIsBlockedByUserTaker(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if (buyerIsBlocked) | ||||||||||||||||||||||||||||||||||||||
return await messages.userTakerIsBlockedByUserOrder(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// We verify if the user is not banned on this community | ||||||||||||||||||||||||||||||||||||||
if (await isBannedFromCommunity(user, order.community_id)) | ||||||||||||||||||||||||||||||||||||||
return await messages.bannedUserErrorMessage(ctx, user); | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -634,3 +634,10 @@ privacy: | | |||||||||||||||||||||||||||||
*2. Wie wir die Informationen verwenden:* | ||||||||||||||||||||||||||||||
- _Reputationssystem:_ Um das Reputationssystem für jeden Benutzer aufzubauen und zu pflegen. | ||||||||||||||||||||||||||||||
- _Streitbeilegung:_ Im Falle eines Streits stellen wir dem Mediator (Löser) die folgenden Informationen zur Verfügung: Ihren Benutzernamen, Ihre Telegram-ID, die Anzahl der abgeschlossenen Transaktionen, die Bewertung des Gegenübers, die Anzahl der Tage, an denen Sie den Bot verwendet haben, und die Anzahl der angesammelten Streitfälle. | ||||||||||||||||||||||||||||||
user_already_blocked: User is already blocked | ||||||||||||||||||||||||||||||
user_blocked: User successfully blocked | ||||||||||||||||||||||||||||||
user_unblocked: User successfully unblocked | ||||||||||||||||||||||||||||||
blocklist_empty: You do not have any blocked user | ||||||||||||||||||||||||||||||
orders_in_process: There are orders in process with this user | ||||||||||||||||||||||||||||||
user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker | ||||||||||||||||||||||||||||||
user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you | ||||||||||||||||||||||||||||||
Comment on lines
+637
to
+643
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Translate the new messages to German to maintain consistency. The new messages for user blocking functionality are in English while this file is for German translations. Apply this diff to add German translations: -user_already_blocked: User is already blocked
-user_blocked: User successfully blocked
-user_unblocked: User successfully unblocked
-blocklist_empty: You do not have any blocked user
-orders_in_process: There are orders in process with this user
-user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker
-user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you
+user_already_blocked: Benutzer ist bereits gesperrt
+user_blocked: Benutzer erfolgreich gesperrt
+user_unblocked: Benutzer erfolgreich entsperrt
+blocklist_empty: Du hast keine gesperrten Benutzer
+orders_in_process: Es gibt laufende Aufträge mit diesem Benutzer
+user_order_is_blocked_by_user_taker: Du kannst diesen Auftrag nicht annehmen, da du seinen Ersteller gesperrt hast
+user_taker_is_blocked_by_user_order: Du kannst diesen Auftrag nicht annehmen, da dich sein Ersteller gesperrt hat 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,3 +633,10 @@ privacy: | | |
*۲. نحوه استفاده ما از اطلاعات:* | ||
- _سیستم اعتبار:_ برای ایجاد و حفظ سیستم اعتبار برای هر کاربر. | ||
- _حل اختلافات:_ در صورت بروز اختلاف، اطلاعات زیر را در اختیار میانجی (حلکننده) قرار میدهیم: نام کاربری شما، شناسه تلگرام، تعداد تراکنشهای انجام شده، امتیاز طرف مقابل، تعداد روزهایی که از ربات استفاده کردهاید و تعداد اختلافات جمع شده. | ||
user_already_blocked: User is already blocked | ||
user_blocked: User successfully blocked | ||
user_unblocked: User successfully unblocked | ||
blocklist_empty: You do not have any blocked user | ||
orders_in_process: There are orders in process with this user | ||
user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker | ||
user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you | ||
Comment on lines
+636
to
+642
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Translate blocking messages to Persian/Farsi. The new blocking-related messages are currently in English and need to be translated to Persian/Farsi to maintain consistency with the rest of the locale file. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -633,3 +633,10 @@ privacy: | | |||||||||||||||||||||||||||||
*2. Comment nous utilisons les informations:* | ||||||||||||||||||||||||||||||
- _Système de réputation:_ Pour construire et maintenir le système de réputation de chaque utilisateur. | ||||||||||||||||||||||||||||||
- _Résolution des litiges:_ En cas de litige, nous fournissons au médiateur (solver) les informations suivantes : votre nom d'utilisateur, votre identifiant Telegram, le nombre de transactions effectuées, la note de la contrepartie, le nombre de jours d'utilisation du bot et le nombre de litiges accumulés. | ||||||||||||||||||||||||||||||
user_already_blocked: User is already blocked | ||||||||||||||||||||||||||||||
user_blocked: User successfully blocked | ||||||||||||||||||||||||||||||
user_unblocked: User successfully unblocked | ||||||||||||||||||||||||||||||
blocklist_empty: You do not have any blocked user | ||||||||||||||||||||||||||||||
orders_in_process: There are orders in process with this user | ||||||||||||||||||||||||||||||
user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker | ||||||||||||||||||||||||||||||
user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you | ||||||||||||||||||||||||||||||
Comment on lines
+636
to
+642
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing French translations for user blocking messages. The new messages are currently in English and need to be translated to French to maintain consistency with the rest of the file. Here are the messages that need translation: -user_already_blocked: User is already blocked
-user_blocked: User successfully blocked
-user_unblocked: User successfully unblocked
-blocklist_empty: You do not have any blocked user
-orders_in_process: There are orders in process with this user
-user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker
-user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you
+user_already_blocked: L'utilisateur est déjà bloqué
+user_blocked: Utilisateur bloqué avec succès
+user_unblocked: Utilisateur débloqué avec succès
+blocklist_empty: Vous n'avez aucun utilisateur bloqué
+orders_in_process: Il y a des ordres en cours avec cet utilisateur
+user_order_is_blocked_by_user_taker: Vous ne pouvez pas accepter cette offre car vous avez bloqué son créateur
+user_taker_is_blocked_by_user_order: Vous ne pouvez pas accepter cette offre car son créateur vous a bloqué 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -631,3 +631,10 @@ privacy: | | |||||||||||||||||||||||||||||
*2. Come utilizziamo le informazioni:* | ||||||||||||||||||||||||||||||
- _Sistema di reputazione:_ Per costruire e mantenere il sistema di reputazione di ciascun utente. | ||||||||||||||||||||||||||||||
- _Risoluzione delle controversie:_ In caso di controversia, forniamo al mediatore (solver) le seguenti informazioni: il tuo nome utente, ID Telegram, numero di transazioni completate, valutazione della controparte, numero di giorni di utilizzo del bot e numero di controversie accumulate. | ||||||||||||||||||||||||||||||
user_already_blocked: User is already blocked | ||||||||||||||||||||||||||||||
user_blocked: User successfully blocked | ||||||||||||||||||||||||||||||
user_unblocked: User successfully unblocked | ||||||||||||||||||||||||||||||
blocklist_empty: You do not have any blocked user | ||||||||||||||||||||||||||||||
orders_in_process: There are orders in process with this user | ||||||||||||||||||||||||||||||
user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker | ||||||||||||||||||||||||||||||
user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you | ||||||||||||||||||||||||||||||
Comment on lines
+634
to
+640
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Italian translations for user blocking messages. The new messages are currently in English and need to be translated to Italian to maintain consistency with the rest of the file. Here are the messages that need translation: -user_already_blocked: User is already blocked
-user_blocked: User successfully blocked
-user_unblocked: User successfully unblocked
-blocklist_empty: You do not have any blocked user
-orders_in_process: There are orders in process with this user
-user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker
-user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you
+user_already_blocked: L'utente è già bloccato
+user_blocked: Utente bloccato con successo
+user_unblocked: Utente sbloccato con successo
+blocklist_empty: Non hai alcun utente bloccato
+orders_in_process: Ci sono ordini in corso con questo utente
+user_order_is_blocked_by_user_taker: Non puoi accettare questo ordine perché hai bloccato il suo creatore
+user_taker_is_blocked_by_user_order: Non puoi accettare questo ordine perché il suo creatore ti ha bloccato 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -631,3 +631,10 @@ privacy: | | |||||||||||||||||||||||||||||
*2. Como Usamos as Informações:* | ||||||||||||||||||||||||||||||
- _Sistema de Reputação:_ Para construir e manter o sistema de reputação de cada usuário. | ||||||||||||||||||||||||||||||
- _Resolução de Disputas:_ Em caso de uma disputa, fornecemos ao mediador (solver) as seguintes informações: seu nome de usuário, ID do Telegram, número de transações concluídas, classificação da contraparte, número de dias usando o bot e o número de disputas acumuladas. | ||||||||||||||||||||||||||||||
user_already_blocked: User is already blocked | ||||||||||||||||||||||||||||||
user_blocked: User successfully blocked | ||||||||||||||||||||||||||||||
user_unblocked: User successfully unblocked | ||||||||||||||||||||||||||||||
blocklist_empty: You do not have any blocked user | ||||||||||||||||||||||||||||||
orders_in_process: There are orders in process with this user | ||||||||||||||||||||||||||||||
user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker | ||||||||||||||||||||||||||||||
user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you | ||||||||||||||||||||||||||||||
Comment on lines
+634
to
+640
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Portuguese translations for user blocking messages. The new messages are currently in English and need to be translated to Portuguese to maintain consistency with the rest of the file. Here are the messages that need translation: -user_already_blocked: User is already blocked
-user_blocked: User successfully blocked
-user_unblocked: User successfully unblocked
-blocklist_empty: You do not have any blocked user
-orders_in_process: There are orders in process with this user
-user_order_is_blocked_by_user_taker: You can't take this order because you blocked its maker
-user_taker_is_blocked_by_user_order: You can't take this order because its maker blocked you
+user_already_blocked: Usuário já está bloqueado
+user_blocked: Usuário bloqueado com sucesso
+user_unblocked: Usuário desbloqueado com sucesso
+blocklist_empty: Você não tem nenhum usuário bloqueado
+orders_in_process: Existem ordens em andamento com este usuário
+user_order_is_blocked_by_user_taker: Você não pode aceitar esta oferta porque bloqueou seu criador
+user_taker_is_blocked_by_user_order: Você não pode aceitar esta oferta porque seu criador bloqueou você 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||
import mongoose, { Document, Schema } from 'mongoose'; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export interface IBlock extends Document { | ||||||||||||||||||||||||||||
blocker_tg_id: string; | ||||||||||||||||||||||||||||
blocked_tg_id: string; | ||||||||||||||||||||||||||||
created_at: Date; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const blockSchema = new Schema<IBlock>({ | ||||||||||||||||||||||||||||
blocker_tg_id: { type: String }, | ||||||||||||||||||||||||||||
blocked_tg_id: { type: String }, | ||||||||||||||||||||||||||||
created_at: { type: Date, default: Date.now }, | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add indexes and field validation to the schema. The current schema could benefit from:
const blockSchema = new Schema<IBlock>({
- blocker_tg_id: { type: String },
- blocked_tg_id: { type: String },
+ blocker_tg_id: { type: String, required: true, index: true },
+ blocked_tg_id: { type: String, required: true, index: true },
created_at: { type: Date, default: Date.now },
});
+
+// Prevent duplicate blocks
+blockSchema.index({ blocker_tg_id: 1, blocked_tg_id: 1 }, { unique: true }); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export default mongoose.model<IBlock>('Block', blockSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add input validation and improve error handling.
The function needs improvements in several areas:
Apply this diff to improve the function: