Flutter Blocs quick events leads to data loss - flutter

I am new to flutter and the famous flutter_bloc library. I have created a chat system based on the BLoC pattern :
A widget fires an event to chatBloc
The chatBloc catches the event, process it and call chatRepository
ChatRepository adds the message as a draft in its messageList variable and then sends the message to the API
ChatRepository receives the message from the API when it is done and replaces the draft within its messageList variable
ChatBloc yields its final state and the page rebuilds
Everything works fine as long as no more than one message is processed at a time.
If my button widget fires two quick events, they will overlap and so the second event will fire while the first event is still in progress. By the time when the second event starts, the first message is still a draft, so when message 2 completes and chatRepository updates its messageList, it will treat message 1 as a draft even if it has been validated.
At this point I'm asking myself if I made a mistake or if I'm trying to do it the wrong way.
Would it be better to create a queue and process messages in the background one by one ?
Thank you for your help !

Related

Best Practices For Handling Feed Subscription Events In getStream

Im having trouble finding documentation regarding best practices for handling activity data emitted from a realtime subscription to a getStream feed.
Our current set-up mimics what it seems react-activity-feed does: (1) subscribe to feed and listen for new activities (2) when a new activity is emitted display a button at the top of the feed announcing the new activity (3) when the announcement button is selected make a new feed.get() call to retrieve the most recent feed data.
The problem we are considering is how we could avoid making a new call to feed.get() every time a new activity is emitted (seems wasteful). We would rather store the original response data from feed.get() inside a state variable and insert new activities into that object.
This doesn't seem possible, however, as we get the following error whenever we try to append to the nested array inside the feed.get() response object: TypeError: Cannot assign to read only property 'activities'
I would greatly appreciate any advice on how others have handled new activities emitted from a feed.
I discovered that react-activity-feed does NOT make a call to feed.get() to retrieve the updated feed data after a new event is emitted to the feed.
feed.get() is only called when a feed is first visited or a pagination event occurs that makes a request to get more feed data. Otherwise, a copy of the feed activity object is created (using immutableJS.Map) and newly emitted events are pushed to this object which is used to display content in the feed (see object definition here). The same is done for managing reactions to activities as well as notifications.
So for anyone who is curious how to manage new events emitted from Streams real-time subscription try to managed feed state in your app by making a copy of the object that is initially returned by feed.get() and manipulate that object in your UI to limit the number of requests made to getStream and improves the performance of the feed as well.

Google action - duplicate MEDIA_FINISHED event received for each file

For each media response we are receiving duplicate MEDIA_FINISHED in MEDIA_STATUS. This is causing every user to skip one file for each media session. There is no identifier in the requests either so we can't ignore one of them.
This is for an existing Action SDK app which was earlier working fine and have broken recently.
This is my Response builder which has suggestion chips as well:
.add(audioString)
.add(
new MediaResponse()
.setMediaObjects(
new ArrayList<MediaObject>(
Arrays.asList(
new MediaObject()
.setName(mediaObject.getString("name"))
.setDescription(audioString)
.setContentUrl(
mediaObject.getString("contentUrl"))
.setIcon(
new Image()
.setUrl(
"https://www.somehost.com/blog/email-img/badge-108.png")
.setAccessibilityText("Logo")))))
.setMediaType("AUDIO"))
.addSuggestions(suggesstionArray);```
We managed to implement a workaround by sending a timestamp in our state. Once Action sdk sent the duplicate MEDIA_FINISHED intent then we replayed the last audio again if MEDIA_FINISHED intent and state has timestamp which less than 10 seconds. It was still a bad experience but we had no response from Google so we had to eventually take workaround route
Eventually this was fixed by Google (Not sure if accidentally) last week and now we are not receiving duplicate MEDIA_FINISHED intent

Recognize removal of Widget in Cockpit Dashboard on Cumulocity

Is there a way (maybe an event or something we can subscribe to) to acknowledge inside a self implemented widget, whenever this or another widget is removed from the dashboard?
There is nothing like an event you can subscribe to.
In the end there will always be a PUT request to update the dashboard object whenever it changes. Maybe you can utilize that.

Ionic 3 adding subscriptions for notification topic in a loop

In my Ionic app, I am trying to dynamically subscribe to topics based on the user's preference. So every time the app loads I am trying to re-subscribe them to their topics. I noticed that without resubscribing them, my callback code is not executed, and thus no popup notification is generated, when a notification comes for that given topic. Rather, the notification just ends up in the notification drawer (android).
So, the app boots up, I request the list of sub topics from my db and loop over each one calling the below function to subscribe:
addBillNotificationSubscription(topic: string){
console.log("Adding a bill notification subscription for topic: " + topic)
this.pushObject.subscribe(topic).then((res:any) =>{
console.log("Received test channel notification for topic: " + topic)
if (res.additionalData.foreground) {
this.showNotificationPopup(res);
}
})
console.log("Done Adding subscription")
}
Now when I call this in a loop, only the first iteration ever gets executed. I've double checked the elements in the list, there are several and even print them out in another loop right before the loop to subscribe. I'm assuming that I'm completely not understanding some fundamental thing, but I'm stumped. There's not much documentation (that I've found) on the proper way to even do these topic subscriptions or example use cases.
I've fully tested one topic subscription and have gotten it working in case the question arises.

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.