fix: issues
This commit is contained in:
@@ -28,6 +28,7 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
request.OffsetID = cfg.MinID + limit
|
||||
request.MinID = cfg.MinID
|
||||
|
||||
logger.Info("get channel message history", zap.Int("min_id", request.MinID), zap.Int("offset", request.OffsetID), zap.Int("limit", request.Limit))
|
||||
history, err := t.Client.API().MessagesGetHistory(ctx, request)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "messages.getHistory")
|
||||
@@ -36,7 +37,11 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
messages := history.(*tg.MessagesChannelMessages).GetMessages()
|
||||
if len(messages) == 0 {
|
||||
if cfg.OffsetID > 0 && request.OffsetID < cfg.OffsetID {
|
||||
cfg.Update(ctx, request.OffsetID)
|
||||
logger.Info("no new message, but update config", zap.Int64("channel", channel.ID), zap.Int("offset", request.OffsetID))
|
||||
if err := cfg.Update(ctx, request.OffsetID); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
logger.Info("no new message", zap.Int64("channel", channel.ID))
|
||||
@@ -52,14 +57,35 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
for _, item := range messages {
|
||||
switch item.(type) {
|
||||
case *tg.MessageEmpty:
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
case *tg.MessageService:
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
msg, ok := item.(*tg.Message)
|
||||
if !ok {
|
||||
logger.Error("convert msg to *tg.Message failed", zap.Int64("channel", channel.ID))
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user