Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-53167] Persist participants list #486

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/channel_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -322,15 +327,15 @@ 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
}
p.track(evCallEnded, map[string]interface{}{
"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,
})
}
Expand Down
8 changes: 8 additions & 0 deletions server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}