Skip to content

Commit

Permalink
feat: add meeting urls
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Jun 22, 2021
1 parent 6bb9f40 commit f23f8ea
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Go to **System Console > Plugins > Management** upload and enable the plugin.
- **Recurrence** - daily, weekly or monthly meetings.
- **Initial text** - The text that will be send to the users when is time to chat.
- **Number of users per meeting** - Minimum users per meeting.
- **MeetingRooms** - urls separated by commas added to every meeting start message.

## Usage

Expand Down
6 changes: 6 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"display_name": "Number of users per meeting",
"type": "number",
"default": 3
},
{
"key": "MeetingRooms",
"display_name": "Meeting rooms",
"type": "text",
"default": ""
}
]
}
Expand Down
1 change: 1 addition & 0 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type configuration struct {
CustomCron string
InitText string
NumUsersPerMeeting int
MeetingRooms string
}

// Clone shallow copies the configuration. Your implementation may require a deep copy if
Expand Down
7 changes: 4 additions & 3 deletions server/meetings.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func getMeetingCandidates(userInMeeting []string, users []string, previousMeetin
for index, userId := range usersList {
maxCount := len(previousMeetings)
lenUsers := len(users)
defaultMaxCount := lenUsers * lenUsers

if maxCount > 40 {
maxCount = lenUsers * lenUsers
if maxCount > defaultMaxCount {
maxCount = defaultMaxCount - 1
}

count := getCountUserMeet(userMeeting, userId, previousMeetings[:maxCount])
Expand Down Expand Up @@ -157,7 +158,7 @@ func getMeetings(users []string, usersPerMeeting int, previousMeetings [][]strin
}
}

if len(meeting) < usersPerMeeting {
if len(meeting) < usersPerMeeting-1 {
for _, userIdFromIncrompleMeeting := range meeting {
meetings = sortMeetingBySize(meetings)
meetings[0] = append(meetings[0], userIdFromIncrompleMeeting)
Expand Down
13 changes: 8 additions & 5 deletions server/meetings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGetUserListByDate(t *testing.T) {
func TestOddGetMeetings(t *testing.T) {
assert := assert.New(t)

users := []string{"user1", "user2", "user3", "user4", "user5", "user6", "user7"}
users := []string{"user1", "user2", "user3", "user4", "user5", "user6", "user7", "user8", "user9", "user10", "user11"}

previousMeetings := [][]string{
{"user1", "user2", "user3"},
Expand All @@ -127,12 +127,15 @@ func TestOddGetMeetings(t *testing.T) {
{"user2", "user4", "user7"},
}

result := getMeetings(users, 3, previousMeetings)
result := getMeetings(users, 4, previousMeetings)

assert.Equal(3, len(result))

users = Remove(users, "user1")

result = getMeetings(users, 4, previousMeetings)

assert.Equal(2, len(result))
// todo: random fail
assert.True(meetingExist([]string{"user1", "user3", "user4", "user7"}, result))
assert.True(meetingExist([]string{"user2", "user5", "user6"}, result))
}

// need work
Expand Down
25 changes: 22 additions & 3 deletions server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"strings"
"sync"

"github.com/mattermost/mattermost-server/v5/model"
Expand Down Expand Up @@ -54,15 +55,23 @@ func (p *Plugin) addCronFunc() {

func (p *Plugin) runMeetings() {
users := p.getAvailableUsers()
config := p.getConfiguration()

meetings := getMeetingsShuffleUsers(users, p.configuration.NumUsersPerMeeting, p.usersMeetings)
rooms := strings.Split(config.MeetingRooms, ",")

for index, meeting := range meetings {
meetingUrl := ""

if len(rooms) > index {
meetingUrl = rooms[index]
}

for _, meeting := range meetings {
p.startMeeting(meeting)
p.startMeeting(meeting, meetingUrl)
}
}

func (p *Plugin) startMeeting(meeting []string) {
func (p *Plugin) startMeeting(meeting []string, meetingUrl string) {
maxMeetings := 100

p.usersMeetings = PrependSlice(p.usersMeetings, meeting)
Expand All @@ -85,6 +94,16 @@ func (p *Plugin) startMeeting(meeting []string) {

p.persistMeetings()
p.API.CreatePost(post)

if len(meetingUrl) > 0 {
post := &model.Post{
UserId: p.botUserID,
ChannelId: channel.Id,
Message: meetingUrl,
}

p.API.CreatePost(post)
}
}

func (p *Plugin) UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember) {
Expand Down

0 comments on commit f23f8ea

Please sign in to comment.