@@ -19,7 +19,7 @@ import (
19
19
"go.mongodb.org/mongo-driver/mongo"
20
20
)
21
21
22
- func PostAndCreateArtwork (ctx context.Context , artwork * types.Artwork , bot * telego.Bot , storage storage. Storage , fromID int64 ) error {
22
+ func PostAndCreateArtwork (ctx context.Context , artwork * types.Artwork , bot * telego.Bot , fromID int64 , messageID int ) error {
23
23
artworkInDB , err := service .GetArtworkByURL (ctx , artwork .SourceURL )
24
24
if err == nil && artworkInDB != nil {
25
25
Logger .Debugf ("Artwork %s already exists" , artwork .Title )
@@ -32,20 +32,60 @@ func PostAndCreateArtwork(ctx context.Context, artwork *types.Artwork, bot *tele
32
32
Logger .Debugf ("Artwork %s is deleted" , artwork .Title )
33
33
return errors .ErrArtworkDeleted
34
34
}
35
+ showProgress := fromID != 0 && messageID != 0 && bot != nil
36
+ if showProgress {
37
+ defer bot .EditMessageReplyMarkup (& telego.EditMessageReplyMarkupParams {
38
+ ChatID : telegoutil .ID (fromID ),
39
+ MessageID : messageID ,
40
+ ReplyMarkup : nil ,
41
+ })
42
+ }
35
43
for i , picture := range artwork .Pictures {
36
- info , err := storage .SavePicture (artwork , picture )
44
+ if showProgress {
45
+ go bot .EditMessageReplyMarkup (& telego.EditMessageReplyMarkupParams {
46
+ ChatID : telegoutil .ID (fromID ),
47
+ MessageID : messageID ,
48
+ ReplyMarkup : telegoutil .InlineKeyboard (
49
+ []telego.InlineKeyboardButton {
50
+ telegoutil .InlineKeyboardButton (fmt .Sprintf ("正在保存图片 %d/%d" , i + 1 , len (artwork .Pictures ))).WithCallbackData ("noop" ),
51
+ },
52
+ ),
53
+ })
54
+ }
55
+ info , err := storage .GetStorage ().SavePicture (artwork , picture )
37
56
if err != nil {
38
57
Logger .Errorf ("saving picture %d of artwork %s: %s" , i , artwork .Title , err )
39
58
return fmt .Errorf ("saving picture %d of artwork %s: %w" , i , artwork .Title , err )
40
59
}
41
60
artwork .Pictures [i ].StorageInfo = info
42
61
}
43
- messages , err := telegram .PostArtwork (telegram .Bot , artwork , storage )
62
+ if showProgress {
63
+ go bot .EditMessageReplyMarkup (& telego.EditMessageReplyMarkupParams {
64
+ ChatID : telegoutil .ID (fromID ),
65
+ MessageID : messageID ,
66
+ ReplyMarkup : telegoutil .InlineKeyboard (
67
+ []telego.InlineKeyboardButton {
68
+ telegoutil .InlineKeyboardButton ("图片保存完成, 正在发布到频道..." ).WithCallbackData ("noop" ),
69
+ },
70
+ ),
71
+ })
72
+ }
73
+ messages , err := telegram .PostArtwork (telegram .Bot , artwork )
44
74
if err != nil {
45
75
return fmt .Errorf ("posting artwork [%s](%s): %w" , artwork .Title , artwork .SourceURL , err )
46
76
}
47
77
Logger .Infof ("Posted artwork %s" , artwork .Title )
48
-
78
+ if showProgress {
79
+ go bot .EditMessageReplyMarkup (& telego.EditMessageReplyMarkupParams {
80
+ ChatID : telegoutil .ID (fromID ),
81
+ MessageID : messageID ,
82
+ ReplyMarkup : telegoutil .InlineKeyboard (
83
+ []telego.InlineKeyboardButton {
84
+ telegoutil .InlineKeyboardButton ("发布完成" ).WithCallbackData ("noop" ),
85
+ },
86
+ ),
87
+ })
88
+ }
49
89
for i , picture := range artwork .Pictures {
50
90
if picture .TelegramInfo == nil {
51
91
picture .TelegramInfo = & types.TelegramInfo {}
@@ -72,12 +112,12 @@ func PostAndCreateArtwork(ctx context.Context, artwork *types.Artwork, bot *tele
72
112
}()
73
113
return fmt .Errorf ("error when creating artwork %s: %w" , artwork .SourceURL , err )
74
114
}
75
- go afterCreate (context .TODO (), artwork , bot , storage , fromID )
115
+ go afterCreate (context .TODO (), artwork , bot , fromID , messageID )
76
116
77
117
return nil
78
118
}
79
119
80
- func afterCreate (ctx context.Context , artwork * types.Artwork , bot * telego.Bot , _ storage. Storage , fromID int64 ) {
120
+ func afterCreate (ctx context.Context , artwork * types.Artwork , bot * telego.Bot , fromID int64 , _ int ) {
81
121
for _ , picture := range artwork .Pictures {
82
122
if err := service .ProcessPictureAndUpdate (ctx , picture ); err != nil {
83
123
Logger .Warnf ("error when processing %d of artwork %s: %s" , picture .Index , artwork .Title , err )
0 commit comments