Skip to content

Commit

Permalink
fix up the iOS code
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 26, 2023
1 parent b9e5542 commit 71d3793
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
24 changes: 16 additions & 8 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function test(name: string, perform: () => Promise<boolean>) {
tests.push({ name, run: perform });
}

// test("can fail", async () => {
// return false;
// });
test("can fail", async () => {
return false;
});

test("can make a client", async () => {
const client = await XMTP.Client.createRandom({
Expand Down Expand Up @@ -559,9 +559,17 @@ test("canManagePreferences", async () => {
);
await delayToPropogate();

const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress)
await bo.contacts.refreshAllowList();
await delayToPropogate();

const initialConvoState = await alixConversation.allowState();
if (initialConvoState != "allowed") {
throw new Error(`conversations created by bo should be allowed by default not ${initialConvoState}`);
}

const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress);
if (!initialState) {
throw new Error(`conversations created by bob should be allowed by default not ${initialState}`);
throw new Error(`contacts created by bo should be allowed by default not ${initialState}`);
}

bo.contacts.block([alixConversation.clientAddress]);
Expand All @@ -570,18 +578,18 @@ test("canManagePreferences", async () => {
const blockedState = await bo.contacts.isBlocked(alixConversation.clientAddress);
const allowedState = await bo.contacts.isAllowed(alixConversation.clientAddress);
if (!blockedState) {
throw new Error(`conversations blocked by bob should be blocked not ${blockedState}`);
throw new Error(`contacts blocked by bo should be blocked not ${blockedState}`);
}

if (allowedState) {
throw new Error(`conversations blocked by bob should be blocked not ${allowedState}`);
throw new Error(`contacts blocked by bo should be blocked not ${allowedState}`);
}

const convoState = await alixConversation.allowState();
await delayToPropogate();

if (convoState != "blocked") {
throw new Error(`conversations blocked by bob should be blocked not ${convoState}`);
throw new Error(`conversations blocked by bo should be blocked not ${convoState}`);
}

return true
Expand Down
22 changes: 11 additions & 11 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,45 +521,45 @@ public class XMTPModule: Module {
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
return await client.contacts.isAllowed(address: address)
return await client.contacts.isAllowed(address)
}

AsyncFunction("isBlocked") { (clientAddress: String, address: String) -> Bool in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
return await client.contacts.isBlocked(address: address)
return await client.contacts.isBlocked(address)
}

AsyncFunction("blockContacts") { (clientAddress: String, addresses: [String]) in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
return try await client.contacts.block(addresses: addresses)
try await client.contacts.block(addresses: addresses)
}

AsyncFunction("allowContacts") { (clientAddress: String, addresses: [String]) in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
return try await client.contacts.allow(addresses: addresses)
try await client.contacts.allow(addresses: addresses)
}

AsyncFunction("refreshAllowList") { (clientAddress: String) in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
return try await client.contacts.refreshAllowList()
try await client.contacts.refreshAllowList()
}

AsyncFunction("conversationAllowState") { (clientAddress: String, conversationTopic: String) -> String in
guard let conversation = try await findConversation(clientAddress: clientAddress, topic: topic) else {
throw Error.conversationNotFound(topic)
guard let conversation = try await findConversation(clientAddress: clientAddress, topic: conversationTopic) else {
throw Error.conversationNotFound(conversationTopic)
}
switch (conversation.allowState()) {
case .allowed -> return "allowed"
case .blocked -> return "blocked"
case .unknown -> return "unknown"
switch (await conversation.allowState()) {
case .allowed: return "allowed"
case .blocked: return "blocked"
case .unknown: return "unknown"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class Client {
constructor(address: string) {
this.address = address;
this.conversations = new Conversations(this);
this.contacts = new Contacts(this);
}

async exportKeyBundle(): Promise<string> {
Expand Down

0 comments on commit 71d3793

Please sign in to comment.