pushListener not called on new messages
Hello.
Precondition: All Firebase setup steps are executed with no errors and firebase functions are listed on Functions page.
Problem: pushListener function is not called when a new message is added to Realtime Database.
Observation: running a function test using Google Cloud Platform testing UI produces an error: TypeError: Cannot read property 'from' of null
the error is reported on this line: const senderId = messageValue["from"];
Hi @waterman76 this is likely to be a setup issue I expect. You can check your Firebase database:

It should look like this. As you can see the from field exists. Can you check your database and see if this field exists. It could be that your test using GCP isn't representative. Can you send me a screenshot from your Firebase Console -> Functions -> Push listener -> Logs?
Also, can you tell me which version of the client you are using?
For reference, I'm using the cloud functions script and it's working fine. So I think it's likely a configuration issue.
Hello.
Our database has one additional node because we have used this setting: config.rootPath = "messages_dev"
According to the docs, this database structure should be fully supported.

We're using the latest Chat SDK codebase.
@waterman76 thanks for that information. Can you also send me the screenshot from your Firebase Console -> Functions -> Push listener -> Logs?
Here is the screenshot. The function does not trigger when new messages are added. This run was started from Google Test UI.

This is the JSON that was used to test the function:
{
"messages_dev" : { "threads" : { "6124ed940637f918e5c69de8" : { "messages" : { "3698EB71-3FF0-4CF0-B4EF-449C99241406" : { ".priority" : 1.629810215185E12, "date" : 1629810215185, "from" : "dzE2Wi87aFOVpt2IEiWDQ6dfxwI2", "meta" : { "text" : "Dacxbxbs" }, "read" : { "ahD6PBzbu1QaxZCjwK9mJS06dh72" : { "date" : 1629810215424, "status" : 1 }, "dzE2Wi87aFOVpt2IEiWDQ6dfxwI2" : { "date" : 1629810215185, "status" : 2 } }, "to" : [ "ahD6PBzbu1QaxZCjwK9mJS06dh72" ], "type" : 0 }, "6884FABA-BFC0-4A33-8497-342734E849B8" : { ".priority" : 1.629810202963E12, "date" : 1629810202963, "from" : "ahD6PBzbu1QaxZCjwK9mJS06dh72", "meta" : { "text" : "Resl" }, "read" : { "ahD6PBzbu1QaxZCjwK9mJS06dh72" : { "date" : 1629810202963, "status" : 2 }, "dzE2Wi87aFOVpt2IEiWDQ6dfxwI2" : { "date" : 1629810203197, "status" : 1 } }, "to" : [ "dzE2Wi87aFOVpt2IEiWDQ6dfxwI2" ], "type" : 0 } }, "users" : { "ahD6PBzbu1QaxZCjwK9mJS06dh72" : { "status" : "member" }, "dzE2Wi87aFOVpt2IEiWDQ6dfxwI2" : { "status" : "owner" } } } } } }
I think it will fail if it's not started by Firebase because the message data will be null.
I'm not sure why your functions are not being triggered. Are you using more than one real-time database?
If you can give me access to your firebase [email protected] I can have a quick look.
I have given you Viewer access to our Firebase account
Hi @waterman76 thanks! From looking at your data in the dev environment at least, all the threads are empty apart from a few where the messages were sent on the 24th of August.
Can you try deleting the threads and making one test thread and sending some messages?
Hi. We deleted all threads, but for unknown reasons, we don't see messages being recorded to firebase db
Ok, have you added the Firebase rules? Do you see any error message from the client?
We have resolved the problem that prevented the messages to be pushed to firebase db. We also see pushListener invocations, triggered by new messages.
We're not able to verify that notifications are working due to a new issue - we're not able to join 2 users in a chat. This was working, but now as soon as we call: BChatSDK.thread().addUsers(getThreadUsers([currentUser]), to: bcThread)
we receive an error: 2021-08-26 18:28:06.688548+0300 Cognizumer[2055:2899042] 7.11.0 - [Firebase/Database][I-RDB038012] updateChildValues: at /messages_dev/threads/SL-q8QRDqKAzhRxMTk6nbXkCMkUNpM2/users/jrnkbz1xSJfjIwpnJlRq5JP6NG02 failed: permission_denied
We're calling addUsers from the 2nd device(user) to join this user to a chat that was created on the 1st device.
Hi @waterman76 you can't call add the user from the second device. There is security in place which means that only a thread owner can add another user. The thread creator needs to add the second user.
Thanks for this clarification. One final question - can updates to the local user profile be pushed to firebase DB?
We're calling .setName(), .setMetaValue(), .setImageURL() on CDUser instance but the data in \users{user-id} is not updated.
We're calling BChatSDK.db().save() after setting the user properties.
Try: [BChatSDK.core pushUser]
Hello.
pushUser works, but we are still not able to add a user to a thread.
As advised, we're calling .addUsers() from the thread owner account but we don't see the new user being joined to the thread in firebase db. It seems that the new user is added, but only in the device cache.
Our code looks like this: thread.add(fbUser) BChatSDK.db().save()
We were unable to find a "pushThread" call - is there a call that pushes the thread user list changes?
Hi @waterman76 if you check this page in the documentation https://chat-sdk.gitbook.io/chat-sdk/guides/api-cheatsheet#messaging-server-api
It says:
The Chat SDK uses a series of services to make requests to the messaging server. These services are contained in a class called NetworkAdapter.
That means that if you want to do something that will affect the server, like adding a user to a thread, you will need to use one of these APIs. In the docs there is a list of all the services and you can choose the one that sounds most appropriate. For example, in this case we need to use the BChatSDK.thread() service.
To add a user you can call:
BChatSDK.thread().addUsers([user1], to: thread)
This pattern is consistently used throughout the SDK. If you want to affect the server, use one of the network adapter services. If you want to access the local database, use the BChatSDK.db() service and to override the UI, the BChatSDK.ui() service.