Skip to content

Commit

Permalink
Merge pull request #446 from edgardmessias/fix_profilepic
Browse files Browse the repository at this point in the history
fix: Fixed set profile picture (fix #359, close #426)
  • Loading branch information
orkestral authored Dec 17, 2020
2 parents 9c4017d + 034c603 commit 19b17a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/api/layers/profile.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class ProfileLayer extends HostLayer {
* Sets the user's current profile photo
* @param name
*/
public async setProfilePic(path: string) {
public async setProfilePic(path: string, to?: string) {
let b64 = await downloadFileToBase64(path, [
'image/gif',
'image/png',
Expand All @@ -137,9 +137,13 @@ export class ProfileLayer extends HostLayer {
_webb64_640 = await resizeImg(buff, { width: 640, height: 640 });
let obj = { a: _webb64_640, b: _webb64_96 };

return await this.page.evaluate(({ obj }) => WAPI.setProfilePic(obj), {
obj,
});
return await this.page.evaluate(
({ obj, to }) => WAPI.setProfilePic(obj, to),
{
obj,
to,
}
);
} else {
console.log('Not an image, allowed formats png, jpeg and webp');
return false;
Expand Down
14 changes: 6 additions & 8 deletions src/lib/wapi/functions/set-profile-pic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export async function setProfilePic(obj) {
var id = await Store.Me.attributes,
base64 = 'data:image/jpeg;base64,';
return await Store.Profile.sendSetPicture(
id.me._serialized,
base64 + obj.b,
base64 + obj.a
);
export async function setProfilePic(obj, id) {
if (!id) {
id = Store.Me.attributes.wid._serialized;
}
let base64 = 'data:image/jpeg;base64,';
return await Store.Profile.sendSetPicture(id, base64 + obj.b, base64 + obj.a);
}
2 changes: 1 addition & 1 deletion src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ interface WAPI {
setMessagesAdminsOnly: (chatId: string, option: boolean) => boolean;
setMyName: (name: string) => void;
setMyStatus: (to: string) => void;
setProfilePic: (path: string) => Promise<boolean>;
setProfilePic: (path: string, to?: string) => Promise<boolean>;
setTheme: (theme?: string) => boolean;
startTyping: (to: string) => void;
stopTyping: (to: string) => void;
Expand Down

0 comments on commit 19b17a7

Please sign in to comment.