diff --git a/.cursor/rules/general.mdc b/.cursor/rules/general.mdc index 1721dab..f15db0b 100644 --- a/.cursor/rules/general.mdc +++ b/.cursor/rules/general.mdc @@ -9,5 +9,12 @@ When working with this project, follow these rules: - Do NOT "test the implementation" when you are done. The only exception is when you need to typecheck or build the app, in that case: - - To typecheck, run "npm run frontend:typecheck". - - To build, run "npm run frontend:build". \ No newline at end of file + - To typecheck, run `npm run frontend:typecheck`. + - To build, run `npm run frontend:build`. + + Do NOT execute other commands like "cd". +- Do NOT "cd" to the project directory. +- If possible, try to update files in a single edit. +- When you need a delay, use `await delay(millis);` in an async function. If the current function is not async, + make it async. The import is `/frontend/src/utils/utils`. +- When you complete your task, remove unused imports if there are any. \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 44ac70d..df1c2c7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,9 +2,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Run", - "type": "shell", - "command": "npm run dev", + "label": "Backend", + "type": "npm", + "script": "backend:run", "options": { "cwd": "${workspaceFolder}" }, @@ -16,23 +16,73 @@ }, "group": { "kind": "build" + }, + "isBackground": true + }, + { + "label": "Frontend (Web)", + "type": "npm", + "script": "frontend:dev", + "options": { + "cwd": "${workspaceFolder}" + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + }, + "group": { + "kind": "build", + }, + "isBackground": true + }, + { + "label": "Frontend (Electron)", + "type": "npm", + "script": "frontend:electron:dev", + "options": { + "cwd": "${workspaceFolder}" + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + }, + "group": { + "kind": "build" + }, + "isBackground": true + }, + + { + "label": "Web", + "dependsOn": ["Backend", "Frontend (Web)"], + "dependsOrder": "parallel", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" } }, { - "label": "Run (Electron)", - "type": "shell", - "command": "npm run dev:electron", - "options": { - "cwd": "${workspaceFolder}" + "label": "Electron", + "dependsOn": ["Backend", "Frontend (Electron)"], + "dependsOrder": "parallel", + "group": { + "kind": "build" }, "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" - }, - "group": { - "kind": "build" } } ] diff --git a/backend/routes/account.py b/backend/routes/account.py index 5b51f54..037873e 100644 --- a/backend/routes/account.py +++ b/backend/routes/account.py @@ -17,6 +17,8 @@ def convert_user(user: User) -> dict: "last_seen": user.last_seen.isoformat(), "online": user.online, "username": user.username, + "profile_picture": user.profile_picture, + "bio": user.bio, "admin": user.username == OWNER_USERNAME } diff --git a/backend/routes/messaging.py b/backend/routes/messaging.py index 79a3ef3..2868f59 100644 --- a/backend/routes/messaging.py +++ b/backend/routes/messaging.py @@ -304,7 +304,8 @@ class MessaggingSocketManager: db.add(env) db.commit() db.refresh(env) - await self.send_to_user(env.recipient_id, { + + payload = { "type": "dmNew", "data": { "id": env.id, @@ -317,8 +318,11 @@ class MessaggingSocketManager: "wrappedMk": env.wrapped_mk_b64, "timestamp": env.timestamp.isoformat(), } - }) - await websocket.send_json({"type": type, "data": {"status": "ok", "id": env.id}}) + } + + await self.send_to_user(env.recipient_id, payload); + await websocket.send_json({"type": type, "data": {"status": "ok", "id": env.id}}); + await self.send_to_user(env.sender_id, payload); except HTTPException as e: await self.send_error(websocket, type, e) elif type == "editMessage": diff --git a/backend/routes/profile.py b/backend/routes/profile.py index c1fa26f..421ee09 100644 --- a/backend/routes/profile.py +++ b/backend/routes/profile.py @@ -8,9 +8,15 @@ import io from dependencies import get_db, get_current_user from models import User, UpdateBioRequest, UserProfileResponse +from pydantic import BaseModel router = APIRouter() +# Request models +class UpdateProfileRequest(BaseModel): + nickname: str | None = None + description: str | None = None + # Create uploads directory if it doesn't exist PROFILE_PICTURES_DIR = Path("data/uploads/pfp") @@ -98,6 +104,56 @@ async def get_user_profile( "created_at": current_user.created_at } +@router.put("/user/profile") +async def update_user_profile( + request: UpdateProfileRequest, + current_user: User = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Update current user's profile information + """ + updated = False + + # Update username if provided + if request.nickname is not None: + nickname = request.nickname.strip() + if len(nickname) < 3: + raise HTTPException(status_code=400, detail="Username must be at least 3 characters long") + if len(nickname) > 50: + raise HTTPException(status_code=400, detail="Username must be 50 characters or less") + + # Check if username is already taken by another user + existing_user = db.query(User).filter(User.username == nickname, User.id != current_user.id).first() + if existing_user: + raise HTTPException(status_code=400, detail="Username already taken") + + current_user.username = nickname + updated = True + + # Update bio if provided + if request.description is not None: + bio = request.description.strip() + if len(bio) > 500: + raise HTTPException(status_code=400, detail="Bio must be 500 characters or less") + + current_user.bio = bio + updated = True + + if updated: + db.commit() + return { + "message": "Profile updated successfully", + "username": current_user.username, + "bio": current_user.bio + } + else: + return { + "message": "No changes made", + "username": current_user.username, + "bio": current_user.bio + } + @router.put("/user/bio") async def update_user_bio( diff --git a/frontend/index.html b/frontend/index.html index e8e87be..9313291 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,124 +7,8 @@ -
-
-
- -
+ -
-
-
-

- login - Добро пожаловать! -

-

Войдите в свой аккаунт

-
-
-
- -
- - - - - - Войти -
- -
-

Ещё нет аккаунта? Зарегистрируйтесь

-
-
-
-
- - - - -