BlueBubblesApp / bluebubbles-server

Server for forwarding iMessages to clients within the BlueBubbles App ecosystem
https://bluebubbles.app
Apache License 2.0
554 stars 47 forks source link

Where are messages marked read #552

Closed SarvagyaVaish closed 1 year ago

SarvagyaVaish commented 1 year ago

I am trying to get an understanding of how messages are marked as "read". I found this code here emits an event, but I am unable to find where the message is received and processed. Any suggestions and help is much appreciated! Thank you :)

    static async markRead(chatGuid: string): Promise<void> {
        await Server().privateApiHelper.markChatRead(chatGuid);
        await Server().emitMessage(CHAT_READ_STATUS_CHANGED, {
            chatGuid,
            read: true
        });
    }

https://github.com/BlueBubblesApp/bluebubbles-server/blob/67284b60ac9d5636e24d55c0d703b3102f2ef130/packages/server/src/server/api/v1/interfaces/chatInterface.ts#L351C45-L351C45

zlshames commented 1 year ago

Marking a message as read happens within the private API helper. The server kinda just passed the message to it.

What are you trying to do/accomplish here?

SarvagyaVaish commented 1 year ago

I am trying to add a feature in this Mac app called 2FHey. It copies the 2FA code from text messages onto the clipboard. I would like to take it one step further and mark the message as read as well. Could you point me to the code in the private API helper where this is happening, please? Or perhaps my approach overall is flawed. Do you have a better recommendation?

zlshames commented 1 year ago

Seems like what you're trying to do is a client-side feature, not a server-side feature. Or are you just trying to mark all 2FA code messages as ready automatically

SarvagyaVaish commented 1 year ago

This application only has a client side component. No server side component. It listens to changes to the local iMessages DB and extracts the 2FA from the text body. Yea, I’d like to mark all the 2FA messages as read after coping the code.

zlshames commented 1 year ago

I am trying to add a feature in this Mac app called 2FHey. It copies the 2FA code from text messages onto the clipboard. I would like to take it one step further and mark the message as read as well. Could you point me to the code in the private API helper where this is happening, please? Or perhaps my approach overall is flawed. Do you have a better recommendation?

right, but i assume you want the client to copy it, not the server. so the code would all need to be on the client-side. There are APIs to call to mark chats as read

SarvagyaVaish commented 1 year ago

Yes the client is the one copying and marking the texts as read. Can you point me to the code for the api calls for that please? Thanks so much for your help!

zlshames commented 1 year ago

Yes the client is the one copying and marking the texts as read. Can you point me to the code for the api calls for that please? Thanks so much for your help!

https://github.com/BlueBubblesApp/bluebubbles-app/blob/master/lib/services/network/http_service.dart#L406

SarvagyaVaish commented 1 year ago

Thank you! One more question, if i may. Where is the (ss.settings.serverAddress.value).origin getting set / getting retrieved from. https://github.com/BlueBubblesApp/bluebubbles-app/blob/c27225ce21ad20dc19238bea518950025e4e2545/lib/services/network/http_service.dart#L19

zlshames commented 1 year ago

Thank you! One more question, if i may. Where is the (ss.settings.serverAddress.value).origin getting set / getting retrieved from. https://github.com/BlueBubblesApp/bluebubbles-app/blob/c27225ce21ad20dc19238bea518950025e4e2545/lib/services/network/http_service.dart#L19

Why do you need to worry about where it gets set? That shouldnt be a part of your workflow for this use-case

SarvagyaVaish commented 1 year ago

Oh, that’s because I’m trying to replicate this in our app.

zlshames commented 1 year ago

Oh, that’s because I’m trying to replicate this in our app.

and what app is this? You're trying to create a separate app to work with BlueBubbles, that is just used for copying 2FA codes? Why not just implement it into BlueBubbles

SarvagyaVaish commented 1 year ago

Yeah. We already have an app called 2FHey (https://github.com/SoFriendly/2fhey/) with many users that’s quite lightweight since it’s only the client side. Trying to add functionality to that.

zlshames commented 1 year ago

Yeah. We already have an app called 2FHey (https://github.com/SoFriendly/2fhey/) with many users that’s quite lightweight since it’s only the client side. Trying to add functionality to that.

Can you elaborate a bit on the arch of the app? I see the repo is a macOS app, that I assume interacts with a Browser Extension. Is that correct? So I assume you are already pulling the 2FA codes and your last task is to just mark the chat as read? I'm wondering what the server url will be used for in that use-case?

For what it's worth, marking a chat as read, is only available for users with the Private API enabled (which requires SIP to be disabled)

SarvagyaVaish commented 1 year ago

There's no browser extension. 2FHey reads the local chat.db [source] which is where messages are stored locally. It has access to this because the app requests full disk access during onboarding. After that's it's a matter of polling and parsing the messages to detect a 2FA code and copy it to the clipboard. Perhaps I don't fully understand what the Private API is. Can you elaborate a bit more on this and/or link me to some documentation, please?

zlshames commented 1 year ago

There's no browser extension. 2FHey reads the local chat.db [source] which is where messages are stored locally. It has access to this because the app requests full disk access during onboarding. After that's it's a matter of polling and parsing the messages to detect a 2FA code and copy it to the clipboard. Perhaps I don't fully understand what the Private API is. Can you elaborate a bit more on this and/or link me to some documentation, please?

Apple does not expose APIs to allow marking chats as read. Disabling SIP allows these APIs to be accessed. So the "Private API" in BlueBubbles relies on SIP to be disabled, so we can access those Private APIs to mark a chat as read.

Can you let me know what you're trying to do with BlueBubbles? Like would 2FHey rely on BlueBubbles to function in certain ways?