So I'm trying to make a notification system similar to Facebook's system. I have a cron job running in the background and when it feels the need to send out a notification to an user it uses the PHP (REST) SDK to send a push to Firebase. On the dashboard I have an 'on' callback that fetches all incoming notifications for the user and shows a notification for each incoming new notification
var push_ref = firebase_ref.on('child_added', function(push) {
new PNotify({
title: 'Notification',
text: push.val().message,
...
});
});
However, when I reload the page all previously sent notifications pops up simultaneously and fills the screen with notification boxes. I don't wanna delete the sent push notifications because later on I'm gonna make a system to fetch them and put them in a dropdown box (similar to the notification dropdown on Facebook).
My question is;
How can I keep all sent notifications but at the same time disable that Firebase returns all notifications when the client goes online again?
UPDATE:
Looked through their documentation again and saw that their retrieving data types are very different. It says under "child_Added" that it "is triggered once for each existing child and then again every time a new child is added to the specified path". This is why it is triggered once I reload the page with all the existing children.
Can you see any other types that might work for me, because I haven't found any.
You could have the client update each message on receipt to acknowledge that it was shown (set acknowledged = true or whatever). Then use the acknowledged field to filter the UI treatment to only highlighting unacknowledged messages.
This assumes the messages are user-specific, or your data structure will require a message/user mapping to hold the acknowledgements.
If the user is reading from a public stream of messages, you could save a user-specific lastReadDate or something that filters out the old messages.
Related
I've been working with getstream.io for a while
and currently I'm facing an issue with the notifications.
To start using notifications I thought it was easier to implement in reactions due to having the targetFeeds property, but I'm facing an access error. I'm trying achieve it doing the next.
UserA commenting in UserB publication
// Client is initialized with UserA info
const comment = await client.reactions.add('comment', activity.id, { data }, { targetFeeds: [`notifications:UserB.ID`] });
My question is how to send a notification to UserB notification feed.
The result I expect is userB receiving a notification like "userA has commented in your publication" or alike.
I believe the default feed for notifications is 'notification' (no s.)
Also I'm not fully aware of what you are tying to accomplish, but just a heads up there is also the TO field for targeting.
https://getstream.io/docs/targeting/?language=js
The issue as first pointed by Sanchaz was that I was using notifications as slug for the notification feed instead of notification, I thought that wasn't the case because I created the notification feed with notifications slug.
StreamIO support stated that if the notification feed doesn't match notification slug, the default permissions doesn't apply, therefore the solution was to rename the slug from notifications to notification.
I created a chat messenger between my website users based on wix repeater when a new msg launch a new row insert into chat collection (my chat collection including the following fields User A, User B, MSG ) and the messenger repeater should refresh for both users.
So if user A send a message to User B
I should do the following :
a new row inserts into DB.
User A repeater is refresh.
3. Refresh user B repeater
What is the best way to Refresh user B repeater?
I used afterInsert() to know which user received a message and when but now I need to send this user a trigger for a refresh.
I thought about sendMessage function after insert to this specific user and then refresh User B repeater when a new msg received (use onMessage ). the main problem is that I don't use wix chat so I can't generate channelId, If there was an option to send a message from a business to a specific user without channelId or alternatively get channelId without using wix chat app, it will solve this problem.
What should I use ?
You can use the Realtime API to create a subscriber for the collection on the client. In your backend code in the afterInsert function, publish a message to the specific client which execute the refresh function for the list in the repeater in the callback function. You could store the channel information for the client and backend to know each other alongside your message in your chat collection.
The best thing you can do is here is to set a setInterval() function under the page's onReady() function to refresh user B's dataset/repeater every 3-5 seconds which would check for fresh messages.
I use pusher to implement real-time chat and notifications in my website. Users are allowed to start conversation(chat) with others and conversation can be only 1 on 1.
Messages are also stored in db so that user could have chat history as well.
I user with userId=14 has three active conversation I would generate JS script in php that would connect him to pusher and subscribe for three presence-channels representing each of three conversations. Every channel has events like "new-msg" etc. Everything work great - users get message if chat window is open or notification badge if not.
The problem starts when another user want to start a new conversation with userId=14. There is no private or presence channel for that. If I used public channel then every logged in user would get notified which is not good.
What I do know is that once logged in my website users connect to pusher and additionally to already active presence-channels subsribe to public channel "new-conversations" but every user waits for specific event which represents his userId.
var pusher = new Pusher('APP_KEY');
var channel = pusher.subscribe('new-conversations');
channel.bind(userId,
function(data) {
// subscribes to new presence-channel using information from data variable
}
);
When another user wants to start conversation with userId=14 he makes ajax call to server where PHP script generates event representing userId=14 containing data about himself and sends it to every connected(logged in) user but only userId=14 is waiting for this. Once triggered userId=14 can subsribe to new presence-channel.
While all this scenario works, I was wondering if there is some better, more cleaner out-of-the-box solution to this situation? I have read through pusher documentation but found nothing but I refuse to except that pusher developrs havent though about it.
POSSIBLE SOLUTION
I though of another solution. Every user should subscribe to presence-channel var channel = pusher.subscribe('presence-14'); where 14 = userId. If userId= 39 wants to start conversation with him he would send userId=14 to server and server would send userId=39 to channel "presence-14". Is that it?
I am using SignalR for notifications in my web site but i couldn't find a way to send notifications according to the page/content.
Let me explain in details.
Assume that, there is a page for showing a record from database (for example a blog post).
So there is only one page for showing posts as it should be.
And every post has a like counter which i want to update via signalr notifications, if another user clicks like button. Until here, it is very easy to accomplish.
This page contains a javascript code block like below
var notify = $.connection.notificationHub;
notify.client.updatePostLikeCount = function (likeCount) {
$("#likeCount").text(likeCount);
};
And this function triggered from server-side like below (it is in another class instead of Hub class)
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.User(user.Id).updatePostLikeCount(likeCount);
But a user might open more than one post; so if a notification is sent from server-side all opened tabs receive this notification and update its counter.
I looked for .Caller method but it is not available in IHubContext interface which GetHubContext() returns and couldn't find another way.
To summarize, i want to send notifications to users who had opened the post which user liked.
EDIT: After sending question i got an idea. Continue sending notification as being and filtering according to the content at client side. It is not very good but i think it will work with charms.
I'm developing nodejs application with users registration using sails.
I have an /signup method, which is looking for existing user, if user not found, it will create new user in db.
As you know in sails model (waterline) available few methods : beforeCreate, afterCreate. In beforeCreate I need also register user in a few other services(it takes +-2 seconds), after that I can set received data to user object.
The problem is if user clicks few times on "register" button (or just send the same request 2+ times in a row), it will create 2 objects in db ( or another services ). I have a similar with some other methods like this.
I was trying to set unique field in user model. Also maybe is good idea to implement police, witch can check user + reqest url and put this data into redis. If the second request arrives , check if it exists in Redis. Any other ideas?