diff --git a/server/channel_state.go b/server/channel_state.go index f914a632d..18fe65a0b 100644 --- a/server/channel_state.go +++ b/server/channel_state.go @@ -23,8 +23,8 @@ type userState struct { } type callStats struct { - Participants int `json:"participants"` - ScreenDuration int64 `json:"screen_duration"` + Participants map[string]struct{} `json:"participants"` + ScreenDuration int64 `json:"screen_duration"` } type callState struct { @@ -313,7 +313,7 @@ func (p *Plugin) cleanCallState(channelID string, state *channelState) error { state.NodeID = "" if state.Call != nil { - if _, err := p.updateCallPostEnded(state.Call.PostID); err != nil { + if _, err := p.updateCallPostEnded(state.Call.PostID, mapKeys(state.Call.Stats.Participants)); err != nil { return err } state.Call = nil diff --git a/server/plugin.go b/server/plugin.go index 90b267a57..753a0e82a 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -325,7 +325,7 @@ func (p *Plugin) createCallStartedPost(state *channelState, userID, channelID, t return createdPost.Id, threadID, nil } -func (p *Plugin) updateCallPostEnded(postID string) (float64, error) { +func (p *Plugin) updateCallPostEnded(postID string, participants []string) (float64, error) { post, appErr := p.API.GetPost(postID) if appErr != nil { return 0, appErr @@ -342,6 +342,7 @@ func (p *Plugin) updateCallPostEnded(postID string) (float64, error) { post.DelProp("attachments") post.AddProp("attachments", []*model.SlackAttachment{&slackAttachment}) post.AddProp("end_at", time.Now().UnixMilli()) + post.AddProp("participants", participants) _, appErr = p.API.UpdatePost(post) if appErr != nil { diff --git a/server/session.go b/server/session.go index fee5376d4..f5175fffe 100644 --- a/server/session.go +++ b/server/session.go @@ -137,8 +137,13 @@ func (p *Plugin) addUserSession(state *channelState, userID, connID, channelID s JoinAt: time.Now().UnixMilli(), } state.Call.Sessions[connID] = struct{}{} - if len(state.Call.Users) > state.Call.Stats.Participants { - state.Call.Stats.Participants = len(state.Call.Users) + + if state.Call.Stats.Participants == nil { + state.Call.Stats.Participants = map[string]struct{}{} + } + + if userID != p.getBotID() { + state.Call.Stats.Participants[userID] = struct{}{} } if err := p.kvSetChannelState(channelID, state); err != nil { @@ -322,7 +327,7 @@ func (p *Plugin) removeSession(us *session) error { // Check if call has ended. if prevState.Call != nil && currState.Call == nil { - dur, err := p.updateCallPostEnded(prevState.Call.PostID) + dur, err := p.updateCallPostEnded(prevState.Call.PostID, mapKeys(prevState.Call.Stats.Participants)) if err != nil { return err } @@ -330,7 +335,7 @@ func (p *Plugin) removeSession(us *session) error { "ChannelID": us.channelID, "CallID": prevState.Call.ID, "Duration": dur, - "Participants": prevState.Call.Stats.Participants, + "Participants": len(prevState.Call.Stats.Participants), "ScreenDuration": prevState.Call.Stats.ScreenDuration, }) } diff --git a/server/utils.go b/server/utils.go index 88ae3c231..a70d93d26 100644 --- a/server/utils.go +++ b/server/utils.go @@ -120,3 +120,11 @@ func checkMinVersion(minVersion, currVersion string) error { return nil } + +func mapKeys[K comparable, V any](m map[K]V) []K { + keys := make([]K, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + return keys +}