Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fa777c3
* Add unique constraints on community group, dispute channel and orde…
Luquitasjeffrey May 12, 2026
08a3f6c
Code formatting
Luquitasjeffrey May 12, 2026
bff1b51
add migration script to resolve community channel and group duplicate…
Luquitasjeffrey May 14, 2026
4f5ffe0
Add test cases for community migration script
Luquitasjeffrey May 14, 2026
26c23e6
Remove redundant logs from migration script unit tests
Luquitasjeffrey May 14, 2026
67c71c6
Use db_connect to connect to mongoose in the migration script
Luquitasjeffrey May 14, 2026
d4e9b60
Set channel name to undefined when community owner is not admin
Luquitasjeffrey May 14, 2026
80a063a
Fix lint errors
Luquitasjeffrey May 14, 2026
2ce96f9
Test should reflect script behaviour. It should set order channel nam…
Luquitasjeffrey May 14, 2026
518f5ad
Send a message to the user if community channel validations fails
Luquitasjeffrey May 16, 2026
d6a7a6f
Merge remote-tracking branch 'upstream/main' into revalidate-communit…
Luquitasjeffrey May 16, 2026
e4ae6e5
Wrap sendMessage in a try/catch block in the case community channel v…
Luquitasjeffrey May 16, 2026
9b1c8f3
Code formatting
Luquitasjeffrey May 16, 2026
d79306f
Update migration script: communities with duplicated order channels s…
Luquitasjeffrey May 16, 2026
a6fa750
Add logging when community channel validation fails, and remove the u…
Luquitasjeffrey May 16, 2026
673b23e
Community order channel name should not be undefined, update model ac…
Luquitasjeffrey May 16, 2026
5a0c53f
Fix fallback in getOrderChannel
Luquitasjeffrey May 19, 2026
1cf0c03
Added manual resolution on the migration script for communities that …
Luquitasjeffrey May 20, 2026
8ee02f1
Fix CI
Luquitasjeffrey May 20, 2026
f52b917
Code formatting
Luquitasjeffrey May 20, 2026
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
16 changes: 12 additions & 4 deletions bot/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,12 @@ const publishBuyOrderMessage = async (
let publishMessage = `⚡️🍊⚡️\n${order.description}\n`;
publishMessage += `:${order._id}:`;

const channel = await getOrderChannel(order);
if (channel === undefined) throw new Error('channel is undefined');
const channel = await getOrderChannel(order, bot.telegram);
if (channel === undefined) {
order.status = 'CLOSED';
await order.save();
throw new Error('channel is undefined');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// Get the community language if available
let communityI18n = i18n;
Expand Down Expand Up @@ -782,8 +786,12 @@ const publishSellOrderMessage = async (
try {
let publishMessage = `⚡️🍊⚡️\n${order.description}\n`;
publishMessage += `:${order._id}:`;
const channel = await getOrderChannel(order);
if (channel === undefined) throw new Error('channel is undefined');
const channel = await getOrderChannel(order, ctx.telegram);
if (channel === undefined) {
order.status = 'CLOSED';
await order.save();
throw new Error('channel is undefined');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// Get the community language if available
let communityI18n = i18n;
Expand Down
6 changes: 3 additions & 3 deletions models/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IOrderChannel extends Document {
}

const OrderChannelSchema = new Schema<IOrderChannel>({
name: { type: String, required: true, trim: true },
name: { type: String, required: true, unique: true },
type: {
type: String,
enum: ['buy', 'sell', 'mixed'],
Expand Down Expand Up @@ -64,7 +64,7 @@ const CommunitySchema = new Schema<ICommunity>({
required: true,
},
creator_id: { type: String },
group: { type: String, trim: true }, // group Id or public name
group: { type: String, unique: true }, // group Id or public name
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
order_channels: {
// array of Id or public name of channels
type: [OrderChannelSchema],
Expand All @@ -73,7 +73,7 @@ const CommunitySchema = new Schema<ICommunity>({
fee: { type: Number, min: 0, max: 100, default: 0 },
earnings: { type: Number, default: 0 }, // Sats amount to be paid to the community
orders_to_redeem: { type: Number, default: 0 }, // Number of orders calculated to be redeemed
dispute_channel: { type: String }, // Id or public name, channel to send new disputes
dispute_channel: { type: String, unique: true }, // Id or public name, channel to send new disputes
solvers: [usernameIdSchema], // users that are dispute solvers
banned_users: [usernameIdSchema], // users that are banned from the community
public: { type: Boolean, default: true },
Expand Down
18 changes: 16 additions & 2 deletions util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Telegram } from 'telegraf';
import axios from 'axios';
import fiatJson from './fiat.json';
import languagesJson from './languages.json';
import { Order, Community } from '../models';
import { Order, Community, User } from '../models';
import { logger } from '../logger';
import QRCode from 'qrcode';
import { Image, createCanvas } from 'canvas';
Expand Down Expand Up @@ -318,7 +318,7 @@ const deleteOrderFromChannel = async (order: IOrder, telegram: Telegram) => {
}
};

const getOrderChannel = async (order: IOrder) => {
const getOrderChannel = async (order: IOrder, bot?: Telegram) => {
Comment thread
Luquitasjeffrey marked this conversation as resolved.
let channel = process.env.CHANNEL;
if (order.community_id) {
const community = await Community.findOne({ _id: order.community_id });
Expand All @@ -334,6 +334,20 @@ const getOrderChannel = async (order: IOrder) => {
}
});
}
const communityOwner = await User.findById(community.creator_id);
if (!communityOwner) {
return undefined;
}

if (bot && channel) {
// Validate order channel if the caller of this function passed the bot instance to perform the validation
// If it was not passed as a parameter the order channel can be trusted because its for ui purposes (listorders for example)
// This validation is performed lazily when publishing the order to the community order channel
const isChannelOk = await isGroupAdmin(channel, communityOwner, bot);
if (!isChannelOk.success) {
return undefined;
}
}
}

return channel;
Expand Down
Loading