Comments, notifications and real-time communication in Nextcloud

Hi. I have created my own app on my Nextcloud server. My app has comments, notifications and custom_user. Now I wanna ask if Nextcloud supports comments and notifications. My app allows users working at the same time. When user1 create a new custom_user, it should update to user2. I found the event listener here: Events — Nextcloud latest Developer Manual latest documentation. I think that I can create listeners for creating/deleting/… custom_user. Another solution I found is using real-time communication. Does Nextcloud support it?

Could someone give me an idea? T.T

Hello @Lucy781227,

honestly, your question is unclear to me. It seems like a mix of features you want to have, already implemented features, and some implementation details.

What is custom_user? So this is the state of your app or the features you want it to have?

Again: What is the point here? You need support implementing these things?

This sounds like a requirement for how the app should behave. Without further information, this is more or less just useless gibberish.

These are implementation details. To help you, I need a bit more context. To explain what I mean: I give you a correct answer that will not satisfy you probably as you have something completely different in mind:

NC already provides this. You can comment on files, get notifications on changes of said files and add the guest app to create custom users.

Not what you are looking for? Please explain what you want to achieve. We cannot help and we do not have a magic glass ball.

Christian

Just one point on this that I forgot: I have seen you have the habit of pushing the question up 24h after initially posting it. This will not help much. The throughput here is not that high. If there were new information or the last post/answer was unclear, you are welcome to add stuff.

But: Please know that the community mainly manages and cultivates this forum. We, the community, are not sitting 24/7 waiting for new topics. There is no point in putting stress on the volunteers. Thank you for your patience.

I apologize for the ambiguity. My own app has a table named custom_user. Multiple users can create, edit, and delete records in table custom_user at the same time. The problem is that once a user creates a new record, that record is not updated in the apps of other users. I tried researching and found two solutions:

  1. Real-time communication: At this time, I’ve created another socket server. But I think it’s not an effective way.
  2. Nextcloud event listener: Through this link: Events — Nextcloud latest Developer Manual latest documentation, I can see that there are events for creating a new user, deleting a user, etc. So I wonder if I can create an event for creating a new record in custom_user, deleting a record, etc.

I got it. Some of my posts haven’t gotten any responses, so I’m worried that this one won’t either. I sincerely apologize and will eliminate this habit immediately.

1 Like

No Problem. I just wanted to point out that we are all community and sometimes a simple question cannot be given directly.

No offense intended.

1 Like

Okay, now things seem to get a bit clearer.

There are different notions of parallelism involved here.

First, there is a single call to the web server by let’s say user A. This call takes maybe 100ms until the answer is delivered to the browser or app in question. If during this time a second call to the server is made (high traffic!) then you might run into synchronization issues inside your app. This should be handled in the database layer.

Then, there is the event system in nextcloud. This is more of a publisher and subscriber pattern to communicate events from one location to other locations. For example, there server sends such an event when a user is created in the instance. All apps can register to the event and handle them. This is however only within such a 100ms request handling routine. The events are not propagated to the next request.

These things are not helping you much, I guess. What you need is a way to inform the frontend (browser code) of new data that has arrived in the backend. Am I correct?

I see two ways to do that in a quick way: poking and long calls. The polls all implements both, so you might want to have a look there for details. Long story sorry:

Polling means your frontend also the backend in regular intervals (all 5 sec or so) for updated data. Of course this scales not so good and the checks should be as cheap as possible.

Long calls means that you create requests that the server is not responding immediately (100ms above) but delayed dedicatedly. The server would wait for an event (new data written to database) in a loop and then answer the data to the server. To avoid tomorrow after a certain time it makes sense to about the long running request my sending that no change has happened. The frontend will then do something like polling but the requests will be much less frequent (1 per 30 sec for example).

As far as I know, there is no better way to do this. The polling is the simplest way to do it. Once this is done you can assignment to the wait mode of this is required, depending on your specs.

Does this help you with your problem?

Chris

Correct. This is exactly what I want. I’m afraid of polling because it will make the client more laggy (decreased performance). Is there any other alternative? I know websockets but I’m worried about security.

Websockets has the problem that you would need to use the new API to use Docker-Apps. The classical PHP apps do not provide a way to support websockets.

Polling is not that much if your services are not expensive. You need to to keep that in mind to tailor the polling content accordingly.

Thank you. I’ll try long polling. About the comment, my comment is not attached to a file, so I guess I need my own table. But for the notification, is there any way to push the notification and show it on the notification icon (on the top right) in Nextcloud?

Yeah, definitively a good idea not to hijack other apps’ tables :wink:. Do something for your own app or use the official API (if available).

See the dev docs with a link to the notification app, or in more details.

Christian

1 Like

Thank you so much, Chris. That’s very helpful.

1 Like