Skip to content

Commit

Permalink
Merge pull request #1235 from WalletConnect/feature/notify-message-id
Browse files Browse the repository at this point in the history
[Notify] Message id
  • Loading branch information
flypaper0 authored Nov 21, 2023
2 parents 0854d91 + 54a8cb2 commit 48f1b15
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ final class NotifyTests: XCTestCase {
walletNotifyClientA.messagesPublisher
.sink { messages in
guard let newNotifyMessageRecord = messages.first else { return }
XCTAssertEqual(newNotifyMessageRecord.message, notifyMessage)
// ID's is not equal because server generates a new one
XCTAssertEqual(newNotifyMessageRecord.message.title, notifyMessage.title)
XCTAssertEqual(newNotifyMessageRecord.message.body, notifyMessage.body)
XCTAssertEqual(newNotifyMessageRecord.message.icon, notifyMessage.icon)
XCTAssertEqual(newNotifyMessageRecord.message.type, notifyMessage.type)
notifyMessageRecord = newNotifyMessageRecord
messageExpectation.fulfill()
}.store(in: &publishers)
Expand Down
1 change: 1 addition & 0 deletions Example/IntegrationTests/Stubs/PushMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WalletConnectNotify
extension NotifyMessage {
static func stub(type: String) -> NotifyMessage {
return NotifyMessage(
id: UUID().uuidString,
title: "swift_test",
body: "body",
icon: "https://images.unsplash.com/photo-1581224463294-908316338239?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=250&q=80",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import Foundation

public struct NotifyMessageRecord: Codable, Equatable, SqliteRow {
public let id: String
public let topic: String
public let message: NotifyMessage
public let publishedAt: Date

public var databaseId: String {
return id
public var id: String {
return message.id
}

public init(id: String, topic: String, message: NotifyMessage, publishedAt: Date) {
self.id = id
public init(topic: String, message: NotifyMessage, publishedAt: Date) {
self.topic = topic
self.message = message
self.publishedAt = publishedAt
}

public init(decoder: SqliteRowDecoder) throws {
self.id = try decoder.decodeString(at: 0)
self.topic = try decoder.decodeString(at: 1)

self.message = NotifyMessage(
id: try decoder.decodeString(at: 0),
title: try decoder.decodeString(at: 2),
body: try decoder.decodeString(at: 3),
icon: try decoder.decodeString(at: 4),
Expand All @@ -34,7 +32,7 @@ public struct NotifyMessageRecord: Codable, Equatable, SqliteRow {

public func encode() -> SqliteRowEncoder {
var encoder = SqliteRowEncoder()
encoder.encodeString(id, for: "id")
encoder.encodeString(message.id, for: "id")
encoder.encodeString(topic, for: "topic")
encoder.encodeString(message.title, for: "title")
encoder.encodeString(message.body, for: "body")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NotifyMessageSubscriber {
logger.debug("Decoded Notify Message: \(payload.topic)", properties: ["topic": payload.topic, "messageBody": messagePayload.message.body, "messageTitle": messagePayload.message.title, "publishedAt": payload.publishedAt.description, "id": payload.id.string])

let dappPubKey = try DIDKey(did: claims.iss)
let record = NotifyMessageRecord(id: payload.id.string, topic: payload.topic, message: messagePayload.message, publishedAt: payload.publishedAt)
let record = NotifyMessageRecord(topic: payload.topic, message: messagePayload.message, publishedAt: payload.publishedAt)
try notifyStorage.setMessage(record)

let receiptPayload = NotifyMessageReceiptPayload(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Foundation

public struct NotifyMessage: Codable, Equatable {
public let id: String
public let title: String
public let body: String
public let icon: String
public let url: String
public let type: String

public init(title: String, body: String, icon: String, url: String, type: String) {
public init(id: String, title: String, body: String, icon: String, url: String, type: String) {
self.id = id
self.title = title
self.body = body
self.icon = icon
Expand Down

0 comments on commit 48f1b15

Please sign in to comment.