Skip to content

Commit

Permalink
updates from master
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs committed Aug 5, 2024
1 parent 1f5aabc commit 2e61339
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
15 changes: 3 additions & 12 deletions frontend/openchat-agent/src/services/community/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import type {
UpdatedEvent,
UpdateUserGroupResponse,
UserFailedError,
UserFailedGateCheck,
UserGroupDetails,
} from "openchat-shared";
import { CommonResponses, UnsupportedValueError } from "openchat-shared";
Expand All @@ -54,7 +53,6 @@ import type {
ApiOptionalCommunityPermissions,
ApiAddMembersToChannelFailed,
ApiAddMembersToChannelPartialSuccess,
ApiUserFailedGateCheck,
ApiUserFailedError,
ApiMessageMatch,
ApiCommunityCanisterCommunitySummaryUpdates,
Expand Down Expand Up @@ -83,7 +81,6 @@ import {
communityChannelSummary,
communityPermissions,
communitySummary,
gateCheckFailedReason,
groupPermissions,
groupSubtype,
memberRole,
Expand Down Expand Up @@ -136,6 +133,9 @@ export function addMembersToChannelResponse(
if ("InternalError" in candid) {
return CommonResponses.internalError();
}
if ("CommunityPublic" in candid) {
return CommonResponses.communityPublic();
}
throw new UnsupportedValueError(
"Unexpected ApiAddMembersToChannelResponse type received",
candid,
Expand All @@ -147,7 +147,6 @@ function addToChannelFailed(candid: ApiAddMembersToChannelFailed): AddMembersToC
kind: "add_to_channel_failed",
usersLimitReached: candid.users_limit_reached.map((u) => u.toString()),
usersAlreadyInChannel: candid.users_already_in_channel.map((u) => u.toString()),
usersFailedGateCheck: candid.users_failed_gate_check.map(userFailedGateCheck),
usersFailedWithError: candid.users_failed_with_error.map(userFailedWithError),
};
}
Expand All @@ -159,21 +158,13 @@ function userFailedWithError(candid: ApiUserFailedError): UserFailedError {
};
}

function userFailedGateCheck(candid: ApiUserFailedGateCheck): UserFailedGateCheck {
return {
userId: candid.user_id.toString(),
reason: gateCheckFailedReason(candid.reason),
};
}

function addToChannelPartialSuccess(
candid: ApiAddMembersToChannelPartialSuccess,
): AddMembersToChannelResponse {
return {
kind: "add_to_channel_partial_success",
usersLimitReached: candid.users_limit_reached.map((u) => u.toString()),
usersAlreadyInChannel: candid.users_already_in_channel.map((u) => u.toString()),
usersFailedGateCheck: candid.users_failed_gate_check.map(userFailedGateCheck),
usersFailedWithError: candid.users_failed_with_error.map(userFailedWithError),
usersAdded: candid.users_added.map((u) => u.toString()),
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/openchat-agent/src/services/user/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ export function achievementType(candid: ApiAchievement): Achievement {
if ("Streak7" in candid) {
return "streak_7";
}
if ("Streak365" in candid) {
return "streak_365";
}
if ("UpgradedToGoldDiamond" in candid) {
return "upgrade_to_gold_diamond";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ export class UserIndexClient extends CandidService {
const allUsers = users.userGroups.flatMap((g) => g.users);

const fromCache = await getCachedUsers(allUsers);
const deletedUserIds = await getCachedDeletedUserIds();
const cachedDeletedUserIds = await getCachedDeletedUserIds();
const suspendedUsersSyncedTo = await getSuspendedUsersSyncedUpTo();

// We throw away all of the updatedSince values passed in and instead use the values from the cache, this
// ensures the cache is always correct and doesn't miss any updates
const args = this.buildGetUsersArgs(allUsers, fromCache, allowStale, deletedUserIds);
const args = this.buildGetUsersArgs(allUsers, fromCache, allowStale, cachedDeletedUserIds);

const requestedFromServer = new Set<string>([...args.userGroups.flatMap((g) => g.users)]);

Expand Down Expand Up @@ -217,7 +217,7 @@ export class UserIndexClient extends CandidService {
users: string[],
fromCache: UserSummary[],
allowStale: boolean,
deletedUserIds: Set<string>,
cachedDeletedUserIds: Set<string>,
): UsersArgs {
const fromCacheGrouped = groupBy(fromCache, (u) => u.updated);
const fromCacheSet = new Set<string>(fromCache.map((u) => u.userId));
Expand All @@ -227,7 +227,9 @@ export class UserIndexClient extends CandidService {
};

// Add the users not found in the cache and ask for all updates
const notFoundInCache = users.filter((u) => !fromCacheSet.has(u) && !deletedUserIds.has(u));
const notFoundInCache = users.filter(
(u) => !fromCacheSet.has(u) && !cachedDeletedUserIds.has(u),
);
if (notFoundInCache.length > 0) {
args.userGroups.push({
users: notFoundInCache,
Expand All @@ -239,7 +241,9 @@ export class UserIndexClient extends CandidService {
// Add the users found in the cache but only ask for updates since the date they were last updated in the cache
for (const [updatedSince, users] of fromCacheGrouped) {
args.userGroups.push({
users: users.filter((u) => !deletedUserIds.has(u.userId)).map((u) => u.userId),
users: users
.filter((u) => !cachedDeletedUserIds.has(u.userId))
.map((u) => u.userId),
updatedSince,
});
}
Expand Down
1 change: 1 addition & 0 deletions frontend/openchat-shared/src/domain/chit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const achievements = [
"streak_7",
"streak_14",
"streak_30",
"streak_365",
"sent_reminder",
"proved_unique_personhood",
"pinned_message",
Expand Down
6 changes: 3 additions & 3 deletions frontend/openchat-shared/src/domain/community/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
import type {
ChatNotFound,
CommunityFrozen,
CommunityPublic,
Failure,
InternalError,
NotAuthorised,
Expand Down Expand Up @@ -104,14 +105,12 @@ export interface UserFailedError {
export type AddMembersToChannelFailed = {
kind: "add_to_channel_failed";
usersLimitReached: string[];
usersFailedGateCheck: UserFailedGateCheck[];
usersAlreadyInChannel: string[];
usersFailedWithError: UserFailedError[];
};
export interface AddMembersToChannelPartialSuccess {
kind: "add_to_channel_partial_success";
usersLimitReached: string[];
usersFailedGateCheck: UserFailedGateCheck[];
usersAlreadyInChannel: string[];
usersFailedWithError: UserFailedError[];
usersAdded: string[];
Expand All @@ -128,7 +127,8 @@ export type AddMembersToChannelResponse =
| UserSuspended
| CommunityFrozen
| InternalError
| Offline;
| Offline
| CommunityPublic;

export type BlockCommunityUserResponse = Success | Failure | Offline;

Expand Down
2 changes: 2 additions & 0 deletions frontend/openchat-shared/src/domain/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type UserNotInCommunity = { kind: "user_not_in_community" };
export type CommunityFrozen = { kind: "community_frozen" };
export type ChatFrozen = { kind: "chat_frozen" };
export type CommunityNotPublic = { kind: "community_not_public" };
export type CommunityPublic = { kind: "community_public" };
export type MessageNotFound = {
kind: "message_not_found";
};
Expand Down Expand Up @@ -77,6 +78,7 @@ export const CommonResponses = {
offline: (): Offline => ({ kind: "offline" }) as Offline,
blocked: (): Blocked => ({ kind: "blocked" }) as Blocked,
userNotFound: (): UserNotFound => ({ kind: "unknown_user" }),
communityPublic: (): CommunityPublic => ({ kind: "community_public" }),
};

export type Blocked = {
Expand Down

0 comments on commit 2e61339

Please sign in to comment.