Keep track of read/unread User Messages with a MessageClicks table? - ruby-on-rails

I'm trying to implement a simple Inbox system for users of my app so that can send basic messages to each other - just like in many forum systems.
If User has_many :messages, how do I keep track of and notify the User of messages unread since last time they were read?
I'm thinking clicks on the link to the Messages screen need to be recorded in a separate table (MessagesClicks).
Is that the best approach here?
So then I check the MessagesClicks table to see if any new messages have arrived since the last time that link was clicked - based on a last_clicked or updated_at field.

I would keep track of when a message was read on the message itself with the default value of null.
If the user has any Messages with a dateRead value of null then they have unread messages.
When you display a message to the user on the Messages screen, update the dateRead property of the message from null to now.

Related

Twilio Programmable chat: Get Deleted messages

I want to give user the ability to delete messages.
In the code I am deleting a message using : message.remove(); and the message gets delete all fine.
Now I want to show users in the chat that a message was deleted at that particular place (like in whatsapp). But channel.getMessages() gives only non-deleted messages.
Is there a way to get deleted messages from twilio?
If not possible, I am thinking to update the message when user wants to delete (deleting only the message body). Please suggest if this is the best solution.
Twilio developer evangelist here.
Deleting a message will remove the message. If you want to keep that message history, your best bet would be to add an attribute to the message to indicate that it was deleted.
You can update the attributes of a message with the message.updateAttributes() method and then listen for updates on messages with the messageUpdated event and remove the message from your UI if the attributes indicate it was removed.

How best to save messages in the chat by timestamp?

I have the following question about creating a chat room. The message model has a creationTimeStamp property, it is assigned when the user sends messages from the device. When another user (or users receive this message), at the moment I do not change this property for the time when the message is received locally on the device. Messages I save locally in Realm. The problem is that for example the message was sent at one time to the first users, but because of the slow Internet connection, the second user already had time to send his message (or messages), then the second user appears this message after his sent message to ChatViewController, But when he leaves this controller and goes back, his message will be displayed last, and not the message of the first user, since when I take messages from Realm, I sort them by creationTimeStamp. So I want to learn the best practice of saving time stamp, for this case.
Can it be better to change the creationTimeStamp when the message is received on the device? But there are also problems here if the user has more than one device. Although I think that this is how messages are stored in iMessage, because they have the synchronization between devices, I attach screensots of the same correspondence, when messages were created quickly.
Unfortunately I don't have best practice for you, only some thoughts.
I think what you want to achieve is quite hard to achieve without inconveniencing users. What I mean is that due to internet connection speed, different users may all have different point of view about timing of your messages. You could correct/sync their view after some time using creationTimeStamp to resort messages, but then messages on screen will be reordered which could be annoying.
I guess you could think about different approach - is it that important that all users have the same timeline view? When some time ago we were implementing a group chat we agreed on the notion that single user can have different timeline view. Then we used recievedTimeStamp for sorting, for local messages receivedTimeStamp is the same as creationTimeStamp. It worked out pretty well for us, but of course you can have different requirements.

How to aggregate iOS push notifications using Parse

so I'm developing an application where a user might get a notification based on some action but I only want the user to receive one notification of a specific type. An example might illustrate this better:
Say a user on facebook makes a facebook post. If someone likes the post they'll get a notification. However, if 20 different people like that post I don't want 20 separate notifications when they finally check their phone. I want one notification that says '20 people have liked your post.' I also only want to track the new notifications. Say 20 people have liked your post. I don't want the notification for the next 5 who've liked your post to be '25 people have liked your post.' I want it to be '5 new people have liked your post.'
What I don't know how to do is delete a notification that got sent using Parse. An idea I thought of off the top of my head for recording new posts was to keep track of what the user has seen for that post but that seems silly. It's a large amount of data to keep track of, compared to querying for a previous notification to that user for that channel (is that possible?).
Anyways, I was hoping other users of Parse using push notifications might've faced this problem and how you all might've gotten around it. I would like to implement my own backend but I don't have the expertise and I'm currently focused on the client side. Any help or suggestion would be greatly appreciated. Thanks!
The thing is, you have don't have the control to cancel a Push Notification. However, you do have a control when to send even how to send it. If you want to implement something like you say, you have to do custom works on that. You might observe a period of time like 2-3 minutes whether there are more than for example 10 notifications you want to send. If so, send one instead.
Before iOS 8, Push Notification did have so many limitations like we can not have our own custom action. But now, I think Apple will let us do more as time goes by.
This might not be the best way but here's how I plan on implementing the feature. I'm going to add a notifications array to the user ([Notification objects]), this will also allow me to query for notifications for a possible notifications page. Say this were facebook and the user gets a new like notification on a post (1 like total).
I will create a new notification object and add it to the User object's notifications array with properties 'seen' set to false, 'prevNotificationLikes' set to 1, and then send out a notification. The message will be generic for singular/plural #'s of likes.
If someone else likes the post before the user responded to the push notification, I will see that the user hasn't 'seen' (false) the first notification and I will not send out a new notification.
Say 19 people like the post and then the user checks the initial notification and sets the 'seen' property to true. The next notification check on the cloud code for the 21st like will query to see if there are any previous notifications for that post/user. Parse cloud will then find a corresponding notification for that post/like where prevNotificationLikes is equal to 1 and update that number to 21. If the 'seen' property is set to true, then it'll send out a notification '20 new people have liked your post.' I know that the notifications are sent 1 step late with the fact that the user probably already knows that 19 people have liked the post but it'll be a compromise to get the job done.
Any critique is welcome. Sorry for wall of text instead of code. I'm just writing out my idea before writing the code so that I have something to follow along.

Quickblox: Share 1.Image and 2.Video along with text chat among users

I am able to establish 1-1 chat by creating a room. I have used room because I will get history of last 50 messages (I would prefer more in number with paged results and expecting this feature in the near future).
I am unable to figure out how I can implement image and video sharing in between the text chat.
I also want this in the history I get. I mean I need to get the order of the text/image/video along with their details to display to the user.
When I upload an image file using Content module, the files are saved in a separate table in contents section (which is fine for user's gallery kind of app). But for chat we need to know who sent to whom and what (image/video/text).
I would like to know whether this is possible with the current version of the Quickblox sdk. or else is there any way we can establish this using Custom objects module? If possible, will this work if there are more number of users in the room? Please give me a solution to this.
If you want create chat with content, you need to use a Custom Objects. (in current QB version).
Advantage - you can also get chat history and implement deleting of message history.
But this method doesn't very simply.
At first you need create Custom objects represented next things:
single chat message
group chat message
(may be need create extended user profile)
At first, you can use QBChat module for changing service information between users.
When you need send message, you create Custom Object (CO) - message with parameters and upload it. When it uploading, you send service message via QB chat to your opponent user. When opponent will receive it, he should perform request for updating CO (in this case - single message).
As example, single chat message can contain next parameters:
opponent qb user id;
owner qb user id;
message text;
link to content;
Sending of content message divide to next steps:
At first, you need upload content file using Content module, and after this create message CO, upload it on server and send service message to your opponent

Process Subscription on Roster has got messed after new attribute has been added Ejabbered

I have a problem in the subscription process after adding a new attribute to the mod_roster_odbc.erl
This obviously required me to alter the table rosterusers adding a new column for the record as well as the queries get_roster (s) in the odbc_queries for this module. And then in the module mod_roster_odbc, I had to extend methods like process_iq (get and set(s)) methods and others like, record_to_string, raw_to_record, process_item_attrs, and also get_subscription_lists, and pending queries for the new attribute to be initialised when setting each element of the roster
I have tested my change to the point of setting each element of my roster and save it correctly to DB, the same goes for getting to roster and the new attribute/record is added just like expected.
Now, my problem is that I broke the subscription part in the client side. The client logic subscribes to each element of the roster, before this changed I was able to subscribe automatically between two contacts being online. As far as I understand, user A sets user B in its roster and subscribes and then server sends presence to user B with this request so that user B subscribes back to user A and user finally get them subscribed as "Both". This is not happening after my change in the server.
Currently, user A is able to set user B to its roster but it does appear offline and I can see that subscription is "None" from rosterusers, basically one has the other on the roster but they do not manage to be subscribed or see each other online. Just until user A sends a message to user B subscription get processed and Both are subscribed to each other.
Now, I would like to avoid providing my code changes because I do ask for hints to know where I might have broken this logic in the server side. What would be the part of the presence that got broken with so small change....

Resources