Skip to content

Commit

Permalink
Merge 4953269 into e2274aa
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrisch authored Jan 16, 2025
2 parents e2274aa + 4953269 commit 3650e77
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 102 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"newArchEnabled": false,
"version": "2.1.0",
"ios": {
"buildNumber": "69"
"buildNumber": "70"
},
"android": {
"versionCode": 270
"versionCode": 271
}
}
}
2 changes: 1 addition & 1 deletion components/AccountSettingsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function AccountSettingsButton({ account }: Props) {
const methods = {
[translate("your_profile_page")]: async () => {
if (account) {
invalidateProfileSocialsQuery(account, account);
invalidateProfileSocialsQuery(account);
setCurrentAccount(account, false);
router.navigate("Chats");
navigate("Profile", {
Expand Down
47 changes: 26 additions & 21 deletions components/StateHandlers/HydrationStateHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export default function HydrationStateHandler() {
const startTime = new Date().getTime();
const accounts = getAccountsList();
if (accounts.length === 0) {
// Awaiting before showing onboarding
await getInstalledWallets(false);
try {
// Awaiting before showing onboarding
await getInstalledWallets(false);
} catch (e) {
logger.error("[Hydration] Error getting installed wallets", e);
}
} else {
// note(lustig) I don't think this does anything?
getInstalledWallets(false);
Expand All @@ -26,26 +30,27 @@ export default function HydrationStateHandler() {
logger.debug(
"[Hydration] Fetching persisted conversation list for all accounts"
);
await Promise.allSettled(
accounts.map(async (account) => {
const accountStartTime = new Date().getTime();
logger.debug(
`[Hydration] Fetching persisted conversation list for ${account}`
);

prefetchInboxIdQuery({ account });
prefetchConversationsQuery({ account });

const accountEndTime = new Date().getTime();
logger.debug(
`[Hydration] Done fetching persisted conversation list for ${account} in ${
(accountEndTime - accountStartTime) / 1000
} seconds`
);
})
);

logger.debug("[Hydration] Done fetching persisted conversation list");
accounts.map((account) => {
const accountStartTime = new Date().getTime();
logger.debug(
`[Hydration] Fetching persisted conversation list for ${account}`
);

prefetchInboxIdQuery({ account });
prefetchConversationsQuery({ account });

const accountEndTime = new Date().getTime();
logger.debug(
`[Hydration] Done fetching persisted conversation list for ${account} in ${
(accountEndTime - accountStartTime) / 1000
} seconds`
);
});

logger.debug(
"[Hydration] Done prefetching all accounts conversation lists"
);

useAppStore.getState().setHydrationDone(true);
logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion components/StateHandlers/MainIdentityStateHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function MainIdentityStateHandler() {
useEffect(() => {
if (userAddress) {
saveUser(userAddress, privyAccountId[userAddress] as string);
invalidateProfileSocialsQuery(userAddress, userAddress);
invalidateProfileSocialsQuery(userAddress);
}
}, [privyAccountId, userAddress]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function InviteUsersToExistingGroupScreen({

if (!isEmptyObject(profiles)) {
// Let's save the profiles for future use
setProfileRecordSocialsQueryData(currentAccount(), profiles);
setProfileRecordSocialsQueryData(profiles);
setStatus({
loading: false,
error: "",
Expand Down Expand Up @@ -233,7 +233,7 @@ export function InviteUsersToExistingGroupScreen({

if (!isEmptyObject(profiles)) {
// Let's save the profiles for future use
setProfileRecordSocialsQueryData(currentAccount(), profiles);
setProfileRecordSocialsQueryData(profiles);
setStatus({
loading: false,
error: "",
Expand Down
4 changes: 1 addition & 3 deletions hooks/useProfileSocials.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useCurrentAccount } from "@data/store/accountsStore";
import { useProfileSocialsQuery } from "@queries/useProfileSocialsQuery";

export const useProfileSocials = (peerAddress: string) => {
const currentAccount = useCurrentAccount();
return useProfileSocialsQuery(currentAccount!, peerAddress);
return useProfileSocialsQuery(peerAddress);
};
3 changes: 1 addition & 2 deletions hooks/useProfilesSocials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import { useProfileSocialsQueries } from "@queries/useProfileSocialsQuery";
* @returns
*/
export const useProfilesSocials = (peerAddresses: string[]) => {
const currentAccount = useCurrentAccount();
return useProfileSocialsQueries(currentAccount!, peerAddresses);
return useProfileSocialsQueries(peerAddresses);
};
16 changes: 8 additions & 8 deletions ios/ConverseNotificationExtension/MMKV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func getAccountsState() -> Accounts? {
}
}

func getProfilesStore(account: String, address: String) -> ProfileSocials? {
func getProfilesStore(address: String) -> ProfileSocials? {
let mmkv = getMmkv()
let key = "profileSocials-\(account.lowercased())-\(address.lowercased())"
let key = "profileSocials-\(address.lowercased())"
let profilesString = mmkv?.string(forKey: key)
if (profilesString == nil) {
return nil
Expand All @@ -72,9 +72,9 @@ func getProfilesStore(account: String, address: String) -> ProfileSocials? {
}
}

func getInboxIdProfilesStore(account: String, inboxId: String) -> ProfileSocials? {
func getInboxIdProfilesStore(inboxId: String) -> ProfileSocials? {
let mmkv = getMmkv()
let key = "inboxProfileSocials-\(account.lowercased())-\(inboxId.lowercased())"
let key = "inboxProfileSocials-\(inboxId.lowercased())"
let profilesString = mmkv?.string(forKey: key)
if (profilesString == nil) {
return nil
Expand All @@ -88,21 +88,21 @@ func getInboxIdProfilesStore(account: String, inboxId: String) -> ProfileSocials
}
}

func saveProfileSocials(account: String, address: String, socials: ProfileSocials) {
func saveProfileSocials(address: String, socials: ProfileSocials) {
let updatedAt = Int(Date().timeIntervalSince1970)
let newProfile = Profile(updatedAt: updatedAt, socials: socials)
let mmkv = getMmkv()
if let jsonData = try? JSONEncoder().encode(newProfile), let jsonString = String(data: jsonData, encoding: .utf8) {
mmkv?.set(jsonString, forKey: "profileSocials-\(account.lowercased())-\(address.lowercased())")
mmkv?.set(jsonString, forKey: "profileSocials-\(address.lowercased())")
}
}

func saveInboxIdProfileSocials(account: String, inboxId: String, socials: ProfileSocials) {
func saveInboxIdProfileSocials(inboxId: String, socials: ProfileSocials) {
let updatedAt = Int(Date().timeIntervalSince1970)
let newProfile = Profile(updatedAt: updatedAt, socials: socials)
let mmkv = getMmkv()
if let jsonData = try? JSONEncoder().encode(newProfile), let jsonString = String(data: jsonData, encoding: .utf8) {
mmkv?.set(jsonString, forKey: "inboxProfileSocials-\(account.lowercased())-\(inboxId.lowercased())")
mmkv?.set(jsonString, forKey: "inboxProfileSocials-\(inboxId.lowercased())")
}
}

Expand Down
24 changes: 12 additions & 12 deletions ios/ConverseNotificationExtension/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@
import Foundation
import Alamofire

func getProfile(account: String, address: String) async -> ProfileSocials? {
var profileFromStore = getProfilesStore(account: account, address: address)
func getProfile(address: String) async -> ProfileSocials? {
var profileFromStore = getProfilesStore(address: address)
let formattedAddress = address.lowercased()
if let profile = profileFromStore {
return profile
}

// If profile is nil, let's refresh it
try? await refreshProfileFromBackend(account: account, address: formattedAddress)
try? await refreshProfileFromBackend(address: formattedAddress)

profileFromStore = getProfilesStore(account: account, address: address)
profileFromStore = getProfilesStore(address: address)
if let profile = profileFromStore {
return profile
}
return nil
}

func getInboxIdProfile(account: String, inboxId: String) async -> ProfileSocials? {
var profileFromStore = getInboxIdProfilesStore(account: account, inboxId: inboxId)
func getInboxIdProfile(inboxId: String) async -> ProfileSocials? {
var profileFromStore = getInboxIdProfilesStore(inboxId: inboxId)
if let profile = profileFromStore {
return profile
}

// If profile is nil, let's refresh it
try? await refreshInboxProfileFromBackend(account: account, inboxId: inboxId)
try? await refreshInboxProfileFromBackend(inboxId: inboxId)

profileFromStore = getInboxIdProfilesStore(account: account, inboxId: inboxId)
profileFromStore = getInboxIdProfilesStore(inboxId: inboxId)
if let profile = profileFromStore {
return profile
}
return nil
}

func refreshProfileFromBackend(account: String, address: String) async throws {
func refreshProfileFromBackend(address: String) async throws {
let apiURI = getApiURI()
if (apiURI != nil && !apiURI!.isEmpty) {
let profileURI = "\(apiURI ?? "")/api/profile"
Expand All @@ -63,15 +63,15 @@ func refreshProfileFromBackend(account: String, address: String) async throws {
let decoder = JSONDecoder()

if let socials = try? decoder.decode(ProfileSocials.self, from: response) {
saveProfileSocials(account: account, address: address, socials: socials)
saveProfileSocials(address: address, socials: socials)
}


}

}

func refreshInboxProfileFromBackend(account: String, inboxId: String) async throws {
func refreshInboxProfileFromBackend(inboxId: String) async throws {
let apiURI = getApiURI()
if (apiURI != nil && !apiURI!.isEmpty) {
let profileURI = "\(apiURI ?? "")/api/inbox"
Expand All @@ -93,7 +93,7 @@ func refreshInboxProfileFromBackend(account: String, inboxId: String) async thro
let decoder = JSONDecoder()

if let socials = try? decoder.decode(ProfileSocials.self, from: response) {
saveInboxIdProfileSocials(account: account, inboxId: inboxId, socials: socials)
saveInboxIdProfileSocials(inboxId: inboxId, socials: socials)
}

}
Expand Down
4 changes: 2 additions & 2 deletions ios/ConverseNotificationExtension/Xmtp/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func handleV3Message(xmtpClient: XMTP.Client, envelope: XMTP.Xmtp_MessageApi_V1_
}
// We replaced decodedMessage.senderAddress from inboxId to actual address
// so it appears well in the app until inboxId is a first class citizen
if let senderProfileSocials = await getInboxIdProfile(account: xmtpClient.address, inboxId: decodedMessage.senderInboxId) {
if let senderProfileSocials = await getInboxIdProfile(inboxId: decodedMessage.senderInboxId) {
bestAttemptContent.subtitle = getPreferredName(address: decodedMessage.senderInboxId, socials: senderProfileSocials)
}

Expand All @@ -89,7 +89,7 @@ func handleV3Message(xmtpClient: XMTP.Client, envelope: XMTP.Xmtp_MessageApi_V1_
messageIntent = getIncomingGroupMessageIntent(group: group, content: bestAttemptContent.body, senderId: decodedMessage.senderInboxId, senderName: bestAttemptContent.subtitle)
} else if case .dm(let dm) = conversation {
var senderAvatar: String? = nil
if let senderProfileSocials = await getInboxIdProfile(account: xmtpClient.address, inboxId: decodedMessage.senderInboxId) {
if let senderProfileSocials = await getInboxIdProfile(inboxId: decodedMessage.senderInboxId) {
let name = getPreferredName(address: decodedMessage.senderInboxId, socials: senderProfileSocials)
bestAttemptContent.title = getPreferredName(address: decodedMessage.senderInboxId, socials: senderProfileSocials)
senderAvatar = getPreferredAvatar(socials: senderProfileSocials)
Expand Down
Loading

0 comments on commit 3650e77

Please sign in to comment.