Skip to content

Commit d720b64

Browse files
Jules was unable to complete the task in time. Please review the work done so far and provide feedback for Jules to continue.
1 parent 796ca0d commit d720b64

File tree

17 files changed

+5801
-797
lines changed

17 files changed

+5801
-797
lines changed

config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import { mongo } from "mongoose";
33
const UserSettings = {
44
// Listed as BOT but is actually a user
55
// each "Setting" is a nice that will sit on the server and proxied through the websocket.
6-
nick : 'nick',
7-
username: 'El encuentro',
8-
gecos: 'El encuentro',
9-
password : '',
10-
realname : 'El encuentro',
11-
channels : [],
12-
host : 'irc.server.com',
13-
port : 6667,
146
auto_reconnect: false,
157
auto_reconnect_wait: 10000,
168
auto_reconnect_max_retries: 1,

jest.config.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
// Automatically clear mock calls and instances between every test
5+
clearMocks: true,
6+
// The directory where Jest should output its coverage files
7+
coverageDirectory: 'coverage',
8+
// A list of paths to directories that Jest should use to search for files in
9+
roots: ['<rootDir>/tests'],
10+
// The glob patterns Jest uses to detect test files
11+
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
12+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
13+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
14+
};

main.ts

Lines changed: 102 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,102 @@
1-
import Express from "express";
2-
import Cors from "cors";
3-
import morgan from "morgan";
4-
import UserSettings from "./config";
5-
import MongooseDal from "./services/mongo";
6-
import { IChannel } from "./models/channel";
7-
import { routes } from "./router";
8-
import { createServer } from "http";
9-
import { SocketService } from "./services/socket";
10-
import { connect } from "./router/chanserv";
11-
import IrcService from "./services/ircService";
12-
import { isLoggedIn } from "./middleware/auth";
13-
14-
MongooseDal.connect().then(
15-
() => {
16-
console.log("Connected to MongoDB");
17-
},
18-
(err) => {
19-
console.log(err);
20-
}
21-
);
22-
23-
const app = Express();
24-
25-
const httpServer = createServer(app);
26-
const socketService = new SocketService(httpServer);
27-
const clientService = new IrcService(socketService);
28-
29-
const client = clientService.getClient();
30-
31-
socketService.configureClient();
32-
33-
app.use(Cors());
34-
app.use(Express.json());
35-
app.use(Express.urlencoded({ extended: true }));
36-
app.use(morgan("dev"));
37-
38-
app.use("/", routes);
39-
app.post("/connect", isLoggedIn, connect(clientService));
40-
41-
app.use("/static", Express.static("public"));
42-
app.use("/login", Express.static("public/login/login.html"));
43-
44-
app.post("/join/dm/:nick", isLoggedIn, async (req, res) => {
45-
const nick = req.params.nick;
46-
var dms = await MongooseDal.getDirectMessagesForUser(UserSettings.nick, nick);
47-
res.send({ nick: nick, messages: dms?.messages || [] });
48-
});
49-
50-
app.post("/channel/join", isLoggedIn, async (req, res) => {
51-
const socketConnections = socketService.getConnections();
52-
const channel = client.channel("#" + req.body.channel, req.body.key);
53-
54-
channel.join("#" + req.body.channel, req.body.key);
55-
56-
let channelMongo: IChannel = {
57-
active: true,
58-
name: req.body.channel,
59-
description: "Test Channel",
60-
owner: UserSettings.nick,
61-
created_at: new Date(),
62-
updated_at: new Date(),
63-
messages: [],
64-
};
65-
66-
var channelMessages = await MongooseDal.getMessagesForChannel(req.body.channel);
67-
await MongooseDal.createChannel(channelMongo);
68-
69-
channel.updateUsers(() => {
70-
var users = channel.users;
71-
socketConnections.forEach((socket) => {
72-
socket.socket.emit("channel:joined", {
73-
channel: req.body.channel,
74-
users: users,
75-
messages: channelMessages?.messages || [],
76-
});
77-
});
78-
res.send({ users: users, channel: req.body.channel });
79-
});
80-
});
81-
82-
httpServer.listen(3000, () => {
83-
console.log("listening on *:3000");
84-
});
1+
import Express from "express";
2+
import Cors from "cors";
3+
import morgan from "morgan";
4+
import UserSettings from "./config";
5+
import MongooseDal from "./services/mongo";
6+
import { IChannel } from "./models/channel";
7+
import { routes } from "./router"; // This will include the ircRouter via router/index.ts
8+
import { createServer } from "http";
9+
import { SocketService } from "./services/socket";
10+
// import { connect } from "./router/chanserv"; // This 'connect' was for the old /connect route
11+
import IrcService from "./services/ircService";
12+
import { isLoggedIn } from "./middleware/auth";
13+
14+
MongooseDal.connect().then(
15+
() => {
16+
console.log("Connected to MongoDB");
17+
},
18+
(err) => {
19+
console.log(err);
20+
}
21+
);
22+
23+
const app = Express();
24+
25+
const httpServer = createServer(app);
26+
const socketService = new SocketService(httpServer);
27+
// Export clientService so it can be imported by router/irc.ts
28+
export const clientService = new IrcService(socketService);
29+
30+
// const client = clientService.getClient();
31+
// TODO: The line above gets a single client, which is part of the old architecture.
32+
// The app.post("/channel/join",...) route below uses this 'client' variable.
33+
// This route will be broken by this change and will need refactoring in a future task
34+
// to get the correct client instance (e.g., based on user and server) from clientService.
35+
// For now, an error will occur if /channel/join is called.
36+
// To avoid a hard crash on startup if 'client' is used elsewhere before being defined,
37+
// we can declare it, but it won't be functional for the old /channel/join.
38+
let client;
39+
40+
41+
socketService.configureClient();
42+
43+
app.use(Cors());
44+
app.use(Express.json());
45+
app.use(Express.urlencoded({ extended: true }));
46+
app.use(morgan("dev"));
47+
48+
// Prefix all routes from router/index.ts with /api
49+
app.use("/api", routes);
50+
// Remove old /connect route, it's now handled by /api/irc/connect via ircRouter
51+
// app.post("/connect", isLoggedIn, connect(clientService));
52+
53+
app.use("/static", Express.static("public"));
54+
app.use("/login", Express.static("public/login/login.html"));
55+
56+
app.post("/join/dm/:nick", isLoggedIn, async (req, res) => {
57+
const nick = req.params.nick;
58+
var dms = await MongooseDal.getDirectMessagesForUser(UserSettings.nick, nick);
59+
res.send({ nick: nick, messages: dms?.messages || [] });
60+
});
61+
62+
app.post("/channel/join", isLoggedIn, async (req, res) => {
63+
// TODO: This route needs refactoring due to changes in IrcService and client handling.
64+
// The 'client' variable used here is no longer the globally relevant IRC client instance.
65+
// This route will likely fail or behave unexpectedly until updated.
66+
if (!client) {
67+
return res.status(500).json({ message: "IRC client not available for channel join. Needs refactoring."});
68+
}
69+
const socketConnections = socketService.getConnections();
70+
const channel = client.channel("#" + req.body.channel, req.body.key);
71+
72+
channel.join("#" + req.body.channel, req.body.key);
73+
74+
let channelMongo: IChannel = {
75+
active: true,
76+
name: req.body.channel,
77+
description: "Test Channel",
78+
owner: UserSettings.nick, // TODO: This should ideally be the logged-in user's nick
79+
created_at: new Date(),
80+
updated_at: new Date(),
81+
messages: [],
82+
};
83+
84+
var channelMessages = await MongooseDal.getMessagesForChannel(req.body.channel);
85+
await MongooseDal.createChannel(channelMongo);
86+
87+
channel.updateUsers(() => {
88+
var users = channel.users;
89+
socketConnections.forEach((socket) => {
90+
socket.socket.emit("channel:joined", {
91+
channel: req.body.channel,
92+
users: users,
93+
messages: channelMessages?.messages || [],
94+
});
95+
});
96+
res.send({ users: users, channel: req.body.channel });
97+
});
98+
});
99+
100+
httpServer.listen(3000, () => {
101+
console.log("listening on *:3000");
102+
});

models/user.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
import { Schema, model, connect } from 'mongoose';
22

3+
export interface IIrcServer { // Add export here
4+
name: string;
5+
host: string;
6+
port: number;
7+
nick: string;
8+
password?: string;
9+
realname?: string;
10+
channels?: string[];
11+
}
12+
313
interface IUser {
414
username: string;
515
password: string;
616
email: string;
717
created_at: Date;
818
updated_at: Date;
19+
ircServers?: IIrcServer[];
920
}
1021

1122
const userSchema = new Schema<IUser>({
1223
username: { type: String, required: true },
1324
email: { type: String, required: true },
1425
password: { type: String, required: true },
1526
created_at: { type: Date, default: Date.now },
16-
updated_at: { type: Date, default: Date.now }
27+
updated_at: { type: Date, default: Date.now },
28+
ircServers: [{
29+
name: { type: String, required: true },
30+
host: { type: String, required: true },
31+
port: { type: Number, required: true },
32+
nick: { type: String, required: true },
33+
password: { type: String },
34+
realname: { type: String },
35+
channels: [{ type: String }]
36+
}]
1737
});
1838

1939
const User = model<IUser>('User', userSchema);

models/userSchema.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)