// GetUserMentions 获取 @ 的 suggest 列表 func (UserLogic) GetUserMentions(term string, limit int) []map[string]string { userActives := make([]*model.UserActive, 0) err := MasterDB.Where("username like ?", "%"+term+"%").Desc("mtime").Limit(limit).Find(&userActives) if err != nil { logger.Errorln("UserLogic GetUserMentions Error:", err) return nil } users := make([]map[string]string, len(userActives)) for i, userActive := range userActives { user := make(map[string]string, 2) user["username"] = userActive.Username user["avatar"] = util.Gravatar(userActive.Avatar, userActive.Email, 20) users[i] = user } return users }
// 获取 @ 的 suggest 列表 func GetUserMentions(term string, limit int) []map[string]string { term = "%" + term + "%" userActives, err := model.NewUserActive().Where("username like ?", term).Limit(strconv.Itoa(limit)).Order("mtime DESC").FindAll("email", "username", "avatar") if err != nil { logger.Errorln("user service GetUserMentions Error:", err) return nil } users := make([]map[string]string, len(userActives)) for i, userActive := range userActives { user := make(map[string]string, 2) user["username"] = userActive.Username user["avatar"] = util.Gravatar(userActive.Avatar, userActive.Email, 20) users[i] = user } return users }