adding chat features, admin features and bug fixes
This commit is contained in:
@@ -80,6 +80,91 @@ class NextcloudController {
|
||||
res.status(500).json({ success: false, message: 'Nextcloud-Trennung fehlgeschlagen' });
|
||||
}
|
||||
}
|
||||
|
||||
async getRooms(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const credentials = await userService.getNextcloudCredentials(req.user!.id);
|
||||
if (!credentials) {
|
||||
res.status(200).json({ success: true, data: { connected: false, rooms: [] } });
|
||||
return;
|
||||
}
|
||||
const rooms = await nextcloudService.getAllConversations(credentials.loginName, credentials.appPassword);
|
||||
res.status(200).json({ success: true, data: { connected: true, rooms, loginName: credentials.loginName } });
|
||||
} catch (error: any) {
|
||||
if (error?.code === 'NEXTCLOUD_AUTH_INVALID') {
|
||||
await userService.clearNextcloudCredentials(req.user!.id);
|
||||
res.status(200).json({ success: true, data: { connected: false, rooms: [] } });
|
||||
return;
|
||||
}
|
||||
logger.error('getRooms error', { error });
|
||||
res.status(500).json({ success: false, message: 'Nextcloud-Räume konnten nicht geladen werden' });
|
||||
}
|
||||
}
|
||||
|
||||
async getMessages(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const credentials = await userService.getNextcloudCredentials(req.user!.id);
|
||||
if (!credentials) {
|
||||
res.status(401).json({ success: false, message: 'Nextcloud nicht verbunden' });
|
||||
return;
|
||||
}
|
||||
const token = req.params.token as string;
|
||||
if (!token) {
|
||||
res.status(400).json({ success: false, message: 'Room token fehlt' });
|
||||
return;
|
||||
}
|
||||
const messages = await nextcloudService.getMessages(token, credentials.loginName, credentials.appPassword);
|
||||
res.status(200).json({ success: true, data: messages });
|
||||
} catch (error) {
|
||||
logger.error('getMessages error', { error });
|
||||
res.status(500).json({ success: false, message: 'Nachrichten konnten nicht geladen werden' });
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const credentials = await userService.getNextcloudCredentials(req.user!.id);
|
||||
if (!credentials) {
|
||||
res.status(401).json({ success: false, message: 'Nextcloud nicht verbunden' });
|
||||
return;
|
||||
}
|
||||
const token = req.params.token as string;
|
||||
const { message } = req.body;
|
||||
if (!token || !message || typeof message !== 'string' || message.trim().length === 0) {
|
||||
res.status(400).json({ success: false, message: 'Token und Nachricht erforderlich' });
|
||||
return;
|
||||
}
|
||||
if (message.length > 32000) {
|
||||
res.status(400).json({ success: false, message: 'Nachricht zu lang' });
|
||||
return;
|
||||
}
|
||||
await nextcloudService.sendMessage(token, message.trim(), credentials.loginName, credentials.appPassword);
|
||||
res.status(200).json({ success: true, data: null });
|
||||
} catch (error) {
|
||||
logger.error('sendMessage error', { error });
|
||||
res.status(500).json({ success: false, message: 'Nachricht konnte nicht gesendet werden' });
|
||||
}
|
||||
}
|
||||
|
||||
async markRoomAsRead(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const credentials = await userService.getNextcloudCredentials(req.user!.id);
|
||||
if (!credentials) {
|
||||
res.status(401).json({ success: false, message: 'Nextcloud nicht verbunden' });
|
||||
return;
|
||||
}
|
||||
const token = req.params.token as string;
|
||||
if (!token) {
|
||||
res.status(400).json({ success: false, message: 'Room token fehlt' });
|
||||
return;
|
||||
}
|
||||
await nextcloudService.markAsRead(token, credentials.loginName, credentials.appPassword);
|
||||
res.status(200).json({ success: true, data: null });
|
||||
} catch (error) {
|
||||
logger.error('markRoomAsRead error', { error });
|
||||
res.status(500).json({ success: false, message: 'Raum konnte nicht als gelesen markiert werden' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new NextcloudController();
|
||||
|
||||
Reference in New Issue
Block a user