Skip to content

Commit

Permalink
Upgrade SDK to fix group streaming issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalzieu committed Sep 30, 2024
1 parent 9998e32 commit 9c4e461
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 81 deletions.
6 changes: 3 additions & 3 deletions components/DebugButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ const DebugButton = forwardRef((props, ref) => {
const client = (await getXmtpClient(currentAccount())) as Client;
const state = await client.inboxState(true);
Alert.alert(
`${state.installationIds.length} installations`,
`${state.installations.length} installations`,
`InboxId: ${client.inboxId}\n\nCurrent installation: ${
client.installationId
}\n\nAll installations:\n\n${state.installationIds
.map((i) => `${i}`)
}\n\nAll installations:\n\n${state.installations
.map((i) => `${i.id}`)
.join("\n\n")}`
);
},
Expand Down
26 changes: 13 additions & 13 deletions ios/ConverseNotificationExtension/Spam.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,28 @@ func computeSpamScoreGroupWelcome(client: XMTP.Client, group: XMTP.Group, apiURI
do {
let consentList = try await client.contacts.refreshConsentList()
// Probably an unlikely case until consent proofs for groups exist
let groupAllowed = await client.contacts.isGroupAllowed(groupId: group.id)
let groupAllowed = try await client.contacts.isGroupAllowed(groupId: group.id)
if groupAllowed {
return -1
}
let inviterInboxId = try group.addedByInboxId()
let inviterAllowed = await client.contacts.isInboxAllowed(inboxId: inviterInboxId)
let inviterAllowed = try await client.contacts.isInboxAllowed(inboxId: inviterInboxId)
if inviterAllowed {
return -1
}
let inviterDenied = await client.contacts.isInboxDenied(inboxId: inviterInboxId)
let inviterDenied = try await client.contacts.isInboxDenied(inboxId: inviterInboxId)
if inviterDenied {
return 1
}
let members = try group.members
let members = try await group.members
if let inviterAddresses = members.first(where: {$0.inboxId == inviterInboxId})?.addresses {
for address in inviterAddresses {
if await client.contacts.isDenied(EthereumAddress(address).toChecksumAddress()) {
if try await client.contacts.isDenied(EthereumAddress(address).toChecksumAddress()) {
return 1
}
}
for address in inviterAddresses {
if await client.contacts.isAllowed(EthereumAddress(address).toChecksumAddress()) {
if try await client.contacts.isAllowed(EthereumAddress(address).toChecksumAddress()) {
return -1
}
}
Expand All @@ -135,39 +135,39 @@ func computeSpamScoreGroupMessage(client: XMTP.Client, group: XMTP.Group, decode
do {

try await client.contacts.refreshConsentList()
let groupDenied = await client.contacts.isGroupDenied(groupId: group.id)
let groupDenied = try await client.contacts.isGroupDenied(groupId: group.id)
if groupDenied {
// Network consent will override other checks
return 1
}
let senderInboxId = decodedMessage.senderAddress
let senderDenied = await client.contacts.isInboxDenied(inboxId: senderInboxId)
let senderDenied = try await client.contacts.isInboxDenied(inboxId: senderInboxId)
if senderDenied {
// Network consent will override other checks
return 1
}

let senderAllowed = await client.contacts.isInboxAllowed(inboxId: senderInboxId)
let senderAllowed = try await client.contacts.isInboxAllowed(inboxId: senderInboxId)
if senderAllowed {
// Network consent will override other checks
return -1
}


let groupAllowed = await client.contacts.isGroupAllowed(groupId: group.id)
let groupAllowed = try await client.contacts.isGroupAllowed(groupId: group.id)
if groupAllowed {
// Network consent will override other checks
return -1
}

if let senderAddresses = try group.members.first(where: {$0.inboxId == senderInboxId})?.addresses {
if let senderAddresses = try await group.members.first(where: {$0.inboxId == senderInboxId})?.addresses {
for address in senderAddresses {
if await client.contacts.isDenied(EthereumAddress(address).toChecksumAddress()) {
if try await client.contacts.isDenied(EthereumAddress(address).toChecksumAddress()) {
return 1
}
}
for address in senderAddresses {
if await client.contacts.isAllowed(EthereumAddress(address).toChecksumAddress()) {
if try await client.contacts.isAllowed(EthereumAddress(address).toChecksumAddress()) {
return -1
}
}
Expand Down
6 changes: 3 additions & 3 deletions ios/ConverseNotificationExtension/Xmtp/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func handleGroupWelcome(xmtpClient: XMTP.Client, apiURI: String?, pushToken: Str
let spamScore = await computeSpamScoreGroupWelcome(client: xmtpClient, group: group, apiURI: apiURI)
if spamScore < 0 { // Message is going to main inbox
// Consent list is loaded in computeSpamScoreGroupWelcome
let groupAllowed = await xmtpClient.contacts.isGroupAllowed(groupId: group.id)
let groupDenied = await xmtpClient.contacts.isGroupDenied(groupId: group.id)
let groupAllowed = try await xmtpClient.contacts.isGroupAllowed(groupId: group.id)
let groupDenied = try await xmtpClient.contacts.isGroupDenied(groupId: group.id)
// If group is already consented (either way) then don't show a notification for welcome as this will likely be a second+ installation
if !groupAllowed && !groupDenied {
shouldShowNotification = true
Expand Down Expand Up @@ -157,7 +157,7 @@ func handleGroupMessage(xmtpClient: XMTP.Client, envelope: XMTP.Envelope, apiURI

// For now, use the group member linked address as "senderAddress"
// @todo => make inboxId a first class citizen
if let senderAddresses = try group.members.first(where: {$0.inboxId == decodedMessage.senderAddress})?.addresses {
if let senderAddresses = try await group.members.first(where: {$0.inboxId == decodedMessage.senderAddress})?.addresses {
decodedMessage.senderAddress = senderAddresses[0]
}

Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ install! 'cocoapods',


# Version must match version from XMTP Podspec (matching @xmtp/react-native-sdk from package.json)
# https://github.com/xmtp/xmtp-react-native/blob/v2.5.4/ios/XMTPReactNative.podspec#L29
$xmtpVersion = '0.14.13'
# https://github.com/xmtp/xmtp-react-native/blob/v2.6.2/ios/XMTPReactNative.podspec#L29
$xmtpVersion = '0.14.18'

# Pinning MMKV to 1.3.3 that has included that fix https://github.com/Tencent/MMKV/pull/1222#issuecomment-1905164314
$mmkvVersion = '1.3.3'
Expand Down
20 changes: 10 additions & 10 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ PODS:
- libwebp/sharpyuv (1.3.2)
- libwebp/webp (1.3.2):
- libwebp/sharpyuv
- LibXMTP (0.5.8-beta5)
- LibXMTP (0.5.8-beta7)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.3):
Expand Down Expand Up @@ -1815,16 +1815,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.14.13):
- XMTP (0.14.18):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.8-beta5)
- LibXMTP (= 0.5.8-beta7)
- web3.swift
- XMTPReactNative (2.5.4):
- XMTPReactNative (2.6.2):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.14.13)
- XMTP (= 0.14.18)
- Yoga (0.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -1962,7 +1962,7 @@ DEPENDENCIES:
- Sentry/HybridSDK (= 8.36.0)
- SQLite.swift
- UMAppLoader (from `../node_modules/unimodules-app-loader/ios`)
- XMTP (= 0.14.13)
- XMTP (= 0.14.18)
- "XMTPReactNative (from `../node_modules/@xmtp/react-native-sdk/ios`)"
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -2316,7 +2316,7 @@ SPEC CHECKSUMS:
libavif: 84bbb62fb232c3018d6f1bab79beea87e35de7b7
libdav1d: 23581a4d8ec811ff171ed5e2e05cd27bad64c39f
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
LibXMTP: ee1591fdb51bc6cc690c1a9ba10792ccc2104328
LibXMTP: 693447f2c1242dd2f5b2146828c52dbb2bd92d6f
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f902fb6719da13c2ab0965233d8963a59416f911
Expand Down Expand Up @@ -2416,10 +2416,10 @@ SPEC CHECKSUMS:
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
UMAppLoader: f17a5ee8e85b536ace0fc254b447a37ed198d57e
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: a9e7382ec5b57eeda3df7b177f034d061e3c9b61
XMTPReactNative: 63c46d6ba9b8dc5831ea49e8716f4b60cc012651
XMTP: ad01d17d7b513704b00033ee72ed544e48d38fcf
XMTPReactNative: fbdd0dfd7737bf2b27bd9265e140e1677f8f5a30
Yoga: 1ab23c1835475da69cf14e211a560e73aab24cb0

PODFILE CHECKSUM: beb6a8b55061fc0f811288dc66c75239474eba01
PODFILE CHECKSUM: bf2c4dd4d3291947d3f8f49dc3dfbee65c4c4e6c

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@xmtp/content-type-transaction-reference": "^1.0.3",
"@xmtp/frames-client": "^0.5.0",
"@xmtp/proto": "^3.60.0",
"@xmtp/react-native-sdk": "^2.5.4",
"@xmtp/react-native-sdk": "^2.6.2",
"@xmtp/xmtp-js": "11.5.0",
"amazon-cognito-identity-js": "^6.3.12",
"axios": "^1.2.1",
Expand Down
5 changes: 3 additions & 2 deletions utils/xmtpRN/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export const reconnectXmtpClientsDbConnections = async () => {

export const isClientInstallationValid = async (client: Client) => {
const inboxState = await client.inboxState(true);
const installationsIds = inboxState.installations.map((i) => i.id);
logger.debug(
`Current installation id : ${client.installationId} - All installation ids : ${inboxState.installationIds}`
`Current installation id : ${client.installationId} - All installation ids : ${installationsIds}`
);
if (!inboxState.installationIds.includes(client.installationId)) {
if (!installationsIds.includes(client.installationId)) {
logger.warn(`Installation ${client.installationId} has been revoked`);
return false;
} else {
Expand Down
43 changes: 0 additions & 43 deletions utils/xmtpRN/signIn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { debugEnabled } from "@components/DebugButton";
import { translate } from "@i18n";
import { awaitableAlert } from "@utils/alert";
import {
copyDatabasesToTemporaryDirectory,
createTemporaryDirectory,
Expand Down Expand Up @@ -78,43 +75,3 @@ export const getXmtpBase64KeyFromSigner = async (
logger.debug("Exported key bundle");
return base64Key;
};

/*
Temporary method for XMTP team to revoke other installations
when logging in to remove weird, broken installation
*/
const revokeOtherInstallations = async (signer: Signer, client: Client) => {
if (!debugEnabled(client.address)) {
return;
}
const state = await client.inboxState(true);
logger.debug(
`Current installation id : ${client.installationId} - All installation ids : ${state.installationIds}`
);
const otherInstallations = state.installationIds.filter(
(installationId) => installationId !== client.installationId
);
if (otherInstallations.length > 0) {
logger.warn(
`Inbox ${client.inboxId} has ${otherInstallations.length} installations to revoke`
);
// We're on a mobile wallet so we need to ask the user first
const doRevoke = await awaitableAlert(
translate("other_installations_count", {
count: otherInstallations.length,
}),
translate("temporary_revoke_description"),
"Yes",
"No"
);
if (!doRevoke) {
logger.debug(`[Onboarding] User decided not to revoke`);
return;
}
logger.debug(
`[Onboarding] User decided to revoke ${otherInstallations.length} installation`
);
await client.revokeAllOtherInstallations(signer);
logger.debug(`[Onboarding] Installations revoked.`);
}
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9588,10 +9588,10 @@
rxjs "^7.8.0"
undici "^5.8.1"

"@xmtp/react-native-sdk@^2.5.4":
version "2.5.4"
resolved "https://registry.yarnpkg.com/@xmtp/react-native-sdk/-/react-native-sdk-2.5.4.tgz#6869eeaa0f479971b923ca67ee54784d6e15d748"
integrity sha512-oujHd59zJpbMtT1IzL7K2YlhcYEU7u9hcH2fRw5xAgttqecYxTWZmzqHCKLD7t6RxuCBr/4adXSFqhmaJPpAJA==
"@xmtp/react-native-sdk@^2.6.2":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@xmtp/react-native-sdk/-/react-native-sdk-2.6.2.tgz#1e39a24822147fdc16cd795ca3b4aae1d6aa2f53"
integrity sha512-KB5sWM+sxjjTzIoHuhQhu8szOeYj5gU/Ba0MX/gOiQYpeVhVwO88KJKEp2JzJz3p+6AeT0nCrLn1dLVB9BrueQ==
dependencies:
"@ethersproject/bytes" "^5.7.0"
"@msgpack/msgpack" "^3.0.0-beta2"
Expand Down

0 comments on commit 9c4e461

Please sign in to comment.