mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 06:05:20 +00:00
Refactor: BitchatMessage (#610)
* Extract BitchatMessage into a separate file * Convert `fromBinaryPayload` to `convenience init?` * Extract message dedup into an extension * Remove dead `formatMessageContent` * Minor refactor of timestamp and username formatting * Remove dead `getSenderColor`
This commit is contained in:
@@ -139,7 +139,7 @@ final class PrivateChatE2ETests: XCTestCase {
|
||||
alice.packetDeliveryHandler = { packet in
|
||||
// Encrypt outgoing private messages
|
||||
if packet.type == 0x01,
|
||||
let message = BitchatMessage.fromBinaryPayload(packet.payload),
|
||||
let message = BitchatMessage(packet.payload),
|
||||
message.isPrivate {
|
||||
do {
|
||||
let encrypted = try aliceManager.encrypt(packet.payload, for: TestConstants.testPeerID2)
|
||||
@@ -164,7 +164,7 @@ final class PrivateChatE2ETests: XCTestCase {
|
||||
if packet.type == 0x02 {
|
||||
do {
|
||||
let decrypted = try bobManager.decrypt(packet.payload, from: TestConstants.testPeerID1)
|
||||
if let message = BitchatMessage.fromBinaryPayload(decrypted) {
|
||||
if let message = BitchatMessage(decrypted) {
|
||||
XCTAssertEqual(message.content, TestConstants.testMessage1)
|
||||
XCTAssertTrue(message.isPrivate)
|
||||
expectation.fulfill()
|
||||
|
||||
@@ -98,7 +98,7 @@ final class PublicChatE2ETests: XCTestCase {
|
||||
// Set up relay in Bob
|
||||
bob.packetDeliveryHandler = { packet in
|
||||
// Bob should relay to Charlie
|
||||
if let message = BitchatMessage.fromBinaryPayload(packet.payload),
|
||||
if let message = BitchatMessage(packet.payload),
|
||||
message.sender == TestConstants.testNickname1 {
|
||||
|
||||
// Create relay message
|
||||
@@ -437,7 +437,7 @@ final class PublicChatE2ETests: XCTestCase {
|
||||
// Check if should relay
|
||||
guard packet.ttl > 1 else { return }
|
||||
|
||||
if let message = BitchatMessage.fromBinaryPayload(packet.payload) {
|
||||
if let message = BitchatMessage(packet.payload) {
|
||||
// Don't relay own messages
|
||||
guard message.senderPeerID != node.peerID else { return }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user