채팅 채널 입장 추가
This commit is contained in:
@ -221,8 +221,8 @@ type partyConfig struct {
|
||||
type groupParty struct {
|
||||
partyConfig
|
||||
sendUpstreamMessage func(*wshandler.UpstreamMessage)
|
||||
sendEnterRoomMessage func(groupID, accountID)
|
||||
sendLeaveRoomMessage func(groupID, accountID)
|
||||
enterRoom func(groupID, accountID)
|
||||
leaveRoom func(groupID, accountID)
|
||||
rh *gocommon.RedisonHandler
|
||||
}
|
||||
|
||||
@ -237,10 +237,10 @@ func (gp *groupParty) Initialize(sub *subTavern, cfg configDocument) error {
|
||||
gp.sendUpstreamMessage = func(msg *wshandler.UpstreamMessage) {
|
||||
sub.wsh.SendUpstreamMessage(sub.region, msg)
|
||||
}
|
||||
gp.sendEnterRoomMessage = func(gid groupID, accid accountID) {
|
||||
gp.enterRoom = func(gid groupID, accid accountID) {
|
||||
sub.wsh.EnterRoom(sub.region, gid.Hex(), accid)
|
||||
}
|
||||
gp.sendLeaveRoomMessage = func(gid groupID, accid accountID) {
|
||||
gp.leaveRoom = func(gid groupID, accid accountID) {
|
||||
sub.wsh.LeaveRoom(sub.region, gid.Hex(), accid)
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ func (gp *groupParty) JoinParty(w http.ResponseWriter, r *http.Request) {
|
||||
Tag: []string{"MemberDocFull"},
|
||||
})
|
||||
|
||||
gp.sendEnterRoomMessage(gid, mid)
|
||||
gp.enterRoom(gid, mid)
|
||||
|
||||
// 새 멤버에 그룹 전체를 알림
|
||||
gp.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
@ -398,7 +398,7 @@ func (gp *groupParty) InviteToParty(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
// 내가 wshandler room에 입장
|
||||
gp.sendEnterRoomMessage(gid, mid)
|
||||
gp.enterRoom(gid, mid)
|
||||
|
||||
gp.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
Target: "@" + mid.Hex(),
|
||||
@ -469,7 +469,7 @@ func (gp *groupParty) AcceptPartyInvitation(w http.ResponseWriter, r *http.Reque
|
||||
Tag: []string{"MemberDocFull"},
|
||||
})
|
||||
|
||||
gp.sendEnterRoomMessage(gid, mid)
|
||||
gp.enterRoom(gid, mid)
|
||||
|
||||
// 새 멤버에 그룹 전체를 알림
|
||||
gp.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
@ -503,8 +503,13 @@ func (gp *groupParty) QueryPartyMemberState(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
state, _ := gp.rh.HGet(gp.rh.Context(), mid, "party_state").Result()
|
||||
w.Write([]byte(state))
|
||||
states, _ := gp.rh.HMGet(gp.rh.Context(), mid, "party_state", "_ts").Result()
|
||||
if states[0] != nil && len(states[0].(string)) > 0 {
|
||||
w.Write([]byte(states[0].(string)))
|
||||
} else if states[1] != nil && len(states[1].(string)) > 0 {
|
||||
w.Write([]byte("connected"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// LeaveParty : 그룹에서 나감 or 내보냄
|
||||
@ -541,7 +546,7 @@ func (gp *groupParty) LeaveParty(w http.ResponseWriter, r *http.Request) {
|
||||
Body: bson.M{"gid": gid},
|
||||
Tag: []string{"GroupDocFull", gid.Hex()},
|
||||
})
|
||||
gp.sendLeaveRoomMessage(gid, mid)
|
||||
gp.leaveRoom(gid, mid)
|
||||
}
|
||||
|
||||
func (gp *groupParty) updateMemberDocument(gid groupID, mid accountID, doc bson.M) error {
|
||||
@ -731,15 +736,12 @@ func (gp *groupParty) memberDisconnected(room string, mid primitive.ObjectID) {
|
||||
}
|
||||
}
|
||||
|
||||
func (gp *groupParty) ClientMessageReceved(sender *wshandler.Sender, mt wshandler.WebSocketMessageType, message any) {
|
||||
if mt == wshandler.Connected {
|
||||
gp.rh.HSet(gp.rh.Context(), sender.Accid.Hex(), "party_state", "connected").Result()
|
||||
} else if mt == wshandler.Disconnected {
|
||||
func (gp *groupParty) ClientMessageReceived(sender *wshandler.Sender, mt wshandler.WebSocketMessageType, message any) {
|
||||
if mt == wshandler.Disconnected {
|
||||
rooms := message.([]string)
|
||||
for _, roomname := range rooms {
|
||||
gp.memberDisconnected(roomname, sender.Accid)
|
||||
}
|
||||
gp.rh.HDel(gp.rh.Context(), sender.Accid.Hex(), "party_state").Result()
|
||||
} else if mt == wshandler.BinaryMessage {
|
||||
commandline := message.([]any)
|
||||
cmd := commandline[0].(string)
|
||||
|
||||
Reference in New Issue
Block a user