|
|
@ -528,6 +528,7 @@ type globalVarsStruct struct { |
|
|
|
replaceCharsHyphenRE *regexp.Regexp |
|
|
|
replaceCharsHyphenRE *regexp.Regexp |
|
|
|
emailToReplacer *strings.Replacer |
|
|
|
emailToReplacer *strings.Replacer |
|
|
|
emailRegexp *regexp.Regexp |
|
|
|
emailRegexp *regexp.Regexp |
|
|
|
|
|
|
|
systemUserNewFuncs map[int64]func() *User |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var globalVars = sync.OnceValue(func() *globalVarsStruct { |
|
|
|
var globalVars = sync.OnceValue(func() *globalVarsStruct { |
|
|
@ -550,6 +551,11 @@ var globalVars = sync.OnceValue(func() *globalVarsStruct { |
|
|
|
";", "", |
|
|
|
";", "", |
|
|
|
), |
|
|
|
), |
|
|
|
emailRegexp: regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"), |
|
|
|
emailRegexp: regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
systemUserNewFuncs: map[int64]func() *User{ |
|
|
|
|
|
|
|
GhostUserID: NewGhostUser, |
|
|
|
|
|
|
|
ActionsUserID: NewActionsUser, |
|
|
|
|
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -978,30 +984,28 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) { |
|
|
|
return users, err |
|
|
|
return users, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
|
|
|
|
// GetPossibleUserByID returns the user if id > 0 or returns system user if id < 0
|
|
|
|
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) { |
|
|
|
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) { |
|
|
|
switch id { |
|
|
|
if id < 0 { |
|
|
|
case GhostUserID: |
|
|
|
if newFunc, ok := globalVars().systemUserNewFuncs[id]; ok { |
|
|
|
return NewGhostUser(), nil |
|
|
|
return newFunc(), nil |
|
|
|
case ActionsUserID: |
|
|
|
} |
|
|
|
return NewActionsUser(), nil |
|
|
|
return nil, ErrUserNotExist{UID: id} |
|
|
|
case 0: |
|
|
|
} else if id == 0 { |
|
|
|
return nil, ErrUserNotExist{} |
|
|
|
return nil, ErrUserNotExist{} |
|
|
|
default: |
|
|
|
|
|
|
|
return GetUserByID(ctx, id) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return GetUserByID(ctx, id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetPossibleUserByIDs returns the users if id > 0 or return system users if id < 0
|
|
|
|
// GetPossibleUserByIDs returns the users if id > 0 or returns system users if id < 0
|
|
|
|
func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) { |
|
|
|
func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) { |
|
|
|
uniqueIDs := container.SetOf(ids...) |
|
|
|
uniqueIDs := container.SetOf(ids...) |
|
|
|
users := make([]*User, 0, len(ids)) |
|
|
|
users := make([]*User, 0, len(ids)) |
|
|
|
_ = uniqueIDs.Remove(0) |
|
|
|
_ = uniqueIDs.Remove(0) |
|
|
|
if uniqueIDs.Remove(GhostUserID) { |
|
|
|
for systemUID, newFunc := range globalVars().systemUserNewFuncs { |
|
|
|
users = append(users, NewGhostUser()) |
|
|
|
if uniqueIDs.Remove(systemUID) { |
|
|
|
} |
|
|
|
users = append(users, newFunc()) |
|
|
|
if uniqueIDs.Remove(ActionsUserID) { |
|
|
|
} |
|
|
|
users = append(users, NewActionsUser()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
res, err := GetUserByIDs(ctx, uniqueIDs.Values()) |
|
|
|
res, err := GetUserByIDs(ctx, uniqueIDs.Values()) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -1011,7 +1015,7 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) { |
|
|
|
return users, nil |
|
|
|
return users, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetUserByNameCtx returns user by given name.
|
|
|
|
// GetUserByName returns user by given name.
|
|
|
|
func GetUserByName(ctx context.Context, name string) (*User, error) { |
|
|
|
func GetUserByName(ctx context.Context, name string) (*User, error) { |
|
|
|
if len(name) == 0 { |
|
|
|
if len(name) == 0 { |
|
|
|
return nil, ErrUserNotExist{Name: name} |
|
|
|
return nil, ErrUserNotExist{Name: name} |
|
|
@ -1042,8 +1046,8 @@ func GetUserEmailsByNames(ctx context.Context, names []string) []string { |
|
|
|
return mails |
|
|
|
return mails |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetMaileableUsersByIDs gets users from ids, but only if they can receive mails
|
|
|
|
// GetMailableUsersByIDs gets users from ids, but only if they can receive mails
|
|
|
|
func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([]*User, error) { |
|
|
|
func GetMailableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([]*User, error) { |
|
|
|
if len(ids) == 0 { |
|
|
|
if len(ids) == 0 { |
|
|
|
return nil, nil |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
} |
|
|
@ -1068,17 +1072,6 @@ func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([ |
|
|
|
Find(&ous) |
|
|
|
Find(&ous) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetUserNamesByIDs returns usernames for all resolved users from a list of Ids.
|
|
|
|
|
|
|
|
func GetUserNamesByIDs(ctx context.Context, ids []int64) ([]string, error) { |
|
|
|
|
|
|
|
unames := make([]string, 0, len(ids)) |
|
|
|
|
|
|
|
err := db.GetEngine(ctx).In("id", ids). |
|
|
|
|
|
|
|
Table("user"). |
|
|
|
|
|
|
|
Asc("name"). |
|
|
|
|
|
|
|
Cols("name"). |
|
|
|
|
|
|
|
Find(&unames) |
|
|
|
|
|
|
|
return unames, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetUserNameByID returns username for the id
|
|
|
|
// GetUserNameByID returns username for the id
|
|
|
|
func GetUserNameByID(ctx context.Context, id int64) (string, error) { |
|
|
|
func GetUserNameByID(ctx context.Context, id int64) (string, error) { |
|
|
|
var name string |
|
|
|
var name string |
|
|
|