0

I'm using Parse SDK's localDataStore to implement offline-capable Android app.

When users create new objects, they're pinned locally with a special label. When it's time to sync offline changes to the server, I search for all objects pinned with that label and save them. At that point, after the object is synced to the server, I want to remove the label, but keep the object pinned locally. The only way I found to achieve that is this:

parseObject.save();
parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE);
parseObject.pin();

Two problems with this approach:

  1. Takes too long
  2. Ugly

My intuition says that in this scenario it should be enough to just remove the label from the already pinned ParseObject, but I can't find a way to do that without full unpin. What do I miss?

Vasiliy
  • 16,221
  • 11
  • 71
  • 127
  • I believe there is no way to do what you want: remove the label, but keeping the object pinned. Maybe you can add two labels when pinning the object in the first place, and later on only remove the label that indicates it was modified. – Davi Macêdo Apr 05 '22 at 16:15
  • @DaviMacêdo, this clever hack might be sufficient for me. I'll try it. Thanks – Vasiliy Apr 06 '22 at 07:44

1 Answers1

0

Eventually, I couldn't find a way to just remove the label from a pinned object, without unpinning it.

So, we either need to pin the object after unpinning:

parseObject.save();
parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE);
parseObject.pin();

Or, as suggested by Davi in the comments, we could pin the object with two different labels to begin with, and then just keep one of them forever:

// when pinning
parseObject.pin(ParsePinLabels.DUMMY_LABEL);
parseObject.pin(ParsePinLabels.MODIFIED_OFFLINE);

// when syncing to the server
parseObject.save();
parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE); // object remains pinned with dummy label

However, when using the second approach, you might run into this nasty unresolved bug when using ParseObject.unpinAll(). Therefore, if you use the second approach, you'll need to remember to unpin all objects in this manner:

ParseObject.unpinAll()
ParseObject.unpinAll(ParsePinLabels.DUMMY_LABEL)
Vasiliy
  • 16,221
  • 11
  • 71
  • 127