desmos-labs / mooncake

The first decentralized social app based on Desmos
MIT License
47 stars 14 forks source link

Duplicated posts showing up #155

Closed RiccardoM closed 3 years ago

RiccardoM commented 3 years ago
## Generic information - OS name and version: iOS 13 - Application build code: `5002` - Network type (mobile/Wi-Fi): Both - Reported by: @lauranori ## Bug description Upon voting to a poll, the poll gets duplicated inside the posts list. ## Steps to reproduce 1. Find a poll 2. Vote the poll 3. See the poll being duplicated ## Expected behavior The vote should be added properly and the poll should not be duplicated ## Why is it happening? Currently posts are stored locally using the SHA256 of their contents as unique keys. Unfortunately, inside the current implementation user answers to poll are also considered when computing the hash of a post. This means that when a user adds a new answer to a poll (voting it), a new hash is generated and used at the post local unique key, resulting in its duplication. ## Solutions I've tried replacing entirely the way that posts are referenced locally inside the device. Instead of using their SHA256 as unique keys, either their `id` or a locally-generated id is used instead. Currently this solution doesn't work because the following error is returned when the sync is performed: ```json { "jsonrpc": "2.0", "id": -1, "error": { "code": -32603, "message": "Internal error", "data": "unsupported type map" } } ``` Talking with the Tendermint team, this seems like a problem correlated to the type of a post's optional data: ```golang OptionalData map[string]string `json:"optional_data,omitempty" yaml:"optional_data,omitempty"` ``` Apparently Amino, which is used when de-serializing the JSON structure of a transaction, does not support maps. For this reason, the ideal thing to do would be changing the type of the `OptionalData` field to a slice of custom objects inside Desmos and Mooncake: ```golang OptionalData []OptionalData `json:"optional_data,omitempty" yaml:"optional_data,omitempty"` ``` This is tracked inside desmos-labs/desmos#272.
kwunyeung commented 3 years ago

It's not only for Poll data. Posts with attachments also have this behaviour.

RiccardoM commented 3 years ago

It's not only for Poll data. Posts with attachments also have this behaviour.

This is also related to the same hashing thing. The attachments initially have a reference to the local media, and then it changes to a remote one. Since it changes, the hash also changes resulting in this error.