forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userargs.go
38 lines (32 loc) · 974 Bytes
/
userargs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package main
import (
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
)
func getUsersFromUserArgs(a *app.App, userArgs []string) []*model.User {
users := make([]*model.User, 0, len(userArgs))
for _, userArg := range userArgs {
user := getUserFromUserArg(a, userArg)
users = append(users, user)
}
return users
}
func getUserFromUserArg(a *app.App, userArg string) *model.User {
var user *model.User
if result := <-a.Srv.Store.User().GetByEmail(userArg); result.Err == nil {
user = result.Data.(*model.User)
}
if user == nil {
if result := <-a.Srv.Store.User().GetByUsername(userArg); result.Err == nil {
user = result.Data.(*model.User)
}
}
if user == nil {
if result := <-a.Srv.Store.User().Get(userArg); result.Err == nil {
user = result.Data.(*model.User)
}
}
return user
}