Skip to content

Commit

Permalink
hotfix: 실시간 친구 접속 깃 문제 hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sejoonkimmm committed Feb 16, 2024
1 parent 87f1008 commit 1cfd454
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ volumes/
/frontend/node_modules/

## backend static ignore
/backend/static/
/backend/static/

## frontend SPA ignore
/frontend/index.html
8 changes: 4 additions & 4 deletions backend/friends/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)

@database_sync_to_async
def set_user_online(self, user_id, online=True):
def set_user_online(user_id, online=True):
User.objects.filter(id=user_id).update(is_online=online)

class FriendStatusConsumer(AsyncWebsocketConsumer):
Expand All @@ -23,8 +23,8 @@ async def connect(self):
)
await self.accept()
# 친구들에게 접속 상태 업데이트 전송
await self.notify_friends_online()
await self.set_user_online(self.user.id, online=True)
# await self.notify_friends_online()
await set_user_online(self.user.id, online=True)
logger.info(f"Websocket connection established for user {self.user.id}")
else:
logger.info("Websocket connection rejected")
Expand All @@ -38,7 +38,7 @@ async def disconnect(self, close_code):
)
# 친구들에게 접속 해제 상태 업데이트 전송
await self.notify_friends_offline()
await self.set_user_online(self.user.id, online=False)
await set_user_online(self.user.id, online=False)
logger.info(f"Websocket connection closed for user {self.user.id}")

async def notify_friends_online(self):
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<header id="header"></header>
<div id="app" style="width: 100vw; height: 88vh;"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>window.mode = "dev"</script>
<script>window.mode = "prod"</script>
<script type="module" src="main.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions frontend/src/header/mainHeader/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function MainHeader($container) {
response.json().then((data) => {
setUserInfo(data);
});
new WebSocket('wss://localhost/ws/friend_status/');
} else {
// TODO => 에러 페이지로 이동
navigate("/");
Expand Down

0 comments on commit 1cfd454

Please sign in to comment.