Add password reset localization and chat configuration
- Implemented German and English localization for password reset functionality. - Added WebSocket URL resolution logic in chat services to support various environments and configurations. - Created centralized chat configuration for event keys and payload mappings. - Developed RoomsView component for admin chat room management, including create, edit, and delete functionalities.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import chatService from '../services/chatService.js';
|
||||
import Joi from 'joi';
|
||||
|
||||
class ChatController {
|
||||
constructor() {
|
||||
@@ -11,12 +12,20 @@ class ChatController {
|
||||
this.initOneToOne = this.initOneToOne.bind(this);
|
||||
this.sendOneToOneMessage = this.sendOneToOneMessage.bind(this);
|
||||
this.getOneToOneMessageHistory = this.getOneToOneMessageHistory.bind(this);
|
||||
this.getRoomList = this.getRoomList.bind(this);
|
||||
}
|
||||
|
||||
async getMessages(req, res) {
|
||||
const { to, from } = req.body;
|
||||
const schema = Joi.object({
|
||||
to: Joi.string().required(),
|
||||
from: Joi.string().required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
const messages = await chatService.getMessages(to, from);
|
||||
const messages = await chatService.getMessages(value.to, value.from);
|
||||
res.status(200).json(messages);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -24,9 +33,17 @@ class ChatController {
|
||||
}
|
||||
|
||||
async findRandomChatMatch(req, res) {
|
||||
const { genders, age, id } = req.body;
|
||||
const schema = Joi.object({
|
||||
genders: Joi.array().items(Joi.string()).required(),
|
||||
age: Joi.number().integer().min(0).required(),
|
||||
id: Joi.string().required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
const match = await chatService.findMatch(genders, age, id);
|
||||
const match = await chatService.findMatch(value.genders, value.age, value.id);
|
||||
if (match) {
|
||||
res.status(200).json({ status: 'matched', user: match });
|
||||
} else {
|
||||
@@ -38,9 +55,16 @@ class ChatController {
|
||||
}
|
||||
|
||||
async registerUser(req, res) {
|
||||
const { gender, age } = req.body;
|
||||
const schema = Joi.object({
|
||||
gender: Joi.string().required(),
|
||||
age: Joi.number().integer().min(0).required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
const userId = await chatService.registerUser(gender, age);
|
||||
const userId = await chatService.registerUser(value.gender, value.age);
|
||||
res.status(200).json({ id: userId });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -48,9 +72,17 @@ class ChatController {
|
||||
}
|
||||
|
||||
async sendMessage(req, res) {
|
||||
const { from, to, text } = req.body;
|
||||
const schema = Joi.object({
|
||||
from: Joi.string().required(),
|
||||
to: Joi.string().required(),
|
||||
text: Joi.string().min(1).max(2000).required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
const message = await chatService.addMessage(from, to, text);
|
||||
const message = await chatService.addMessage(value.from, value.to, value.text);
|
||||
res.status(200).json(message);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -58,9 +90,15 @@ class ChatController {
|
||||
}
|
||||
|
||||
async removeUser(req, res) {
|
||||
const { id } = req.body;
|
||||
const schema = Joi.object({
|
||||
id: Joi.string().required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
await chatService.removeUser(id);
|
||||
await chatService.removeUser(value.id);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -68,9 +106,15 @@ class ChatController {
|
||||
}
|
||||
|
||||
async stopChat(req, res) {
|
||||
const { id } = req.body;
|
||||
const schema = Joi.object({
|
||||
id: Joi.string().required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
await chatService.endChat(id);
|
||||
await chatService.endChat(value.id);
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -78,10 +122,16 @@ class ChatController {
|
||||
}
|
||||
|
||||
async initOneToOne(req, res) {
|
||||
const schema = Joi.object({
|
||||
partnerHashId: Joi.string().required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { partnerHashId } = req.body;
|
||||
try {
|
||||
await chatService.initOneToOne(hashedUserId, partnerHashId);
|
||||
await chatService.initOneToOne(hashedUserId, value.partnerHashId);
|
||||
res.status(200).json({ message: 'One-to-one chat initialization is pending implementation.' });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -89,9 +139,17 @@ class ChatController {
|
||||
}
|
||||
|
||||
async sendOneToOneMessage(req, res) {
|
||||
const { user1HashId, user2HashId, message } = req.body;
|
||||
const schema = Joi.object({
|
||||
user1HashId: Joi.string().required(),
|
||||
user2HashId: Joi.string().required(),
|
||||
message: Joi.string().min(1).max(2000).required()
|
||||
});
|
||||
const { error, value } = schema.validate(req.body);
|
||||
if (error) {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
await chatService.sendOneToOneMessage(user1HashId, user2HashId, message);
|
||||
await chatService.sendOneToOneMessage(value.user1HashId, value.user2HashId, value.message);
|
||||
res.status(200).json({ status: 'message sent' });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
@@ -107,6 +165,16 @@ class ChatController {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getRoomList(req, res) {
|
||||
// Öffentliche Räume für Chat-Frontend
|
||||
try {
|
||||
const rooms = await chatService.getRoomList();
|
||||
res.status(200).json(rooms);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ChatController;
|
||||
|
||||
Reference in New Issue
Block a user