diff --git a/shortcuts/vc/vc_meeting_events.go b/shortcuts/vc/vc_meeting_events.go index e58dc449a..888172f74 100644 --- a/shortcuts/vc/vc_meeting_events.go +++ b/shortcuts/vc/vc_meeting_events.go @@ -302,22 +302,39 @@ func meetingEventsCurrentRoster(rawRoster []interface{}, selfIdentity meetingEve func enrichMeetingEventsCurrentRoster(roster []meetingEventsIdentity, events []meetingEventsEvent) []meetingEventsIdentity { typeByID := make(map[string]string) + nameByID := make(map[string]string) for _, event := range events { for _, actor := range event.Actors { - if actor.ID == "" || !isKnownParticipantType(actor.ParticipantType) { + if actor.ID == "" { continue } - if _, exists := typeByID[actor.ID]; !exists { - typeByID[actor.ID] = actor.ParticipantType + if actor.Name != "" { + if _, exists := nameByID[actor.ID]; !exists { + nameByID[actor.ID] = actor.Name + } + } + if isKnownParticipantType(actor.ParticipantType) { + if _, exists := typeByID[actor.ID]; !exists { + typeByID[actor.ID] = actor.ParticipantType + } } } } for i := range roster { - if !isUnknownParticipantType(roster[i].ParticipantType) { - continue + changed := false + if roster[i].Name == "" { + if name := nameByID[roster[i].ID]; name != "" { + roster[i].Name = name + changed = true + } } - if participantType := typeByID[roster[i].ID]; participantType != "" { - roster[i].ParticipantType = participantType + if isUnknownParticipantType(roster[i].ParticipantType) { + if participantType := typeByID[roster[i].ID]; participantType != "" { + roster[i].ParticipantType = participantType + changed = true + } + } + if changed { roster[i].Label = identityLabel(roster[i]) } } diff --git a/shortcuts/vc/vc_meeting_events_test.go b/shortcuts/vc/vc_meeting_events_test.go index 7bffb62ad..900ff87c7 100644 --- a/shortcuts/vc/vc_meeting_events_test.go +++ b/shortcuts/vc/vc_meeting_events_test.go @@ -1330,7 +1330,7 @@ func TestBuildMeetingEventsOutput_EnrichesUnknownRosterTypeFromActors(t *testing } out := buildMeetingEventsOutput(map[string]interface{}{}, []interface{}{event}, []interface{}{ - map[string]interface{}{"id": "ou_bot", "user_name": "Meeting Bot", "user_type": 0, "role": "3"}, + map[string]interface{}{"id": "ou_bot", "user_type": 0, "role": "3"}, }, meetingEventsIdentity{}) if got := len(out.CurrentRoster); got != 1 { @@ -1339,11 +1339,38 @@ func TestBuildMeetingEventsOutput_EnrichesUnknownRosterTypeFromActors(t *testing if got := out.CurrentRoster[0].ParticipantType; got != "bot" { t.Fatalf("current_roster participant_type = %q, want bot: %#v", got, out.CurrentRoster[0]) } + if got := out.CurrentRoster[0].Name; got != "Meeting Bot" { + t.Fatalf("current_roster name = %q, want actor name", got) + } if got := out.CurrentRoster[0].Label; got != "Meeting Bot [bot,participant]" { t.Fatalf("current_roster label = %q, want enriched bot label", got) } } +func TestBuildMeetingEventsOutput_DoesNotOverwriteRosterName(t *testing.T) { + event := participantJoinedEvent() + payload := common.GetMap(event, "payload") + items := common.GetSlice(payload, "participant_joined_items") + item, _ := items[0].(map[string]interface{}) + item["participant"] = map[string]interface{}{ + "id": "ou_user", + "user_name": "Event Name", + "user_type": 1, + "user_role": 1, + } + + out := buildMeetingEventsOutput(map[string]interface{}{}, []interface{}{event}, []interface{}{ + map[string]interface{}{"id": "ou_user", "user_name": "Roster Name", "user_type": 1, "role": "3"}, + }, meetingEventsIdentity{}) + + if got := out.CurrentRoster[0].Name; got != "Roster Name" { + t.Fatalf("current_roster name = %q, want roster name", got) + } + if got := out.CurrentRoster[0].Label; got != "Roster Name [human,participant]" { + t.Fatalf("current_roster label = %q, want roster label", got) + } +} + func TestMeetingEventsIdentityFromParticipant_IgnoresGenericTypeField(t *testing.T) { got := meetingEventsIdentityFromParticipant(map[string]interface{}{ "id": "u1",