hoehermann / purple-gowhatsapp

Pidgin/libpurple plug-in for WhatsApp Web.
GNU General Public License v3.0
289 stars 35 forks source link

Multi-Device Beta #90

Closed drkui closed 2 years ago

drkui commented 3 years ago

I joined the multi-device beta lab feature on WhatsApp and now when I scan the QR to login again, pidgin force closes the moment I do so.

hoehermann commented 3 years ago

Multi-device mode is not supported by go-whatsapp, see https://github.com/Rhymen/go-whatsapp/issues/598. This issue will probably be the end of this plug-in. :(

surskitt commented 2 years ago

Someone in that issue mentioned https://github.com/tulir/whatsmeow , it's not finished but under active development, hopefully it gets good enough to switch to.

XP-Fan commented 2 years ago

I'm pretty damn sure that whatsmeow is now mature enough, especially cause https://github.com/FKLC/WhatsAppToDiscord also uses it and this thing works amazingly well. However hoehermann are you willing to port? And on a completely different note: Are typing notifications yet supported?

hoehermann commented 2 years ago

@XP-Fan Thank you for the note. It sounds really promising.

Here in Germany, the next lockdown is just around the corner. With any luck it will give me much spare time on the weekends while not completely wrecking my motivation. :)

hoehermann commented 2 years ago

Good news, everyone! Farnsworth

After some encouragement by @XP-Fan and @pkar70, I switched from go-whatsapp to whatsmeow, doing a full re-write along the way. To all developers and power-users, please help me by testing the new beta. https://github.com/hoehermann/purple-gowhatsapp/tree/whatsmeow. Feel free to share your experiences by commenting on this issue. Please do not open new issues regarding this beta.

Building on Ubuntu and Arch has been tested by me. On Windows, MSVC will not produce a usable output. You need gcc (I tested with MSYS from MinGW). Recent binaries can be obtained from the buildbot.

EionRobb commented 2 years ago

The new beta doesn't show the QR code anywhere (other than in the debug log) when adding a new account

hoehermann commented 2 years ago

@EionRobb That is a total show-stopper! :astonished: :disappointed:

It works on my three test systems:

Ubuntu:

Arch:

Windows:

On Windows and Arch, I start with an empty Pidgin folder, on Ubuntu, I use my live one.

Your recommendation was very good. It has been working fine in gowhatsapp for years. I am still using it in this project. I currently do not see what I may have changed by accident.

hoehermann commented 2 years ago

Current limitations of whatsmeow:

EionRobb commented 2 years ago

Whoops, i didn't provide any helpful debugging. Sorry about that. 😄

I'm testing on Windows. When i try to hook it up the debug log is getting events including generating qrcodes as text, but the error log message is something like "there is no active account called eionrobb, skipping". Not sure what the exact error was, because i got past it by quickly copy-pasying the qr text into a image generator and scanning it (although whatsmeow wasn't happy i wasn't in the multi device beta)

After that point, i got a bit stuck, it doesn't grab my buddy list and when it does, i can't send a message to anyone. It's like the account isn't completely enabled?

hoehermann commented 2 years ago

As go and Pidgin maintain independent memory regions, I am mapping accounts between go-space and C-space. Apparently, that went out of sync for you. I used the username for identification, maybe that is not unique enough. I switched back to using a raw pointer, which feels more dangerous but has been rather reliable in the past. I updated the build in the post above. I am looking forward to your experiences. :)

EionRobb commented 2 years ago

Yay :) The new dll is displaying the QR Code popup :) I think half the problem was that I connected to the account as Away rather than Available?

Now I've gotten to the next problem: the buddy list didn't come through, and when I try to manually send it wont let me send. I could initiate messages from my phone and have the messages display in Pidgin, but I can't reply from Pidgin. image

Are you setting the purple connection state to PURPLE_CONNECTED? The username is showing in brackets which normally means offline, but with the Away status icon normally means the account isn't marked as connected yet.

Also, thanks for the demo code for QR stuff. It's gone full circle back into https://github.com/EionRobb/purple-discord/blob/qrcode-auth/discord_rsa.c#L43-L104 😄 )

hoehermann commented 2 years ago

@EionRobb I am very grateful for your input. Thank you so much!

Connection State

The plug-in should set the connection state as seen here. Does that look correct? I am remembering #24.

There are two paths the above code can be reached:

"Marked self as available" is the debug message you can look out for. Both paths should have the same effect. The connection should become "online".

Away vs. Available

I introduced the "Away" state here. I hope, I did that right. It has no effect on the user's own connection (I hope), but it is necessary (as far as I can tell) for the "Autoreply" plug-in. Also I need it so I can set buddies to "Away" and "Online" (as soon as the presence notification works). Is that correct?

Update and Multiple Accounts

In any case, I drastically re-did the log-in mechanism. It is now much more verbose and actually supports multiple accounts. Previously, I accidentally mangled all Pidgin accounts into the same WhatsApp session. The binary has been updated in the original post. It would be nice if you could try again.

QR Code Popup

That is nice to hear. ❤️

vitalyster commented 2 years ago

Is it possible to lower Go version requirement to 1.15? This will allow to build plugin using Debian golang version

vitalyster commented 2 years ago

Nevermind, I see 1.17 is backported

hoehermann commented 2 years ago

Glad to hear you found a way. For the record: No, it is not possible as whatsmeow depends on crypto implementation only available in 1.17 (and later, I hope).

verm commented 2 years ago

I tried this on FreeBSD 12 and it works perfectly. The old plugin would no longer log in and crashed as soon as you scanned the QR code. This is so much nicer thank you!

hoehermann commented 2 years ago

Thank you for sharing positive feedback. So far, the re-write has consumed more than 60 man hours. Your appreciation feels good.

verm commented 2 years ago

No problem! I know how it is I can tell you've spent a lot of time at this I looked at the code.

There are couple of issues I've run into.

One is anytime someone shares a video (edited: I said 'photo' previously) as a status Pidgin asks me if I want to download it. Is it possible to have a setting to autodownload images/files? It also happens during any video/file send actually.

Also I started getting a StreamReplaced Error. From the debug log:

(18:06:02) whatsmeow: [Client] Got replaced stream error, sending StreamReplaced event
(18:06:02) whatsmeow: recieved error (subtype 1) for account 0x8025421c0 remote (null) (isGroup 0) sender (null) (alias (null), fromMe 0) sent 0: StreamReplaced: &{}
(18:06:02) connection: Connection error on 0x83e5c3600 (reason: 16 description: StreamReplaced: &{})

This forces the plugin to stop if I hit Reconnect it doesn't try I have to go into Manage Accounts and enable it there.

Otherwise it's working great the async send takes a while to get used to since I'm so used to the pause when hitting send!

hoehermann commented 2 years ago

I have now officially released the whatsmeow re-write. The gowhatsapp branch has been deprecated. I consider this issue as "fix implemented".

hoehermann commented 1 year ago

@verm I somehow forgot to answer to your post.

One is anytime someone shares a video (edited: I said 'photo' previously) as a status Pidgin asks me if I want to download it. Is it possible to have a setting to autodownload images/files?

This is possible, but outside of the scope of this plug-in. Pidgin features an "autoaccept" plug-in which automatically accepts files and stores them in the default location. I do not know how about other front-ends. For images, you can also chose to have them inlined into the conversation window. I stick to the standard way of receiving files since non-standard solutions tend to break compatibility e.g. with protocol bridges such as Spectrum or bitlbee.

Connection error on 0x83e5c3600 (reason: 16 description: StreamReplaced: &{})

For me, this happens occasionally. Not frequently enough so I can debug it. I can reproduce the issue if I try to have more than four devices connected at a time. When a fifth device goes online, another one is replaced. This is a WhatsApp limitation. The reconnect does not happen automatically. This is by design since I do not want two auto-reconnects to fight each other.

Otherwise it's working great the async send takes a while to get used to since I'm so used to the pause when hitting send!

Yes, it feels weird at first. Other users like to rapidly send multiple one-word messages so it feels more natural to them, I guess.