BP-REST
BP-REST copied to clipboard
Is there is a way to check if a member already messaged another member?
Using REST API endpoint Is there is a way to check if a member already messaged another member? Or they never messaged each other?
We already check the documentation, but we can't find a special endpoint for it
thanks
No endpoint performs this specific check, but I think you can use https://developer.buddypress.org/bp-rest-api/reference/private-messaging/#list-messages-threads to get a user list of thread messages and compare it against this other user.
No endpoint performs this specific check, but I think you can use https://developer.buddypress.org/bp-rest-api/reference/private-messaging/#list-messages-threads to get a user list of thread messages and compare it against this other user.
Thank you for the answer, for now that what we are planning to do, but the problem is if the: get user list of threads only give last 10 threads and the thread with user we are trying to compare against is not returned in the last 10, this way we will not be able to make sure if there was a thread and I don't see a way to get second page for list of threads like we do in activities, even if there is a way it will be not good idea to keep calling the server again and again to compare against every page? Can you please plan to add an endpoint for it, it will be much faster, thank you
Could you elaborate more on ,what, and how, you are trying to do?
If you have an app, for example, that lists the threads of a user, why would you need to check if a thread/message was already created for another specific user unrelated to the current user?
Can you please plan to add an endpoint for it, it will be much faster, thank you
It'd be good to know what problem this is solving. We definitely can't add new endpoints to support specific features for everyone. A first look tells me this is something you should create yourself instead of bundling into BuddyPress but I'm curious about what and how you are trying to do it.
Could you elaborate more on ,what, and how, you are trying to do?
If you have an app, for example, that lists the threads of a user, why would you need to check if a thread/message was already created for another specific user unrelated to the current user?
Normal case You are right, in the normal case we do not need to know if a user messaged another user, when I build a message's inbox ill just get all the threads and list them all in the inbox if there are any. That's works great.
It'd be good to know what problem this is solving. We definitely can't add new endpoints to support specific features for everyone. A first look tells me this is something you should create yourself instead of bundling into BuddyPress but I'm curious about what and how you are trying to do it.
Second case The problem that will be solved is: let's say I'm logged as a user and browsing the activities then I wanted to message someone privately, ill create a message button under that user profile it will open new layout with text field input where I can write my message to him
but before I load the messaging layout I would like to check if I messaged this person before or not, if never messaged him before ill show blank layout and a text field where I can write my first message But if I messaged that user before, I would like to get the thread messages list the history of messages, so I can read all my previous messages to him then I can send more messages
I hope my explanation is clear
thank you
It looks like you want a new field on the member schema, similar to the friendship_status but checking if a user has a thread with the current logged in user.
Since you would: get the activities and the user related to the activity (including this new field with the "status" of the user, meaning if they have a thread with the current logged-in user.)
To my understanding it looks more like a "filter by recipient's user ID" messages need. This means, we'd need to edit BP_Messages_Thread::get_current_threads_for_user() to add an includes parameter to pass recipient ids and then add a "r.user_id IN {$includes)" clause there https://github.com/buddypress/buddypress/blob/master/src/bp-messages/classes/class-bp-messages-thread.php#L732
If you guys approved this and implement it please let us know, thanks
Related ticket: https://buddypress.trac.wordpress.org/ticket/9157