Page MenuHomePhabricator

Implement translation of media JSON object to SQLite database entities
ClosedPublic

Authored by marcin on May 10 2022, 2:47 AM.
Tags
None
Referenced Files
F3279524: D3982.id12845.diff
Sat, Nov 16, 8:46 AM
F3279211: D3982.id12551.diff
Sat, Nov 16, 8:38 AM
F3279079: D3982.id12485.diff
Sat, Nov 16, 8:36 AM
F3279023: D3982.id13952.diff
Sat, Nov 16, 8:35 AM
Unknown Object (File)
Wed, Nov 13, 3:59 AM
Unknown Object (File)
Thu, Nov 7, 12:09 PM
Unknown Object (File)
Thu, Nov 7, 8:51 AM
Unknown Object (File)
Sat, Nov 2, 11:02 AM

Details

Summary

This diff introduces a function to convert folly dynamic thet represents media JSON object received with notification into SQLite database Media enitities.

Test Plan

No testing plan. Future diffs will provide a code that uses those functions on iOS and Android respectively

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Update commit message to include diff link

karol added inline comments.
native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
13 ↗(On Diff #12485)

What happens when there's nothing under a given key? Have you tested this case? Are you sure we won't encounter UB/crash here? asString may be then invoked on null or some random value from memory? I'm not sure.

This revision now requires changes to proceed.May 10 2022, 6:13 AM
native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
13 ↗(On Diff #12485)

According to folly documentation on dynamic: https://github.com/facebook/folly/blob/main/folly/docs/Dynamic.md and its implementation: https://github.com/facebook/folly/blob/main/folly/dynamic.cpp an attempt to access non-existing key throws std::out_of_range error and attempt to perform invalid conversion (e.g. asString() on some random memory ) throws folly::TypeError. Both of this can be try{} catch{}. This function is not intended to be used independently (we expect it to be used in translateRawMessageInfoToClientDBMessageInfo introduced in the next diff), so my proposal here is to make it private, let it crash in case of malicious operation and perform appropriate error handling in translateRawMessageInfoToClientDBMessageInfo where it is used to create std::vector<Media> that may potentially be empty.

An idea for a test plan might be to write a code that uses this function. This code could be invoked in any place of our app, or even as a separate main function.

native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
6 ↗(On Diff #12485)

Do we use this import?

23–30 ↗(On Diff #12485)

Are we sure it is a good idea to move these? We don't want to move when returning, but just wondering if we apply the same rule here.

Do not move, remove unnecessary includes.

karol added inline comments.
native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
13 ↗(On Diff #12485)

By "crash" you mean throw, right?

Thanks for the research, if folly throws on its own when accessing non-existent keys, then we're good here, I think.

This revision is now accepted and ready to land.May 13 2022, 5:53 AM

Rebase and move to persistent storage utilities