Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change group consent to string instead of bytes #359

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions Sources/XMTPiOS/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,9 @@ public class ConsentList {
case .group_id:
switch entry.consentType {
case .allowed:
if let valueData = entry.value.data(using: .utf8) {
payload.allowGroup.groupIds.append(valueData)
}
payload.allowGroup.groupIds.append(entry.value)
case .denied:
if let valueData = entry.value.data(using: .utf8) {
payload.denyGroup.groupIds.append(valueData)
}
payload.denyGroup.groupIds.append(entry.value)
case .unknown:
payload.messageType = nil
}
Expand Down Expand Up @@ -192,17 +188,15 @@ public class ConsentList {
return entry
}

func allowGroup(groupId: Data) async -> ConsentListEntry {
let groupIdString = groupId.toHex
let entry = ConsentListEntry.groupId(groupId: groupIdString, type: ConsentState.allowed)
func allowGroup(groupId: String) async -> ConsentListEntry {
let entry = ConsentListEntry.groupId(groupId: groupId, type: ConsentState.allowed)
await entriesManager.set(entry.key, entry)

return entry
}

func denyGroup(groupId: Data) async -> ConsentListEntry {
let groupIdString = groupId.toHex
let entry = ConsentListEntry.groupId(groupId: groupIdString, type: ConsentState.denied)
func denyGroup(groupId: String) async -> ConsentListEntry {
let entry = ConsentListEntry.groupId(groupId: groupId, type: ConsentState.denied)
await entriesManager.set(entry.key, entry)

return entry
Expand Down Expand Up @@ -333,7 +327,7 @@ public actor Contacts {
try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
for groupId in groupIds {
group.addTask {
return await self.consentList.allowGroup(groupId: groupId)
return await self.consentList.allowGroup(groupId: groupId.toHex)
}
}

Expand All @@ -350,7 +344,7 @@ public actor Contacts {
try await withThrowingTaskGroup(of: ConsentListEntry.self) { group in
for groupId in groupIds {
group.addTask {
return await self.consentList.denyGroup(groupId: groupId)
return await self.consentList.denyGroup(groupId: groupId.toHex)
}
}

Expand Down
16 changes: 16 additions & 0 deletions Sources/XMTPiOS/Extensions/String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// String.swift
//
//
// Created by Naomi Plasterer on 7/1/24.
//

import Foundation


extension String {
var hexToData: Data {
return Data(self.web3.bytesFromHex ?? [])
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public struct Xmtp_MessageContents_PrivatePreferencesAction {
// methods supported on all messages.

/// Add the given group_ids to the allow list
public var groupIds: [Data] = []
public var groupIds: [String] = []

public var unknownFields = SwiftProtobuf.UnknownStorage()

Expand All @@ -205,7 +205,7 @@ public struct Xmtp_MessageContents_PrivatePreferencesAction {
// methods supported on all messages.

/// Add the given group_ids to the deny list
public var groupIds: [Data] = []
public var groupIds: [String] = []

public var unknownFields = SwiftProtobuf.UnknownStorage()

Expand Down Expand Up @@ -553,15 +553,15 @@ extension Xmtp_MessageContents_PrivatePreferencesAction.AllowGroup: SwiftProtobu
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeRepeatedBytesField(value: &self.groupIds) }()
case 1: try { try decoder.decodeRepeatedStringField(value: &self.groupIds) }()
default: break
}
}
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if !self.groupIds.isEmpty {
try visitor.visitRepeatedBytesField(value: self.groupIds, fieldNumber: 1)
try visitor.visitRepeatedStringField(value: self.groupIds, fieldNumber: 1)
}
try unknownFields.traverse(visitor: &visitor)
}
Expand All @@ -585,15 +585,15 @@ extension Xmtp_MessageContents_PrivatePreferencesAction.DenyGroup: SwiftProtobuf
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeRepeatedBytesField(value: &self.groupIds) }()
case 1: try { try decoder.decodeRepeatedStringField(value: &self.groupIds) }()
default: break
}
}
}

public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if !self.groupIds.isEmpty {
try visitor.visitRepeatedBytesField(value: self.groupIds, fieldNumber: 1)
try visitor.visitRepeatedStringField(value: self.groupIds, fieldNumber: 1)
}
try unknownFields.traverse(visitor: &visitor)
}
Expand Down
Loading
Loading