|
|
|
@ -179,14 +179,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
|
|
|
|
|
|
|
|
|
var photo string
|
|
|
|
|
if chat != nil && chat.Photo != nil {
|
|
|
|
|
path := chat.Photo.Small.Local.Path
|
|
|
|
|
if path == "" {
|
|
|
|
|
tgFile, err := c.DownloadFile(chat.Photo.Small.Id, 1, true)
|
|
|
|
|
if err == nil {
|
|
|
|
|
path = tgFile.Local.Path
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file, err := os.Open(path)
|
|
|
|
|
file, path, err := c.OpenPhotoFile(chat.Photo.Small, 1)
|
|
|
|
|
if err == nil {
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
@ -1006,6 +999,30 @@ func (c *Client) DownloadFile(id int32, priority int32, synchronous bool) (*clie
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OpenPhotoFile reliably obtains a photo if possible
|
|
|
|
|
func (c *Client) OpenPhotoFile(photoFile *client.File, priority int32) (*os.File, string, error) {
|
|
|
|
|
if photoFile == nil {
|
|
|
|
|
return nil, "", errors.New("Photo file not found")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path := photoFile.Local.Path
|
|
|
|
|
file, err := os.Open(path)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return file, path, nil
|
|
|
|
|
// obtain the photo right now if still not downloaded
|
|
|
|
|
} else if !photoFile.Local.IsDownloadingCompleted {
|
|
|
|
|
tdFile, tdErr := c.DownloadFile(photoFile.Id, priority, true)
|
|
|
|
|
if tdErr == nil {
|
|
|
|
|
path = tdFile.Local.Path
|
|
|
|
|
file, err = os.Open(path)
|
|
|
|
|
return file, path, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// give up
|
|
|
|
|
return nil, path, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// subscribe to a Telegram ID
|
|
|
|
|
func (c *Client) subscribeToID(id int64, chat *client.Chat) {
|
|
|
|
|
var args []args.V
|
|
|
|
|