feat(chat): add chat room management functionality
- Created new chat schema in the database. - Implemented chat room model with necessary fields (title, ownerId, roomTypeId, etc.). - Added room type model and rights model for chat functionality. - Developed API endpoints for managing chat rooms, including create, edit, and delete operations. - Integrated chat room management into the admin interface with a dedicated view and dialog for room creation/editing. - Added internationalization support for chat room management UI. - Implemented autocomplete for victim selection in underground activities. - Enhanced the underground view with new activity types and political target selection.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import RoomType from './chat/room_type.js';
|
||||
import ChatRight from './chat/rights.js';
|
||||
import ChatUserRight from './chat/user_rights.js';
|
||||
import ChatUser from './chat/user.js';
|
||||
import Room from './chat/room.js';
|
||||
import User from './community/user.js';
|
||||
import UserParam from './community/user_param.js';
|
||||
import UserParamType from './type/user_param.js';
|
||||
@@ -92,6 +97,31 @@ import Underground from './falukant/data/underground.js';
|
||||
import UndergroundType from './falukant/type/underground.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
// RoomType 1:n Room
|
||||
RoomType.hasMany(Room, { foreignKey: 'roomTypeId', as: 'rooms' });
|
||||
Room.belongsTo(RoomType, { foreignKey: 'roomTypeId', as: 'roomType' });
|
||||
// ChatUser <-> ChatRight n:m
|
||||
ChatUser.belongsToMany(ChatRight, {
|
||||
through: ChatUserRight,
|
||||
foreignKey: 'chat_user_id',
|
||||
otherKey: 'chat_right_id',
|
||||
as: 'rights',
|
||||
});
|
||||
ChatRight.belongsToMany(ChatUser, {
|
||||
through: ChatUserRight,
|
||||
foreignKey: 'chat_right_id',
|
||||
otherKey: 'chat_user_id',
|
||||
as: 'users',
|
||||
});
|
||||
// ChatUser zu FalukantUser
|
||||
ChatUser.belongsTo(FalukantUser, { foreignKey: 'falukant_user_id', as: 'falukantUser' });
|
||||
FalukantUser.hasOne(ChatUser, { foreignKey: 'falukant_user_id', as: 'chatUser' });
|
||||
// Chat Room associations
|
||||
Room.belongsTo(User, { foreignKey: 'owner_id', as: 'owner' });
|
||||
User.hasMany(Room, { foreignKey: 'owner_id', as: 'ownedRooms' });
|
||||
|
||||
Room.belongsTo(UserParamValue, { foreignKey: 'gender_restriction_id', as: 'genderRestriction' });
|
||||
UserParamValue.hasMany(Room, { foreignKey: 'gender_restriction_id', as: 'roomsWithGenderRestriction' });
|
||||
// UserParam related associations
|
||||
SettingsType.hasMany(UserParamType, { foreignKey: 'settingsId', as: 'user_param_types' });
|
||||
UserParamType.belongsTo(SettingsType, { foreignKey: 'settingsId', as: 'settings_type' });
|
||||
|
||||
0
backend/models/chat/index.js
Normal file
0
backend/models/chat/index.js
Normal file
22
backend/models/chat/rights.js
Normal file
22
backend/models/chat/rights.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
|
||||
const ChatRight = sequelize.define('ChatRight', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
tr: {
|
||||
type: DataTypes.STRING(32),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
}, {
|
||||
schema: 'chat',
|
||||
tableName: 'rights',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default ChatRight;
|
||||
69
backend/models/chat/room.js
Normal file
69
backend/models/chat/room.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
|
||||
const Room = sequelize.define('Room', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
ownerId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true, // kann null sein, wenn system-owned
|
||||
},
|
||||
roomTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
isPublic: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
genderRestrictionId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
minAge: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
maxAge: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
passwordHash: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
friendsOfOwnerOnly: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
requiredUserRightId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
||||
schema: 'chat',
|
||||
tableName: 'room',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{
|
||||
name: 'idx_chat_room_owner',
|
||||
fields: ['owner_id'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default Room;
|
||||
22
backend/models/chat/room_type.js
Normal file
22
backend/models/chat/room_type.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
|
||||
const RoomType = sequelize.define('RoomType', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
tr: {
|
||||
type: DataTypes.STRING(32),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
}, {
|
||||
schema: 'chat',
|
||||
tableName: 'room_type',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default RoomType;
|
||||
41
backend/models/chat/user.js
Normal file
41
backend/models/chat/user.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
|
||||
const ChatUser = sequelize.define('ChatUser', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
falukant_user_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: 'Verknüpfung zu community.falukant_user',
|
||||
},
|
||||
display_name: {
|
||||
type: DataTypes.STRING(64),
|
||||
allowNull: false,
|
||||
},
|
||||
color: {
|
||||
type: DataTypes.STRING(16), // z.B. Hex-Code
|
||||
allowNull: false,
|
||||
defaultValue: '#000000',
|
||||
},
|
||||
show_gender: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
show_age: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
}, {
|
||||
schema: 'chat',
|
||||
tableName: 'user',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default ChatUser;
|
||||
26
backend/models/chat/user_rights.js
Normal file
26
backend/models/chat/user_rights.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import ChatUser from './user.js';
|
||||
import ChatRight from './rights.js';
|
||||
|
||||
const ChatUserRight = sequelize.define('ChatUserRight', {
|
||||
chatUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
references: null, // Assoziation wird separat gesetzt
|
||||
},
|
||||
chatRightId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
references: null, // Assoziation wird separat gesetzt
|
||||
},
|
||||
}, {
|
||||
schema: 'chat',
|
||||
tableName: 'user_rights',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default ChatUserRight;
|
||||
@@ -99,6 +99,12 @@ import ElectionHistory from './falukant/log/election_history.js';
|
||||
import UndergroundType from './falukant/type/underground.js';
|
||||
import Underground from './falukant/data/underground.js';
|
||||
|
||||
import Room from './chat/room.js';
|
||||
import ChatUser from './chat/user.js';
|
||||
import ChatRight from './chat/rights.js';
|
||||
import ChatUserRight from './chat/user_rights.js';
|
||||
import RoomType from './chat/room_type.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
UserParamValue,
|
||||
@@ -197,6 +203,11 @@ const models = {
|
||||
ElectionHistory,
|
||||
UndergroundType,
|
||||
Underground,
|
||||
Room,
|
||||
ChatUser,
|
||||
ChatRight,
|
||||
ChatUserRight,
|
||||
RoomType,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
Reference in New Issue
Block a user