Page MenuHomePhabricator

[lib] implement Outbound P2P Messages API in `SQLiteAPI`
ClosedPublic

Authored by kamil on May 16 2024, 10:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 7:44 PM
Unknown Object (File)
Fri, Nov 22, 2:36 PM
Unknown Object (File)
Wed, Nov 13, 4:25 PM
Unknown Object (File)
Tue, Nov 12, 10:57 PM
Unknown Object (File)
Oct 20 2024, 10:49 AM
Unknown Object (File)
Oct 14 2024, 4:27 PM
Unknown Object (File)
Oct 14 2024, 4:27 PM
Unknown Object (File)
Oct 14 2024, 4:27 PM
Subscribers

Details

Summary

Using OutboundP2PMessage's from /lib.

Depends on D12079

Test Plan

Added some messages from C++ code:

OutboundP2PMessage msg1 = {
    "message_001",
    "device_01",
    "user_01",
    "1609459200",
    "Hello, world!",
    "SGVsbG8sIHdvcmxkIQ==",
    "encrypted"
};
OutboundP2PMessage msg2 = {
    "message_002",
    "device_01",
    "user_02",
    "1609459201",
    "Goodbye, world!",
    "R29vZGJ5ZSwgd29ybGQh",
    "encrypted"};
OutboundP2PMessage msg3 = {
    "message_003",
    "device_03",
    "user_03",
    "1609459202",
    "Hello again, world!",
    "SGVsbG8gYWdhaW4sIHdvcmxkIQ==",
    "encrypted"};

const std::vector<OutboundP2PMessage> messages = {msg1, msg2, msg3};

 static std::string addMessage =
      "REPLACE INTO outbound_p2p_messages ("
      " message_id, device_id, user_id, timestamp, plaintext, ciphertext, "
      "status"
      ") "
      "VALUES (?, ?, ?, ?, ?, ?, ?);";

  for (const OutboundP2PMessage &clientMessage : messages) {
    SQLiteOutboundP2PMessage message =
        clientMessage.toSQLiteOutboundP2PMessage();
    replaceEntity<SQLiteOutboundP2PMessage>(
        SQLiteQueryExecutor::getConnection(), addMessage, message);
  }

Execute this code from /lib:

const m1 = await sqliteAPI.getAllOutboundP2PMessage();
 console.log(m1);
 const msg: OutboundP2PMessage = m1[1];
 await sqliteAPI.markOutboundP2PMessageAsSent(msg.messageID, msg.deviceID);
 const m2 = await sqliteAPI.getAllOutboundP2PMessage();
 console.log(m2);
 await sqliteAPI.removeOutboundP2PMessagesOlderThan(
   msg.messageID,
   msg.deviceID,
 );
 const m3 = await sqliteAPI.getAllOutboundP2PMessage();
 console.log(m3);

And verify results on both web and native

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.May 17 2024, 3:27 AM
This revision is now accepted and ready to land.May 17 2024, 6:36 AM