feat(ws): 在线状态管理(Redis SET + TTL 心跳续期)

- app/ws/online_service.go: 上线/下线/心跳续期/批量查询在线状态
- 集成到 WebSocket handler: 连接时写入 Redis, 断线时清除
- client.go: 添加 DisconnectHandler 回调
- Redis 键: echo:user:online (SET) + echo:user:status:{uid} (TTL 60s)

Made-with: Cursor
This commit is contained in:
bujinyuan
2026-03-02 17:10:13 +08:00
parent 632e3b9a28
commit 1c87a466a1
6 changed files with 233 additions and 32 deletions

View File

@@ -47,11 +47,12 @@ func InitializeApp(cfg *config.Config) (*App, error) {
userManageController := controller2.NewUserManageController(userManageService)
hub := ws.ProvideHub()
pubSub := ws.ProvidePubSub(client, hub)
handler := ws.ProvideWSHandler(hub, pubSub, jwtConfig)
onlineService := ws.ProvideOnlineService(client, hub, pubSub)
handler := ws.ProvideWSHandler(hub, pubSub, jwtConfig, onlineService)
friendshipDAO := dao3.NewFriendshipDAO(gormDB)
friendGroupDAO := dao3.NewFriendGroupDAO(gormDB)
contactService := service3.NewContactService(friendshipDAO, friendGroupDAO, pubSub)
contactController := controller3.NewContactController(contactService)
app := NewApp(cfg, gormDB, client, authService, authController, adminAuthController, userManageController, handler, hub, pubSub, contactController)
app := NewApp(cfg, gormDB, client, authService, authController, adminAuthController, userManageController, handler, hub, pubSub, onlineService, contactController)
return app, nil
}