IOS Chat App unread Messages in UITableview cell - swift

I have a Query related to Chat Application like Whatsapp. How to Calculate total number of Unread messages by friends in chat app like whatsapp. if we want to calculate all unread messages and show on a badge in current chat window only?

Without knowing how you model the conversations or without any code provided by you it's difficult to give you an exact answer but let's imagine a possible way to model it assuming you still haven't implemented nothing.
You could use a Message object class (or struct if using swift) to hold each conversation entry which could hold among other properties: message text, the User object owing the message, other relevant info etc and a property to determine if it was read (e.g. isRead Boolean property or an enum type .read .unread).
A Conversation object could be a List (an Array) of Message objects and if you want to know how many messages on a conversation are unread (to update UI, badge or whatever other UI widget you need to update) it would be a matter of filtering a given Conversation instance and counting the amount of Message objects inside of it that have isRead==false or whose status is .unread if you go the enum way.
This is a simplistic approach and may (or not) match your current implementation but as no code was provided by you, let's consider this an 'educated guess'.

Related

Firebase functions solution for building a secure Chat App with Seen functionality

I am building a chat app using Flutter and Firebase.
The way it works in Firebase Firestore is really simple, I just have a conversationId which represents the documents where there are the messages, all of the users have a list of their conversations, when they tap on a conversation, a new screen pops up where they see the messages based on data from the stream of the "Messages" collection that is under the conversationId document. Basically that's the structure
col: Chats
doc: conversationId
col: Messages
message documents...
And this is how I get the messages inside the Chat Screen.
_firestore
.collection("Chats")
.doc(_messageCollectionId)
.collection("Messages")
.orderBy("sentOn", descending: true)
.snapshots()
.map(...)
The message document is basically the message text and when it was sent and who sent it.
I want to create the "seen" functionality, inherently I want the user to see what conversation he read or not (which ones have new messages, like instagram chat or discord)
I can not come up with a good solution to this, my main 2 problems are:
If I were to call a cloud function which fetches the messages and somehow marks them as being read, that would break my app, as I need a continous stream of live message data for the chat to feel good, I can not stream data from the cloud function.
I would like to create a system which is not write intensive. If I would have to mark each message document in particular with some "seenOn :timestamp" value, that would mean that if the user is reading 200 new messages, there are 200 new writes on each document, which seems too much to me, there should be another way.
I am asking for guidance on how I should go about the architecture of such a chat using Firebase. Maybe my chat model is not really fit for what I need, how should I tweak it?
Another problem is that I do not know how the "seen" signal should be sent. If I manually write to a document and change the boolean value of some "isRead" field from my client, the client could easily skip that line of code and break my whole seen system, they could read messages without sending the seen signal just with a break point. This is quite exploitable, there is no cloud function trigger on documents "onRead" that could help me move that logic outside the client, so what is the solution to make this also secure?
so if you want to create the seen function you could made the database structure look like this first
you should create 2 collection for the db, the users collection would only save user data and in the chats collection inside of the uid is saving the chat room id that would be look like this
that was the collection inside of users. only put the roomId of connection that been made when user trying to send a new message to other user. put the the field exactly look like that. after that you could create a chatroom collection that look like this
to be sure that random uid inside of chats collection is a room id that you should register in your users/doc/chats/ collection. the field inside of the roomId would be a connection between of the 2 user for accesing the message that've been send to db. and inside of the chat collection you would send message data in this format
and after you put that you could retrieve the chat data using stream function that would look like this
Stream<QuerySnapshot<Map<String, dynamic>>> streamChats(String chatId) {
CollectionReference chats = firestore.collection("chats");
return chats.doc(chatId).collection("chat").orderBy("time").snapshots();
}
each time of user sending message you could put the total of message that've been send to other user in the total_unread field and update it when other of user open the chat roomId. and tada your seen could work properly
oh and you can create a function that check the total_unread is 0 already and you can put the seen/check icon beside of your user message bubble.

FB Chatbot how to get the previous message

Is it possible to receive the previous message that the user have send to the chatbot (without using quick replies or postback buttons). Example:
User: "Can you call a friend?"
Bot: "Who should I call?"
User: "Tim"
In the API I now have just the information "Tim", without knowing if I should call him or text him or make him a sandwich or whatever. So I basically I want to add some Postbackdata or metadata additionally to the text "Can you call a friend" (intent: 'CALL'), so the message "Tim" will come with that data.
Is there a way without storing the data into a database? AWS Lambda with ClaudiaJs.
I found the metadata field in the FB API which turns out to be the wrong field for that since it is only for communicating between several apps?!
What you are looking for a called a "slot-based bot", or slot-filling, basically meaning that you have a "slot", or blank that needs to be filled in before your bot can perform an action. In your example you have two slots: action and person
Actions could be: call, text, message
Person: name of a person, friend, etc.
I don't think any of the message frameworks (Slack, Facebook, etc) will provide you with the information you need. You will need to build this logic out yourself.
You can look at using wit.ai stories to achieve this.
Look to this similar Stack Overflow question and answer.
You can reverse order of conversation, and at beginning user writes some text or send you something else. After receiving, you should send to user buttonsTemplate, where postbacks will be like "CallTo&Tim" where instead of Tim you can put every text you need to pass to next executor(and you also can store previous user message here). Than just make substring of postback, check it`s type and do whatever you want.

Can PayPal's CUSTOM variable be used on eBay?

I program with PHP and I'm familiar with getting data from PayPal's IPN. I need to send custom data to ebay and get it back when payment is made. For example, if sold 1 Widget on ebay and that widget has a stock number of 12345A, I receive data back from PayPal. I get things like customer's name, address, item name, etc. But, unless I include that stock number in my title, I don't see any way to get that data back from PayPal. I don't want to use ebay's limited title space for including my stock numbers. I realize I could do it if I had another database to store ebay's item numbers and cross reference them with my stock numbers, but I don't want to do that.
I have noticed that when data comes back from PayPal after an ebay sale, it includes the custom variable and that variable has a large number in assigned to it. I have no idea what that is. I've also tried using ebay's custom label feature that's found in Turbo Lister and Selling Manager Pro. I was hoping that would be sent back in PayPal's custom variable, but no luck. Any ideas?
As you've discovered, it looks like it's some internal id number uniquely identifying each eBay order. You can probably forget about specifying a value for this field as it isn't documented anywhere.
The best solution to your problem is to use the eBay API. GetSingleItem will return information about an item given the item id.
The ItemSpecifics list will contain any item specific data that the seller has entered about the product. In my case, I added a custom field called SKU to the eBay item. Just add itemspecifics to your include selector. The call can be executed with a GET request:
http://open.api.ebay.com/shopping?callname=GetSingleItem&IncludeSelector=ItemSpecifics&appid=YOURAPPID=515&ItemID=ITEMIDOFINTEREST
What you get back will contain those custom fields you added to your item:
..
<ItemSpecifics>
<NameValueList>
<Name>MPN</Name>
<Value>MyPartModelA</Value>
</NameValueList>
<NameValueList>
<Name>SKU</Name>
<Value>123-456</Value>
</NameValueList>
</ItemSpecifics>
..

Facebook Profile Subscriber Count

Is there a method in the API to query the number of subscribers for one of the new profiles? I am talking about the new profiles (not pages), like this one for Tyra Banks:
http://www.facebook.com/XOXOTYTY
I can see on that page that she has 696k subscribers (more specifically, 696,833 as it shows when you search for her profile), but I cannot find that number in the graph.
I know that /userId/subscribers gives a list of my subscribers (which is awesome), but many pages that I'm querying have over 10k subscribers, so it doesn't list them all, and I just need the count.
Only user object have subscribers connection.
For page you can get count of "fans" by looking for likes property.
Update:
If you're looking for subscribers count on user object you need to use paging to get all the list, since there is no way to get only count of this data (currently, I hope this will be added later, since it's a really in high-demand by some players)...
Yet now you're out of luck since there is a BUG #134805496634011 with paging, so you may only get first page. There is limit argument but it's can't be whooping 697k for sure...

how to respond an error to payments_get_items method in the credit callback

Anybody know how to respond an error to the payments_get_items method?
for the payments_status_update method we can send a "canceled" status, but no error message is documented (as I konw) for the payments_get_items method
For example... there is an item any user can buy, but with a limited quantity global to the game; an user UI was loaded when there are items left so he can send an order, but when I was sending back the item description I detect that there aren't any item left: I don't want to send the description now and then give a "canceled" message in the following communication
any solution?
I don't believe there's an official method - one option would be to 'hack' around their system by responding with a "fake" item which costs 0 currency and informs the player that the item is no longer available.