Skip to content

Commit

Permalink
Merge branch 'master' into deleted_users
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Aug 2, 2024
2 parents a64a9e1 + 27215f3 commit 248adda
Show file tree
Hide file tree
Showing 56 changed files with 1,893 additions and 284 deletions.
1 change: 1 addition & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Add logging to find deleted account with OGY tokens ([#6177](https://github.com/open-chat-labs/open-chat/pull/6177))
- Return deleted users in `users` response ([#6182](https://github.com/open-chat-labs/open-chat/pull/6182))

## [[2.0.1279](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1279-user_index)] - 2024-08-01

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user_index/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type UsersResponse = variant {
Success : record {
users : vec UserSummaryV2;
current_user : opt CurrentUserSummary;
deleted : vec UserId;
timestamp : TimestampMillis;
};
};
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user_index/api/src/queries/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Response {
pub struct Result {
pub users: Vec<UserSummaryV2>,
pub current_user: Option<CurrentUserSummary>,
pub deleted: Vec<UserId>,
pub timestamp: TimestampMillis,
}

Expand Down
41 changes: 23 additions & 18 deletions backend/canisters/user_index/impl/src/queries/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn users_impl(args: Args, state: &RuntimeState) -> Response {

let mut user_ids = HashSet::new();
let mut users = Vec::new();
let mut deleted = Vec::new();
let mut current_user: Option<CurrentUserSummary> = None;

if let Some(u) = state.data.users.get_by_principal(&caller) {
Expand Down Expand Up @@ -50,24 +51,27 @@ fn users_impl(args: Args, state: &RuntimeState) -> Response {
let now_month = MonthKey::from_timestamp(now);
for group in args.user_groups {
let updated_since = group.updated_since;
users.extend(
group
.users
.into_iter()
.filter_map(|u| state.data.users.get_by_user_id(&u))
.filter(move |u| {
(u.date_updated > updated_since
|| u.chit_updated > updated_since
|| (now > u.streak_ends && u.streak_ends > updated_since))
&& u.principal != caller
})
.filter(|u| user_ids.insert(u.user_id))
.map(|u| UserSummaryV2 {
user_id: u.user_id,
stable: (u.date_updated > updated_since).then(|| u.to_summary_stable(now)),
volatile: Some(u.to_summary_volatile(now, now_month)),
}),
);

for user_id in group.users {
if !user_ids.insert(user_id) {
continue;
}
if let Some(user) = state.data.users.get_by_user_id(&user_id).filter(|u| {
(u.date_updated > updated_since
|| u.chit_updated > updated_since
|| (now > u.streak_ends && u.streak_ends > updated_since))
&& u.principal != caller
}) {
users.push(UserSummaryV2 {
user_id,
stable: (user.date_updated > updated_since).then(|| user.to_summary_stable(now)),
volatile: Some(user.to_summary_volatile(now, now_month)),
});
// TODO maybe convert `deleted_users` to a HashMap?
} else if state.data.deleted_users.iter().any(|u| u.user_id == user_id) {
deleted.push(user_id)
}
}
}

if let Some(ts) = args.users_suspended_since {
Expand All @@ -87,6 +91,7 @@ fn users_impl(args: Args, state: &RuntimeState) -> Response {
Success(Result {
users,
current_user,
deleted,
timestamp: now,
})
}
1 change: 1 addition & 0 deletions frontend/app/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const languages = [
{ lang: "uk", code: "uk" },
{ lang: "vi", code: "vi" },
{ lang: "pl", code: "pl" },
{ lang: "fa", code: "fa" },
];

languages.forEach(async ({ lang, code }) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/Head.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
if (chat.kind === "direct_chat") {
title = `${title} -
${
users[chat.them.userId]?.displayName ??
users[chat.them.userId]?.username ??
users.get(chat.them.userId)?.displayName ??
users.get(chat.them.userId)?.username ??
"Direct chat"
}`;
} else {
Expand Down
10 changes: 5 additions & 5 deletions frontend/app/src/components/SelectChatModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@
switch (chatSummary.kind) {
case "direct_chat":
const description = await buildDirectChatDescription(chatSummary, now);
const them = $userStore[chatSummary.them.userId];
const them = $userStore.get(chatSummary.them.userId);
return {
kind: "chat",
id: chatSummary.id,
userId: chatSummary.them.userId,
name: client.displayName(them),
diamondStatus: them.diamondStatus,
streak: client.getStreak(them.userId),
diamondStatus: them?.diamondStatus ?? "inactive",
streak: client.getStreak(chatSummary.them.userId),
avatarUrl: client.userAvatarUrl(them),
description,
username: "@" + them.username,
username: them ? "@" + them.username : undefined,
lastUpdated: chatSummary.lastUpdated,
uniquePerson: them.isUniquePerson,
uniquePerson: them?.isUniquePerson ?? false,
};
default:
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/ChatEvent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
{#if event.event.kind === "message"}
{#if !hidden}
<ChatMessage
sender={$userStore[event.event.sender]}
sender={$userStore.get(event.event.sender)}
senderTyping={client.isTyping($typing, event.event.sender, messageContext)}
{focused}
{observer}
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/ChatList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
$selectedChatId === undefined;
$: chatSummariesListStore = client.chatSummariesListStore;
$: userStore = client.userStore;
$: user = $userStore[$createdUser.userId];
$: user = $userStore.get($createdUser.userId);
$: lowercaseSearch = searchTerm.toLowerCase();
$: showExploreGroups =
($chatListScope.kind === "none" || $chatListScope.kind === "group_chat") &&
Expand Down Expand Up @@ -137,7 +137,7 @@
}
if (chat.kind === "direct_chat") {
const user = $userStore[chat.them.userId];
const user = $userStore.get(chat.them.userId);
if (user !== undefined) {
return (
user.username.toLowerCase().indexOf(lowercaseSearch) >= 0 ||
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/ChatSubtext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
$: userStore = client.userStore;
$: userId = chat.kind === "direct_chat" ? chat.them.userId : "";
$: isBot = $userStore[userId]?.kind === "bot";
$: isSuspended = $userStore[userId]?.suspended ?? false;
$: isBot = $userStore.get(userId)?.kind === "bot";
$: isSuspended = $userStore.get(userId)?.suspended ?? false;
$: subtext = isSuspended ? $_("accountSuspended") : "";
$: checkLastOnline = !isSuspended && !isBot && chat.kind === "direct_chat";
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/components/home/ChatSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
: { muted: 0, unmuted: 0 };
switch (chatSummary.kind) {
case "direct_chat":
const them = $userStore[chatSummary.them.userId];
const them = $userStore.get(chatSummary.them.userId);
return {
name: client.displayName(them),
diamondStatus: them.diamondStatus,
streak: client.getStreak(them.userId),
diamondStatus: them?.diamondStatus ?? "inactive",
streak: client.getStreak(chatSummary.them.userId),
avatarUrl: client.userAvatarUrl(them),
userId: chatSummary.them,
typing: client.getTypingString(
Expand All @@ -94,7 +94,7 @@
eventsTTL: undefined,
video,
private: false,
uniquePerson: them.isUniquePerson,
uniquePerson: them?.isUniquePerson ?? false,
};
default:
return {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/CryptoTransferBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
onMount(() => {
// default the receiver to the other user in a direct chat
if (chat.kind === "direct_chat") {
receiver = $userStore[chat.them.userId];
receiver = $userStore.get(chat.them.userId);
} else if (defaultReceiver !== undefined && defaultReceiver !== $user.userId) {
receiver = $userStore[defaultReceiver];
receiver = $userStore.get(defaultReceiver);
}
});
Expand Down
12 changes: 6 additions & 6 deletions frontend/app/src/components/home/CurrentChatHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$: userId = selectedChatSummary.kind === "direct_chat" ? selectedChatSummary.them.userId : "";
$: isMultiUser =
selectedChatSummary.kind === "group_chat" || selectedChatSummary.kind === "channel";
$: isBot = $userStore[userId]?.kind === "bot";
$: isBot = $userStore.get(userId)?.kind === "bot";
$: hasUserProfile = !isMultiUser && !isBot;
$: selectedChatId = client.selectedChatId;
$: selectedCommunity = client.selectedCommunity;
Expand Down Expand Up @@ -73,11 +73,11 @@
function normaliseChatSummary(_now: number, chatSummary: ChatSummary, typing: TypersByKey) {
switch (chatSummary.kind) {
case "direct_chat":
const them = $userStore[chatSummary.them.userId];
const them = $userStore.get(chatSummary.them.userId);
return {
name: client.displayName(them),
diamondStatus: them.diamondStatus,
streak: client.getStreak(them.userId),
diamondStatus: them?.diamondStatus ?? "inactive",
streak: client.getStreak(chatSummary.them.userId),
avatarUrl: client.userAvatarUrl(them),
userId: chatSummary.them.userId,
typing: client.getTypingString(
Expand All @@ -86,9 +86,9 @@
{ chatId: chatSummary.id },
typing,
),
username: "@" + them.username,
username: them ? "@" + them.username : undefined,
eventsTTL: undefined,
uniquePerson: them.isUniquePerson,
uniquePerson: them?.isUniquePerson ?? false,
};
default:
return {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/CurrentChatMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
client.tryGetNervousSystem(governanceCanisterId)?.submittingProposalsEnabled ?? false;
$: userId = selectedChatSummary.kind === "direct_chat" ? selectedChatSummary.them.userId : "";
$: userStore = client.userStore;
$: isBot = $userStore[userId]?.kind === "bot";
$: isSuspended = $userStore[userId]?.suspended ?? false;
$: isBot = $userStore.get(userId)?.kind === "bot";
$: isSuspended = $userStore.get(userId)?.suspended ?? false;
$: lastState = $rightPanelHistory[$rightPanelHistory.length - 1] ?? { kind: "no_panel" };
$: groupDetailsSelected = lastState.kind === "group_details";
$: pinnedSelected = lastState.kind === "show_pinned";
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/CurrentChatMessages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
{:else if chat.kind === "direct_chat"}
<div class="big-avatar">
<Avatar
url={client.userAvatarUrl($userStore[chat.them.userId])}
url={client.userAvatarUrl($userStore.get(chat.them.userId))}
userId={chat.them.userId}
size={AvatarSize.Large} />
</div>
Expand Down Expand Up @@ -376,7 +376,7 @@
{:else if chat.kind === "direct_chat"}
<div class="big-avatar">
<Avatar
url={client.userAvatarUrl($userStore[chat.them.userId])}
url={client.userAvatarUrl($userStore.get(chat.them.userId))}
userId={chat.them.userId}
size={AvatarSize.Large} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/Markdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
function replaceUserIds(text: string): string {
return text.replace(/@UserId\(([\d\w-]+)\)/g, (match, p1) => {
const u = $userStore[p1];
const u = $userStore.get(p1);
if (u !== undefined) {
return `<profile-link text="${u.username}" user-id="${u.userId}" suppress-links="${suppressLinks}"></profile-link>`;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/MentionPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
(a: UserOrUserGroup, b: UserOrUserGroup) => {
const order = { everyone: 1, user_group: 2, user: 3, bot: 4 };
return order[a.kind] - order[b.kind];
}
},
);
});
Expand Down Expand Up @@ -154,7 +154,7 @@
</div>
{:else}
<Avatar
url={client.userAvatarUrl($userStore[item.userId])}
url={client.userAvatarUrl($userStore.get(item.userId))}
userId={item.userId}
size={AvatarSize.Small} />
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/MessageEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
function formatUserMentions(text: string): string {
return text.replace(/@UserId\(([\d\w-]+)\)/g, (match, p1) => {
const u = $userStore[p1];
const u = $userStore.get(p1);
if (u?.username !== undefined) {
const username = u.username;
return `@${username}`;
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/PrizeWinnerContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
function username(userId: string): string {
return userId === $user.userId
? $_("you")
: `${$userStore[userId]?.username ?? $_("unknown")}`;
: `${$userStore.get(userId)?.username ?? $_("unknown")}`;
}
function zoomToMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
$: message = $_("report.messageReport", {
values: {
username:
$userStore[report.reportedBy]?.username ?? `unknown user (${report.reportedBy}))`,
$userStore.get(report.reportedBy)?.username ??
`unknown user (${report.reportedBy}))`,
timestamp: client.toDatetimeString(new Date(report.timestamp)),
reason: reasons[report.reasonCode],
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/RightPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$: selectedCommunity = client.selectedCommunity;
$: eventsStore = client.eventsStore;
$: userStore = client.userStore;
$: user = $userStore[$currentUser.userId] ?? client.nullUser("unknown");
$: user = $userStore.get($currentUser.userId) ?? client.nullUser("unknown");
$: lastState = $rightPanelHistory[$rightPanelHistory.length - 1] ?? { kind: "no_panel" };
$: modal = !$fullWidth;
$: multiUserChat = selectedChat as Readable<MultiUserChat>;
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/ThreadSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="thread-avatars">
{#each [...threadSummary.participantIds].slice(0, 5) as participantId}
<Avatar
url={client.userAvatarUrl($userStore[participantId])}
url={client.userAvatarUrl($userStore.get(participantId))}
userId={participantId}
size={AvatarSize.Tiny} />
{/each}
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/TipThumbnail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
{#each userTipsList as [userId, amount]}
<div class="avatar">
<Avatar
url={client.userAvatarUrl($userStore[userId])}
url={client.userAvatarUrl($userStore.get(userId))}
{userId}
size={AvatarSize.Tiny} />
</div>
<div class="username">
@{$userStore[userId]?.username}
@{$userStore.get(userId)?.username}
</div>
<div class="amount">
{client.formatTokens(amount, tokenDetails.decimals)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/VideoCallContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<div class="avatars">
{#each [...content.participants].slice(0, 5) as participantId}
<Avatar
url={client.userAvatarUrl($userStore[participantId.userId])}
url={client.userAvatarUrl($userStore.get(participantId.userId))}
userId={participantId.userId}
size={AvatarSize.Small} />
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
{/if}
</td>
<td class="proposed_by"
>{$userStore[correction.proposedBy]?.username ?? correction.proposedBy}</td>
>{$userStore.get(correction.proposedBy)?.username ??
correction.proposedBy}</td>
<td class="proposed_at"
>{client.toDatetimeString(new Date(Number(correction.proposedAt)))}</td>
<td class="action">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
): Record<string, UserSummary> {
return [...members.values()].reduce(
(map, m) => {
const user = allUsers[m.userId];
const user = allUsers.get(m.userId);
if (user !== undefined) {
map[user.userId] = {
...user,
Expand Down
Loading

0 comments on commit 248adda

Please sign in to comment.