Skip to content

Profile Picture Save + Fix Duplicate Problem - #12

Merged
patrizok merged 0 commit into
3bl3gamer:masterfrom
patrizok:master
Aug 10, 2022
Merged

Profile Picture Save + Fix Duplicate Problem#12
patrizok merged 0 commit into
3bl3gamer:masterfrom
patrizok:master

Conversation

@patrizok

@patrizok patrizok commented Dec 7, 2021

Copy link
Copy Markdown
Contributor

Hello again ;)

To fix this Issue #9 and adding profile picture save feature,
I check duplicate chats while appending and I change pp saving style.
To remind you, this pull request fix both Open Issue and makes unneccessary old pull request #10

I try to watch your comments on old pull request;
Added default WrongRespError to switch case.
Profile pictures saving a new directory to decrease file count in same folder.
Profile pictures saving with timestamps to detect duplicates and skip downloading next time.
Detecting duplicate chats algorithm was so complicated before, I do same thing with few lines of code;
5fdefa4#diff-d794c0fcc1a8766d115416f801ed1ea1b6d31c57acaa1f342c7ed9ac084c287fR212 (Line 212)

@3bl3gamer 3bl3gamer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello (:
Thank you again, and here are some comments:

Comment thread tg.go Outdated
for _, d := range group {
for _, c := range chats {
if d.ID == c.ID {
continue //If duplicates don't add to array again

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will continue the inner range chats loop, i.e. do nothing. Loop label is missing?

Comment thread tg.go Outdated
}
case mtproto.TL_photos_photosSlice: //Downloads first 20 photos if 20+ photos exists
photos := resPhotos.(mtproto.TL_photos_photosSlice)
for _, photo := range photos.Photos {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two almost same loops, better move it outside of switch. For example

var photos []mtproto.TL
switch {
    ...
    photos = append(photos, ...photos.Photos)
    ...
}
for _, photo := range photos {

Also, _, err = os.Stat(fpath) is missing in second (this one) loop.

Comment thread tg.go Outdated
}
}

func tgGetPhotoFileInfo(photo mtproto.TL_photo) *TGFileInfo {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func does the half work of the tgGetMessageMediaFileInfo. So it's better to move that half inside tgGetPhotoFileInfo (including FName: "photo.jpg" and if size == nil, just in case) and call this func from tgGetMessageMediaFileInfo.

Comment thread tg.go Outdated
for _, photo := range photos.Photos {
photo := photo.(mtproto.TL_photo)
file := tgGetPhotoFileInfo(photo)
fpath := profilePicFPath + "/" + strconv.Itoa(int(photo.Date)) + ".jpg"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better make file name more human-readable. I.e. profilePicFPath + "/" + time.Unix(photo.Date, 0).UTC().Format("2006-01-02_15-04-05Z")

Comment thread main.go Outdated
saver.SaveAccount(*me)
log.Info("User Account Info Saved")

tgSaveUserProfilePhotos(tg, *me, saver.profilePicFPath())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a config option for profile pics, so the whole dump could still be text-only. Something like "dump_account_profilepics": true/false and disabled by default.

That way it can also work independently of config.DoAccountDump (i.e. outside that if).

@patrizok
patrizok merged commit d5690ec into 3bl3gamer:master Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants