parseUserID return user id or current login user id
(ctx context.Context, query *string, currentUserID string)
| 153 | |
| 154 | // parseUserID return user id or current login user id |
| 155 | func (sp *SearchParser) parseUserID(ctx context.Context, query *string, currentUserID string) (userID string) { |
| 156 | var ( |
| 157 | exprUsername = `user:(\S+)` |
| 158 | exprMe = "user:me" |
| 159 | q = *query |
| 160 | ) |
| 161 | |
| 162 | re := regexp.MustCompile(exprUsername) |
| 163 | res := re.FindStringSubmatch(q) |
| 164 | if strings.Contains(q, exprMe) { |
| 165 | userID = currentUserID |
| 166 | q = strings.ReplaceAll(q, exprMe, "") |
| 167 | } else if len(res) > 1 { |
| 168 | name := res[1] |
| 169 | user, has, err := sp.userCommon.GetUserBasicInfoByUserName(ctx, name) |
| 170 | if err == nil && has { |
| 171 | userID = user.ID |
| 172 | q = re.ReplaceAllString(q, "") |
| 173 | } |
| 174 | } |
| 175 | *query = strings.TrimSpace(q) |
| 176 | return |
| 177 | } |
| 178 | |
| 179 | // parseVotes return the votes of search query |
| 180 | func (sp *SearchParser) parseVotes(query *string) (votes int) { |
no test coverage detected