Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Hiroki Hokari
5,308 Pointsremove current user from recipientIds array
This is the part where I delete the message when the current user is the only recipient or remove current user's id from recipientIds array. And I'm confused, because I don't quite understand what is going on down there inside else{}. I got the image about processing locally and then saving onto Parse backend, but what does this mean?:
recipientIds.remove(ParseUser.getCurrentUser().getObjectId());
How is it different from this part?:
message.removeAll(ParseConstants.KEY_RECIPIENT_IDS, idsToRemove);
List<String> recipientIds = message.getList(ParseConstants.KEY_RECIPIENT_IDS);
if (recipientIds.size() == 1) {
// Last person to see. Delete it.
message.deleteInBackground();
}
else {
// There are still other people who didn't see it.
recipientIds.remove(ParseUser.getCurrentUser().getObjectId());
ArrayList<String> idsToRemove = new ArrayList<String>();
idsToRemove.add(ParseUser.getCurrentUser().getObjectId());
message.removeAll(ParseConstants.KEY_RECIPIENT_IDS, idsToRemove);
message.saveInBackground();
3 Answers
Dustin James
11,364 Points[EDITED]
// If the recipient list is less than 1, we know that the CurrentUser is the last user that needs to see the image/video
// so we will removeAll users from the list and remove the data from the backend.
if (recipientIds.Size() == 1) {
// This removes the message from the CurrentUser - More literally, we are removing the CurrentUser from the array of users the message was sent to.
recipientIds.remove(ParseUser.getCurrentUser().getObjectId());
}
else {
// We need to check to see if another user has not seen this image/video and we should not delete the message from the backend
I hope this helps. I have not programmed for the Android, but the iOS version of this app is pretty much the same thing.
Hiroki Hokari
5,308 PointsThank you for kindly answering Android's side.
I'm not really sure how it goes(like Billy Joel) ,cause I just finished and to be honest I have no idea anymore at some parts of this project. I don't remember them all.
But I think that that way the message itself remains on the backend with no users associated. I have to delete it.
Dustin James
11,364 PointsCorrect.
If a message contains 5 recipients on Parse, when one of the users (i.e. the current user) views the message it calls the if statement because there are now 4 users who are in the array. At that point, you are removing just the current user that just viewed the message.
Otherwise, the current user is the 5th person to view the message, therefore we can delete all users from the array and content from the Parse backend.
I agree that if you do an entire lesson back to back, not much sinks in. I would highly encourage you to Pause the video and read through each line to make sure you are understanding what you are coding. This helps ensure you at least understand the principals - everything else is just syntax. (i.e. you can speak english just fine, but grammar in written english has guidelines you should follow)
I also try to go back through a finished project to relearn what I've written.
Hiroki Hokari
5,308 PointsActually I think I've been very careful so that I understand most of the project if I take a peek at a completed app like I have now. But I can't understand this part....
I think your code's explanation ( // ) is reversed: "recipientIds.Size() == 1" means the current user is the last person to see the message so we can blow it off. Otherwise, which is inside else{ }, get rid of the current user id from recipient ids and save the revised recipient ids to the backend.
Dustin James
11,364 PointsYou're right. I fixed it. Thank you.