diff --git a/pkg/connector/client.go b/pkg/connector/client.go index 930fe58f..db461a18 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -234,7 +234,7 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge return userInfo, nil }, GetUserInfoByUsername: func(ctx context.Context, username string) (telegramfmt.UserInfo, error) { - if peerType, userID, err := client.ScopedStore.GetUserIDByUsername(ctx, username); err != nil { + if peerType, userID, err := client.ScopedStore.GetEntityIDByUsername(ctx, username); err != nil { return telegramfmt.UserInfo{}, err } else if peerType != ids.PeerTypeUser { return telegramfmt.UserInfo{}, fmt.Errorf("unexpected peer type: %s", peerType) diff --git a/pkg/connector/startnewchat.go b/pkg/connector/startnewchat.go index 4fca05eb..eb00bdd8 100644 --- a/pkg/connector/startnewchat.go +++ b/pkg/connector/startnewchat.go @@ -81,7 +81,7 @@ func (t *TelegramClient) ResolveIdentifier(ctx context.Context, identifier strin return t.getResolveIdentifierResponseForUserID(ctx, userID) } else if match := usernameRe.FindStringSubmatch(identifier); match != nil && !strings.Contains(identifier, "__") { // This is a username - entityType, userID, err := t.ScopedStore.GetUserIDByUsername(ctx, match[1]) + entityType, userID, err := t.ScopedStore.GetEntityIDByUsername(ctx, match[1]) if entityType == ids.PeerTypeUser && (err == nil || userID != 0) { // We know this username. return t.getResolveIdentifierResponseForUserID(ctx, userID) diff --git a/pkg/connector/store/scoped_store.go b/pkg/connector/store/scoped_store.go index 64c938e6..ea8280f0 100644 --- a/pkg/connector/store/scoped_store.go +++ b/pkg/connector/store/scoped_store.go @@ -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 } diff --git a/pkg/connector/telegram.go b/pkg/connector/telegram.go index bd08b62c..78651ae8 100644 --- a/pkg/connector/telegram.go +++ b/pkg/connector/telegram.go @@ -77,6 +77,8 @@ func (t *TelegramClient) onUpdateChannel(ctx context.Context, update *tg.UpdateC } else if channel.Left { log.Error().Msg("Update was for a left channel. Leaving the channel.") leave() + } else { + // TODO update the channel info } return nil } @@ -408,6 +410,13 @@ func (t *TelegramClient) updateChannel(ctx context.Context, channel *tg.Channel) } } + if username, set := channel.GetUsername(); set { + err := t.ScopedStore.SetUsername(ctx, ids.PeerTypeChannel, channel.ID, username) + if err != nil { + return err + } + } + ghost.UpdateInfo(ctx, &bridgev2.UserInfo{ Name: &channel.Title, Avatar: avatar,