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
F3525104: D12080.id40299.diff
Mon, Dec 23, 3:43 PM
F3525103: D12080.id40597.diff
Mon, Dec 23, 3:43 PM
F3525092: D12080.id.diff
Mon, Dec 23, 3:43 PM
F3525083: D12080.diff
Mon, Dec 23, 3:43 PM
Unknown Object (File)
Nov 22 2024, 7:44 PM
Unknown Object (File)
Nov 22 2024, 2:36 PM
Unknown Object (File)
Nov 13 2024, 4:25 PM
Unknown Object (File)
Nov 12 2024, 10:57 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
Lint Not Applicable
Unit
Tests Not Applicable

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