client: save channel usernames in database

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans
2024-09-26 14:01:09 -06:00
parent 332bbb8de1
commit 31397681f5
4 changed files with 16 additions and 7 deletions
+5 -5
View File
@@ -192,17 +192,17 @@ func (s *ScopedStore) GetUsername(ctx context.Context, entityType ids.PeerType,
return
}
func (s *ScopedStore) SetUsername(ctx context.Context, entityType ids.PeerType, userID int64, username string) (err error) {
func (s *ScopedStore) SetUsername(ctx context.Context, entityType ids.PeerType, entityID int64, username string) (err error) {
if username == "" {
_, err = s.db.Exec(ctx, clearUsernameQuery, entityType, userID)
_, err = s.db.Exec(ctx, clearUsernameQuery, entityType, entityID)
} else {
_, err = s.db.Exec(ctx, setUsernameQuery, username, entityType, userID)
_, err = s.db.Exec(ctx, setUsernameQuery, username, entityType, entityID)
}
return
}
func (s *ScopedStore) GetUserIDByUsername(ctx context.Context, username string) (entityType ids.PeerType, userID int64, err error) {
err = s.db.QueryRow(ctx, getByUsernameQuery, username).Scan(&entityType, &userID)
func (s *ScopedStore) GetEntityIDByUsername(ctx context.Context, username string) (entityType ids.PeerType, entityID int64, err error) {
err = s.db.QueryRow(ctx, getByUsernameQuery, username).Scan(&entityType, &entityID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}