Force downloading the chat photo when vCard is requested
This commit is contained in:
parent
02444d7a04
commit
6da0fd56ff
|
@ -134,11 +134,7 @@ func (c *Client) updateUserStatus(update *client.UpdateUserStatus) {
|
|||
func (c *Client) updateNewChat(update *client.UpdateNewChat) {
|
||||
go func() {
|
||||
if update.Chat != nil && update.Chat.Photo != nil && update.Chat.Photo.Small != nil {
|
||||
_, err := c.client.DownloadFile(&client.DownloadFileRequest{
|
||||
FileId: update.Chat.Photo.Small.Id,
|
||||
Priority: 32,
|
||||
Synchronous: false,
|
||||
})
|
||||
_, err := c.DownloadFile(update.Chat.Photo.Small.Id, 32, true)
|
||||
|
||||
if err != nil {
|
||||
log.Error("Failed to download the chat photo")
|
||||
|
@ -196,11 +192,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
|
|||
|
||||
// download file(s)
|
||||
if file != nil && !file.Local.IsDownloadingCompleted {
|
||||
c.client.DownloadFile(&client.DownloadFileRequest{
|
||||
FileId: file.Id,
|
||||
Priority: 10,
|
||||
Synchronous: false,
|
||||
})
|
||||
c.DownloadFile(file.Id, 10, false)
|
||||
}
|
||||
// OTR support (I do not know why would you need it, seriously)
|
||||
if !strings.HasPrefix(text, "?OTR") {
|
||||
|
|
|
@ -635,3 +635,12 @@ func (c *Client) getLastMessages(id int64, query string, from int64, count int32
|
|||
Limit: count,
|
||||
})
|
||||
}
|
||||
|
||||
// DownloadFile actually obtains a file by id given by TDlib
|
||||
func (c *Client) DownloadFile(id int32, priority int32, synchronous bool) (*client.File, error) {
|
||||
return c.client.DownloadFile(&client.DownloadFileRequest{
|
||||
FileId: id,
|
||||
Priority: priority,
|
||||
Synchronous: synchronous,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -236,6 +236,15 @@ func handleGetVcardTempIq(s xmpp.Sender, iq *stanza.IQ) {
|
|||
if chat.Photo != nil {
|
||||
path := chat.Photo.Small.Local.Path
|
||||
file, err := os.Open(path)
|
||||
// obtain the photo right now if still not downloaded
|
||||
if err != nil && !chat.Photo.Small.Local.IsDownloadingCompleted {
|
||||
tdFile, tdErr := session.DownloadFile(chat.Photo.Small.Id, 32, true)
|
||||
if tdErr == nil {
|
||||
path = tdFile.Local.Path
|
||||
file, err = os.Open(path)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
|
||||
|
@ -250,6 +259,8 @@ func handleGetVcardTempIq(s xmpp.Sender, iq *stanza.IQ) {
|
|||
}
|
||||
} else if path != "" {
|
||||
log.Errorf("Photo does not exist: %v", path)
|
||||
} else {
|
||||
log.Errorf("PHOTO: %#v", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue