Skip to content

Commit 6e31e18

Browse files
authored
Merge pull request #2626 from traPtitech/fix/qall-roomstate-ws-event
fix: QallRoomStateChangedEvent
2 parents 05ff228 + 4dd3dc9 commit 6e31e18

5 files changed

Lines changed: 139 additions & 144 deletions

File tree

docs/v3-api.yaml

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6986,50 +6986,55 @@ components:
69866986
type: object
69876987
description: Qallのルーム状態が変更された
69886988
properties:
6989-
room_id:
6990-
type: string
6991-
format: uuid
6992-
description: 変更されたルームのId
6993-
state:
6994-
type: object
6995-
description: 変更後のルーム状態
6996-
properties:
6997-
roomId:
6998-
type: string
6999-
format: uuid
7000-
description: ルームのID
7001-
participants:
7002-
type: array
7003-
items:
7004-
type: object
7005-
properties:
7006-
identity:
7007-
type: string
7008-
description: ユーザーID_RandomUUID
7009-
name:
7010-
type: string
7011-
description: 表示名
7012-
joinedAt:
7013-
type: string
7014-
format: date-time
7015-
description: 参加した時刻
7016-
attributes:
7017-
type: object
7018-
additionalProperties:
6989+
roomStates:
6990+
type: array
6991+
items:
6992+
type: object
6993+
properties:
6994+
roomId:
6995+
type: string
6996+
format: uuid
6997+
description: ルームのID
6998+
participants:
6999+
type: array
7000+
items:
7001+
type: object
7002+
properties:
7003+
identity:
70197004
type: string
7020-
description: ユーザーに関連付けられたカスタム属性
7021-
canPublish:
7022-
type: boolean
7023-
description: 発言権限
7024-
isWebinar:
7025-
type: boolean
7026-
description: ウェビナールームかどうか
7027-
metadata:
7028-
type: string
7029-
description: ルームに関連付けられたカスタム属性
7005+
description: ユーザーID_RandomUUID
7006+
name:
7007+
type: string
7008+
description: 表示名
7009+
joinedAt:
7010+
type: string
7011+
format: date-time
7012+
description: 参加した時刻
7013+
attributes:
7014+
type: object
7015+
additionalProperties:
7016+
type: string
7017+
description: ユーザーに関連付けられたカスタム属性
7018+
canPublish:
7019+
type: boolean
7020+
description: 発言権限
7021+
required:
7022+
- identity
7023+
- name
7024+
- joinedAt
7025+
- canPublish
7026+
isWebinar:
7027+
type: boolean
7028+
description: ウェビナールームかどうか
7029+
metadata:
7030+
type: string
7031+
description: ルームに関連付けられたカスタム属性
7032+
required:
7033+
- roomId
7034+
- participants
7035+
- isWebinar
70307036
required:
7031-
- room_id
7032-
- state
7037+
- roomStates
70337038
QallSoundboardItemCreatedEvent:
70347039
title: QallSoundboardItemCreatedEvent
70357040
type: object

router/v3/qall.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Handlers) PlaySoundboardItem(c echo.Context) error {
9393
// 2-2) ルームに参加しているか確認
9494
isParticipant := false
9595
for _, participant := range roomState.Participants {
96-
if *participant.Name == userID.String() {
96+
if participant.Name == userID.String() {
9797
isParticipant = true
9898
break
9999
}
@@ -189,7 +189,7 @@ func (h *Handlers) PatchRoomMetadata(c echo.Context) error {
189189
// Verify user is a participant
190190
isParticipant := false
191191
for _, participant := range targetRoom.Participants {
192-
if *participant.Name == userID.String() {
192+
if participant.Name == userID.String() {
193193
isParticipant = true
194194
break
195195
}
@@ -202,7 +202,7 @@ func (h *Handlers) PatchRoomMetadata(c echo.Context) error {
202202
// Update metadata
203203
metadata := qall.Metadata{
204204
Status: req.Metadata,
205-
IsWebinar: *targetRoom.IsWebinar,
205+
IsWebinar: targetRoom.IsWebinar,
206206
}
207207

208208
_, err = livekitClient.UpdateRoomMetadata(c.Request().Context(), &livekit.UpdateRoomMetadataRequest{
@@ -250,8 +250,8 @@ func (h *Handlers) PatchRoomParticipants(c echo.Context) error {
250250
// userがcanPublishかどうかを確認
251251
canPublish := false
252252
for _, participant := range roomState.Participants {
253-
if *participant.Name == userID.String() {
254-
canPublish = *participant.CanPublish
253+
if participant.Name == userID.String() {
254+
canPublish = participant.CanPublish
255255
break
256256
}
257257
}
@@ -263,10 +263,10 @@ func (h *Handlers) PatchRoomParticipants(c echo.Context) error {
263263
livekitClient := lksdk.NewRoomServiceClient(h.Config.LiveKitHost, h.Config.LiveKitAPIKey, h.Config.LiveKitAPISecret)
264264
for _, participant := range req.Users {
265265
for _, roomParticipant := range roomState.Participants {
266-
if *roomParticipant.Name == participant.UserID {
266+
if roomParticipant.Name == participant.UserID {
267267
_, err := livekitClient.UpdateParticipant(c.Request().Context(), &livekit.UpdateParticipantRequest{
268268
Room: roomID.String(),
269-
Identity: *roomParticipant.Identity,
269+
Identity: roomParticipant.Identity,
270270
Permission: &livekit.ParticipantPermission{
271271
CanPublish: participant.CanPublish,
272272
},
@@ -275,7 +275,7 @@ func (h *Handlers) PatchRoomParticipants(c echo.Context) error {
275275
failedUsers[participant.UserID] = err.Error()
276276
} else {
277277
succeedUsers = append(succeedUsers, participant.UserID)
278-
h.QallRepo.UpdateParticipantCanPublish(roomID.String(), *roomParticipant.Identity, participant.CanPublish)
278+
h.QallRepo.UpdateParticipantCanPublish(roomID.String(), roomParticipant.Identity, participant.CanPublish)
279279
}
280280
}
281281
}
@@ -330,7 +330,7 @@ func (h *Handlers) GetLiveKitToken(c echo.Context) error {
330330

331331
// ルームが存在して、webinar=true の場合はCanPublish=false
332332
isExistingRoom := roomState != nil
333-
if isExistingRoom && *roomState.IsWebinar {
333+
if isExistingRoom && roomState.IsWebinar {
334334
isWebinar = true
335335
}
336336

@@ -341,8 +341,8 @@ func (h *Handlers) GetLiveKitToken(c echo.Context) error {
341341
isAlreadyCanPublish := false
342342
if roomState != nil {
343343
for _, participant := range roomState.Participants {
344-
if *participant.Name == userID.String() {
345-
isAlreadyCanPublish = *participant.CanPublish
344+
if participant.Name == userID.String() {
345+
isAlreadyCanPublish = participant.CanPublish
346346
break
347347
}
348348
}
@@ -391,7 +391,7 @@ func (h *Handlers) GetLiveKitToken(c echo.Context) error {
391391
// ルームが存在しない場合は新規作成
392392
emptyMetadata := ""
393393
roomWithParticipants := qall.RoomWithParticipants{
394-
IsWebinar: &isWebinar,
394+
IsWebinar: isWebinar,
395395
Metadata: &emptyMetadata,
396396
RoomID: roomID,
397397
Participants: []qall.Participant{},

service/qall/roomstate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ type Participant struct {
2323
Attributes *map[string]string `json:"attributes,omitempty"`
2424

2525
// CanPublish 発言権限
26-
CanPublish *bool `json:"canPublish,omitempty"`
26+
CanPublish bool `json:"canPublish"`
2727

2828
// Identity ユーザーID_RandomUUID
29-
Identity *string `json:"identity,omitempty"`
29+
Identity string `json:"identity"`
3030

3131
// JoinedAt 参加した時刻
32-
JoinedAt *time.Time `json:"joinedAt,omitempty"`
32+
JoinedAt time.Time `json:"joinedAt"`
3333

3434
// Name 表示名
35-
Name *string `json:"name,omitempty"`
35+
Name string `json:"name"`
3636
}
3737

3838
// RoomWithParticipants defines model for RoomWithParticipants.
3939
type RoomWithParticipants struct {
4040
// IsWebinar ウェビナールームかどうか
41-
IsWebinar *bool `json:"isWebinar,omitempty"`
41+
IsWebinar bool `json:"isWebinar"`
4242

4343
// Metadata ルームに関連付けられたカスタム属性
4444
Metadata *string `json:"metadata,omitempty"`

service/qall/roomstate_impl.go

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ func (r *Repository) AddParticipantToRoomState(room *livekit.Room, participant *
4040
if roomState.RoomID.String() == room.Name {
4141
t := time.Unix(participant.JoinedAt, 0).In(time.FixedZone("Asia/Tokyo", 9*60*60))
4242
r.RoomState[i].Participants = append(r.RoomState[i].Participants, Participant{
43-
Identity: &participant.Identity,
44-
JoinedAt: &t,
45-
Name: &participant.Name,
43+
Identity: participant.Identity,
44+
JoinedAt: t,
45+
Name: participant.Name,
4646
Attributes: &participant.Attributes,
47-
CanPublish: &participant.Permission.CanPublish,
47+
CanPublish: participant.Permission.CanPublish,
4848
})
4949

5050
if r.Hub != nil {
5151
r.Hub.Publish(hub.Message{
5252
Name: event.QallRoomStateChanged,
5353
Fields: hub.Fields{
54-
"room_id": roomState.RoomID,
55-
"state": &r.RoomState[i],
54+
"roomState": r.RoomState,
5655
},
5756
})
5857
}
@@ -67,15 +66,14 @@ func (r *Repository) UpdateParticipantCanPublish(roomID string, participantID st
6766
for i, roomState := range r.RoomState {
6867
if roomState.RoomID.String() == roomID {
6968
for j, participant := range roomState.Participants {
70-
if *participant.Identity == participantID {
71-
r.RoomState[i].Participants[j].CanPublish = &canPublish
69+
if participant.Identity == participantID {
70+
r.RoomState[i].Participants[j].CanPublish = canPublish
7271

7372
if r.Hub != nil {
7473
r.Hub.Publish(hub.Message{
7574
Name: event.QallRoomStateChanged,
7675
Fields: hub.Fields{
77-
"room_id": roomState.RoomID,
78-
"state": &r.RoomState[i],
76+
"roomState": r.RoomState,
7977
},
8078
})
8179
}
@@ -93,22 +91,21 @@ func (r *Repository) UpdateParticipant(roomID string, participant *livekit.Parti
9391
for i, roomState := range r.RoomState {
9492
if roomState.RoomID.String() == roomID {
9593
for j, p := range roomState.Participants {
96-
if *p.Identity == participant.Identity {
94+
if p.Identity == participant.Identity {
9795
t := time.Unix(participant.JoinedAt, 0).In(time.FixedZone("Asia/Tokyo", 9*60*60))
9896
r.RoomState[i].Participants[j] = Participant{
99-
Identity: &participant.Identity,
100-
JoinedAt: &t,
101-
Name: &participant.Name,
97+
Identity: participant.Identity,
98+
JoinedAt: t,
99+
Name: participant.Name,
102100
Attributes: &participant.Attributes,
103-
CanPublish: &participant.Permission.CanPublish,
101+
CanPublish: participant.Permission.CanPublish,
104102
}
105103

106104
if r.Hub != nil {
107105
r.Hub.Publish(hub.Message{
108106
Name: event.QallRoomStateChanged,
109107
Fields: hub.Fields{
110-
"room_id": roomState.RoomID,
111-
"state": &r.RoomState[i],
108+
"roomState": r.RoomState,
112109
},
113110
})
114111
}
@@ -126,15 +123,14 @@ func (r *Repository) RemoveParticipant(roomID string, participantID string) {
126123
for i, roomState := range r.RoomState {
127124
if roomState.RoomID.String() == roomID {
128125
for j, participant := range roomState.Participants {
129-
if *participant.Identity == participantID {
126+
if participant.Identity == participantID {
130127
r.RoomState[i].Participants = slices.Delete(r.RoomState[i].Participants, j, j+1)
131128

132129
if r.Hub != nil {
133130
r.Hub.Publish(hub.Message{
134131
Name: event.QallRoomStateChanged,
135132
Fields: hub.Fields{
136-
"room_id": roomState.RoomID,
137-
"state": &r.RoomState[i],
133+
"roomState": r.RoomState,
138134
},
139135
})
140136
}
@@ -165,8 +161,7 @@ func (r *Repository) AddRoomState(room RoomWithParticipants) {
165161
r.Hub.Publish(hub.Message{
166162
Name: event.QallRoomStateChanged,
167163
Fields: hub.Fields{
168-
"room_id": room.RoomID,
169-
"state": &room,
164+
"roomState": r.RoomState,
170165
},
171166
})
172167
}
@@ -182,8 +177,7 @@ func (r *Repository) UpdateRoomMetadata(roomID string, metadata Metadata) {
182177
r.Hub.Publish(hub.Message{
183178
Name: event.QallRoomStateChanged,
184179
Fields: hub.Fields{
185-
"room_id": roomState.RoomID,
186-
"state": &r.RoomState[i],
180+
"roomState": r.RoomState,
187181
},
188182
})
189183
}
@@ -200,16 +194,12 @@ func (r *Repository) RemoveRoomState(roomID string) {
200194
r.RoomState = append(r.RoomState[:i], r.RoomState[i+1:]...)
201195

202196
if r.Hub != nil {
203-
roomUUID, err := uuid.FromString(roomID)
204-
if err == nil {
205-
r.Hub.Publish(hub.Message{
206-
Name: event.QallRoomStateChanged,
207-
Fields: hub.Fields{
208-
"room_id": roomUUID,
209-
"state": nil,
210-
},
211-
})
212-
}
197+
r.Hub.Publish(hub.Message{
198+
Name: event.QallRoomStateChanged,
199+
Fields: hub.Fields{
200+
"roomState": r.RoomState,
201+
},
202+
})
213203
}
214204

215205
break
@@ -254,9 +244,9 @@ func (r *Repository) GetRoomsWithParticipantsByLiveKitServer(ctx context.Context
254244
for _, p := range partResp.Participants {
255245
t := time.Unix(p.JoinedAt, 0).In(time.FixedZone("Asia/Tokyo", 9*60*60))
256246
Participants = append(Participants, Participant{
257-
Identity: &p.Identity,
258-
JoinedAt: &t,
259-
Name: &p.Name,
247+
Identity: p.Identity,
248+
JoinedAt: t,
249+
Name: p.Name,
260250
Attributes: &p.Attributes,
261251
})
262252
}
@@ -275,7 +265,7 @@ func (r *Repository) GetRoomsWithParticipantsByLiveKitServer(ctx context.Context
275265

276266
roomWithParticipants = append(roomWithParticipants, RoomWithParticipants{
277267
Metadata: &metadata.Status,
278-
IsWebinar: &metadata.IsWebinar,
268+
IsWebinar: metadata.IsWebinar,
279269
RoomID: roomID,
280270
Participants: Participants,
281271
})

0 commit comments

Comments
 (0)