fix парсер
This commit is contained in:
@@ -18,9 +18,11 @@ func (d *Database) GetChannels(ctx context.Context) []domain.Channel {
|
||||
title,
|
||||
access_hash,
|
||||
pts,
|
||||
invite_link
|
||||
invite_link,
|
||||
is_accessible
|
||||
FROM channel
|
||||
WHERE deleted_at IS NULL;`
|
||||
WHERE deleted_at IS NULL
|
||||
AND is_accessible = true;`
|
||||
|
||||
txOrPool := transaction.TryExtractTX(ctx)
|
||||
|
||||
@@ -56,6 +58,7 @@ type getChannelsDTO struct {
|
||||
AccessHash pgtype.Int8
|
||||
Pts pgtype.Int4
|
||||
InviteLink pgtype.Text
|
||||
IsAccessible pgtype.Bool
|
||||
}
|
||||
|
||||
func (dto *getChannelsDTO) destination() []any {
|
||||
@@ -67,6 +70,7 @@ func (dto *getChannelsDTO) destination() []any {
|
||||
&dto.AccessHash,
|
||||
&dto.Pts,
|
||||
&dto.InviteLink,
|
||||
&dto.IsAccessible,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +83,6 @@ func (dto *getChannelsDTO) toDomain() domain.Channel {
|
||||
AccessHash: dto.AccessHash.Int64,
|
||||
Pts: int(dto.Pts.Int32),
|
||||
InviteLink: dto.InviteLink.String,
|
||||
IsAccessible: dto.IsAccessible.Bool,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,24 +18,31 @@ SET telegram_id = $2,
|
||||
title = $4,
|
||||
access_hash = $5,
|
||||
pts = $6,
|
||||
is_accessible = $7,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1;`
|
||||
|
||||
txOrPool := transaction.TryExtractTX(ctx)
|
||||
|
||||
username := strings.TrimSpace(channel.Username)
|
||||
usernameValid := username != ""
|
||||
var usernameDTO pgtype.Text
|
||||
if username != "" {
|
||||
usernameDTO = pgtype.Text{String: username, Valid: true}
|
||||
} else {
|
||||
usernameDTO = pgtype.Text{Valid: false}
|
||||
}
|
||||
|
||||
dto := updateChannelDTO{
|
||||
ID: pgtype.UUID{Bytes: channel.ID, Valid: true},
|
||||
TelegramID: pgtype.Int8{Int64: channel.TelegramID, Valid: true},
|
||||
Username: pgtype.Text{String: username, Valid: usernameValid},
|
||||
Username: usernameDTO,
|
||||
Title: pgtype.Text{String: channel.Title, Valid: true},
|
||||
AccessHash: pgtype.Int8{Int64: channel.AccessHash, Valid: true},
|
||||
Pts: pgtype.Int4{Int32: int32(channel.Pts), Valid: true},
|
||||
IsAccessible: pgtype.Bool{Bool: channel.IsAccessible, Valid: true},
|
||||
}
|
||||
|
||||
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.TelegramID, dto.Username, dto.Title, dto.AccessHash, dto.Pts)
|
||||
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.TelegramID, dto.Username, dto.Title, dto.AccessHash, dto.Pts, dto.IsAccessible)
|
||||
if err != nil {
|
||||
return fmt.Errorf("txOrPool.Exec: %w", err)
|
||||
}
|
||||
@@ -50,4 +57,5 @@ type updateChannelDTO struct {
|
||||
Title pgtype.Text
|
||||
AccessHash pgtype.Int8
|
||||
Pts pgtype.Int4
|
||||
IsAccessible pgtype.Bool
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func extractChannelMeta(currentChannel domain.Channel, chats []tg.ChatClass) *do
|
||||
}
|
||||
|
||||
username := ""
|
||||
if usernameVal, ok := ch.GetUsername(); ok {
|
||||
if usernameVal, ok := ch.GetUsername(); ok && usernameVal != "" {
|
||||
username = usernameVal
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ func extractChannelMeta(currentChannel domain.Channel, chats []tg.ChatClass) *do
|
||||
Title: ch.Title,
|
||||
AccessHash: accessHash,
|
||||
Pts: currentChannel.Pts,
|
||||
IsAccessible: currentChannel.IsAccessible,
|
||||
}
|
||||
|
||||
return &updated
|
||||
|
||||
@@ -55,5 +55,6 @@ func (t *Telegram) ParseChannelMeta(ctx context.Context, username string) (domai
|
||||
Title: ch.Title,
|
||||
AccessHash: ch.AccessHash,
|
||||
Pts: pts,
|
||||
IsAccessible: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (t *Telegram) ParseChannelMetaByInvite(ctx context.Context, inviteLink stri
|
||||
}
|
||||
|
||||
username := ""
|
||||
if usernameVal, ok := channel.GetUsername(); ok {
|
||||
if usernameVal, ok := channel.GetUsername(); ok && usernameVal != "" {
|
||||
username = usernameVal
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ func (t *Telegram) ParseChannelMetaByInvite(ctx context.Context, inviteLink stri
|
||||
Title: channel.Title,
|
||||
AccessHash: channel.AccessHash,
|
||||
Pts: pts,
|
||||
IsAccessible: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ type Channel struct {
|
||||
AccessHash int64
|
||||
Pts int
|
||||
InviteLink string
|
||||
IsAccessible bool
|
||||
}
|
||||
|
||||
const channelIDOffset int64 = 1000000000000
|
||||
|
||||
@@ -44,16 +44,25 @@ func (uc *UseCase) processChannel(ctx context.Context, channel domain.Channel) e
|
||||
if isPrivateChannelError(err) {
|
||||
log.Warn().Err(err).Int64("telegram_id", channel.TelegramID).Msg("Private channel, attempting rejoin")
|
||||
if channel.InviteLink == "" {
|
||||
log.Warn().Int64("telegram_id", channel.TelegramID).Msg("No invite link stored, skipping channel")
|
||||
log.Warn().Int64("telegram_id", channel.TelegramID).Msg("No invite link stored, marking inaccessible")
|
||||
channel.IsAccessible = false
|
||||
if err := uc.database.UpdateChannel(ctx, channel); err != nil {
|
||||
return fmt.Errorf("database.UpdateChannel (mark inaccessible): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
updatedChannel, joinErr := uc.telegram.ParseChannelMetaByInvite(ctx, channel.InviteLink)
|
||||
if joinErr != nil {
|
||||
log.Warn().Err(joinErr).Int64("telegram_id", channel.TelegramID).Msg("Invite rejoin failed")
|
||||
log.Warn().Err(joinErr).Int64("telegram_id", channel.TelegramID).Msg("Invite rejoin failed, marking inaccessible")
|
||||
channel.IsAccessible = false
|
||||
if err := uc.database.UpdateChannel(ctx, channel); err != nil {
|
||||
return fmt.Errorf("database.UpdateChannel (mark inaccessible): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
updatedChannel.ID = channel.ID
|
||||
updatedChannel.InviteLink = channel.InviteLink
|
||||
updatedChannel.IsAccessible = true
|
||||
updatedChannel.Pts = 0
|
||||
if err := uc.database.UpdateChannel(ctx, updatedChannel); err != nil {
|
||||
return fmt.Errorf("database.UpdateChannel: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user