Skip to content

Commit

Permalink
improving the type structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Jul 28, 2021
1 parent 042de75 commit f80062c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { JWTUserToken, DevToken, CheckSignature } from './signing';
import { TokenManager } from './token_manager';
import {
isFunction,
isOwnUserProperty,
isOwnUserBaseProperty,
addFileToFormData,
chatCodes,
normalizeQuerySort,
Expand Down Expand Up @@ -1349,7 +1349,7 @@ export class StreamChat<
) {
// Remove deleted properties from user objects.
for (const key in this.user) {
if (key in event.user || isOwnUserProperty(key)) {
if (key in event.user || isOwnUserBaseProperty(key)) {
continue;
}

Expand Down
33 changes: 14 additions & 19 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,21 @@ export function isOwnUser<
);
}

/**
* @todo Fix the typescript to ensure all the properties of `OwnUserBase` exist in return statement.
*
* @returns {array} "Own user" specific properties
*/
function getOwnUserBaseProperties(): (keyof OwnUserBase)[] {
return [
'channel_mutes',
'devices',
'mutes',
'total_unread_count',
'unread_channels',
'unread_count',
'invisible',
'roles',
];
}
export function isOwnUserBaseProperty(property: string) {
const ownUserBaseProperties: {
[Property in keyof Required<OwnUserBase>]: boolean;
} = {
channel_mutes: true,
devices: true,
mutes: true,
total_unread_count: true,
unread_channels: true,
unread_count: true,
invisible: true,
roles: true,
};

export function isOwnUserProperty(property: string) {
return (getOwnUserBaseProperties() as string[]).includes(property);
return ownUserBaseProperties[property as keyof OwnUserBase];
}

export function addFileToFormData(
Expand Down

0 comments on commit f80062c

Please sign in to comment.