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
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
Unknown Object (File)
Thu, Oct 24, 7:17 PM
Unknown Object (File)
Thu, Oct 24, 7:12 PM
Unknown Object (File)
Mon, Oct 21, 12:51 AM
Unknown Object (File)
Fri, Oct 18, 5:29 PM

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

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

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

Do we use this import?

23–30

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

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