Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
felicio committed Nov 7, 2024
1 parent 640ffc6 commit 607e723
Show file tree
Hide file tree
Showing 35 changed files with 142 additions and 148 deletions.
8 changes: 1 addition & 7 deletions packages/components/src/tag/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ function Tag(
props: Props & (ButtonProps | DivProps),
ref: Ref<HTMLButtonElement | HTMLDivElement>,
) {
const {
size = '32',
icon,
iconPlacement = 'left',
label,
...rest
} = props
const { size = '32', icon, iconPlacement = 'left', label, ...rest } = props

const iconOnly = Boolean(icon && !label)

Expand Down
2 changes: 1 addition & 1 deletion packages/status-js/src/client/activityCenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ActivityCenter {

public addMessageNotification = (
newMessage: ChatMessage,
referencedMessage?: ChatMessage
referencedMessage?: ChatMessage,
) => {
let isMention: boolean | undefined
let isReply: boolean | undefined
Expand Down
44 changes: 22 additions & 22 deletions packages/status-js/src/client/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Chat {
client: Client,
uuid: string,
type: MessageType.COMMUNITY_CHAT,
description: CommunityChat
description: CommunityChat,
) => {
const id = `${community.publicKey}${uuid}`
const contentTopic = idToContentTopic(id)
Expand Down Expand Up @@ -171,7 +171,7 @@ export class Chat {
}

public onMessage = (
callback: (messages: ChatMessage[]) => void
callback: (messages: ChatMessage[]) => void,
): (() => void) => {
this.messageCallbacks.add(callback)
// todo?: set from ui, think use case without an ui
Expand Down Expand Up @@ -227,7 +227,7 @@ export class Chat {
pageSize: 50,
// most recent page first
pageDirection: PageDirection.BACKWARD,
}
},
)

this.#previousFetchedStartTime = startTime
Expand Down Expand Up @@ -278,7 +278,7 @@ export class Chat {
this.#oldestFetchedMessage = this.getOldestFetchedMessage(
this.#oldestFetchedMessage,
newMessage.messageId,
timestamp
timestamp,
)
}

Expand Down Expand Up @@ -340,7 +340,7 @@ export class Chat {
if (!this.#isActive && !isAuthor) {
this.client.activityCenter.addMessageNotification(
newMessage,
this.#messages.get(newMessage.responseTo)
this.#messages.get(newMessage.responseTo),
)
}
}
Expand All @@ -349,7 +349,7 @@ export class Chat {
messageId: string,
text: string,
clock: bigint,
signerPublicKey: string
signerPublicKey: string,
) => {
const message = this.#messages.get(messageId)

Expand All @@ -374,7 +374,7 @@ export class Chat {
public handleDeletedMessage = (
messageId: string,
clock: bigint,
signerPublicKey: string
signerPublicKey: string,
) => {
const message = this.#messages.get(messageId)
if (message && this.isAuthor(message, signerPublicKey)) {
Expand All @@ -394,7 +394,7 @@ export class Chat {
public handlePinnedMessage = (
messageId: string,
clock: bigint,
pinned?: boolean
pinned?: boolean,
) => {
const message = this.#messages.get(messageId)
if (message) {
Expand All @@ -419,14 +419,14 @@ export class Chat {
messageId: string,
reaction: EmojiReaction,
clock: bigint,
signerPublicKey: string
signerPublicKey: string,
) => {
const message = this.#messages.get(messageId)
if (message) {
const reactions = getReactions(
reaction,
message.reactions,
signerPublicKey
signerPublicKey,
)
message.reactions = reactions

Expand All @@ -447,15 +447,15 @@ export class Chat {
SAD: new Set<string>(),
ANGRY: new Set<string>(),
},
signerPublicKey
signerPublicKey,
)

this.#reactEvents.set(messageId, { clock, reactions })
} else {
const reactions = getReactions(
reaction,
reactEvent.reactions,
signerPublicKey
signerPublicKey,
)

this.#reactEvents.set(messageId, { clock, reactions })
Expand Down Expand Up @@ -489,7 +489,7 @@ export class Chat {
ApplicationMetadataMessage_Type.CHAT_MESSAGE,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

Expand Down Expand Up @@ -518,7 +518,7 @@ export class Chat {
ApplicationMetadataMessage_Type.CHAT_MESSAGE,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

Expand Down Expand Up @@ -554,14 +554,14 @@ export class Chat {
ApplicationMetadataMessage_Type.EDIT_MESSAGE,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

public deleteMessage = async (messageId: string) => {
if (!this.client.account) {
throw new Error(
'Text message cannot be deleted without a created account'
'Text message cannot be deleted without a created account',
)
}

Expand All @@ -587,13 +587,13 @@ export class Chat {
ApplicationMetadataMessage_Type.DELETE_MESSAGE,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

public sendReaction = async (
messageId: string,
reaction: keyof ChatMessage['reactions']
reaction: keyof ChatMessage['reactions'],
) => {
if (!this.client.account) {
throw new Error('Account not initialized')
Expand All @@ -606,7 +606,7 @@ export class Chat {
}

const retracted = message.reactions[reaction].has(
`0x${this.client.account.publicKey}`
`0x${this.client.account.publicKey}`,
)

const payload = new EmojiReaction({
Expand All @@ -623,21 +623,21 @@ export class Chat {
ApplicationMetadataMessage_Type.EMOJI_REACTION,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

public isAuthor = (
message: ChatMessage,
signerPublicKey: string
signerPublicKey: string,
): boolean => {
return message.signer === signerPublicKey
}

private getOldestFetchedMessage(
oldestMessage: FetchedMessage | undefined,
messageId: string,
messageTimestamp?: Date
messageTimestamp?: Date,
): FetchedMessage {
let message: FetchedMessage

Expand Down
6 changes: 3 additions & 3 deletions packages/status-js/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Client {
await waitForRemotePeer(
waku,
[Protocols.Store, Protocols.Filter, Protocols.LightPush],
10 * 1000
10 * 1000,
)

// Client
Expand Down Expand Up @@ -250,7 +250,7 @@ class Client {
type: ApplicationMetadataMessage_Type,
payload: Uint8Array,
contentTopic: string,
symKey: Uint8Array
symKey: Uint8Array,
) => {
if (!this.waku) {
throw new Error('Waku not started')
Expand Down Expand Up @@ -278,7 +278,7 @@ class Client {
shard: 32,
},
}),
{ payload: message }
{ payload: message },
)
}

Expand Down
28 changes: 14 additions & 14 deletions packages/status-js/src/client/community/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Community {
if (this.description) {
return true
}
}
},
)

return this.description
Expand All @@ -120,12 +120,12 @@ export class Community {
shard: 32,
}),
],
this.client.handleWakuMessage
this.client.handleWakuMessage,
)
}

private observeChatMessages = async (
chatDescriptions: CommunityDescription['chats']
chatDescriptions: CommunityDescription['chats'],
) => {
const chatPromises = Object.entries(chatDescriptions).map(
async ([chatUuid, chatDescription]: [string, CommunityChat]) => {
Expand All @@ -134,7 +134,7 @@ export class Community {
this.client,
chatUuid,
MessageType.COMMUNITY_CHAT,
chatDescription
chatDescription,
)

this.chats.set(chatUuid, chat)
Expand All @@ -146,18 +146,18 @@ export class Community {
shard: 32,
}),
],
this.client.handleWakuMessage
this.client.handleWakuMessage,
)

this.#chatUnobserveFns.set(chat.contentTopic, unobserveFn)
}
},
)

await Promise.all(chatPromises)
}

private unobserveChatMessages = (
chatDescription: CommunityDescription['chats']
chatDescription: CommunityDescription['chats'],
) => {
const contentTopics: string[] = []

Expand All @@ -179,7 +179,7 @@ export class Community {
}

contentTopics.forEach(contentTopic =>
this.#chatUnobserveFns.get(contentTopic)?.()
this.#chatUnobserveFns.get(contentTopic)?.(),
)
}

Expand Down Expand Up @@ -207,15 +207,15 @@ export class Community {
// observe
const removedChats = getDifferenceByKeys(
this.description.chats,
description.chats
description.chats,
)
if (Object.keys(removedChats).length) {
this.unobserveChatMessages(removedChats)
}

const addedChats = getDifferenceByKeys(
description.chats,
this.description.chats
this.description.chats,
)
if (Object.keys(addedChats).length) {
this.observeChatMessages(addedChats)
Expand All @@ -232,7 +232,7 @@ export class Community {

const members = getObjectsDifference(
this.description.members,
description.members
description.members,
)

this.addMembers(members.added)
Expand All @@ -251,7 +251,7 @@ export class Community {
// handle
Object.entries(this.description.chats).forEach(
([chatUuid, chatDescription]) =>
this.chats.get(chatUuid)?.handleChange(chatDescription)
this.chats.get(chatUuid)?.handleChange(chatDescription),
)
}

Expand All @@ -275,13 +275,13 @@ export class Community {
ApplicationMetadataMessage_Type.COMMUNITY_REQUEST_TO_JOIN,
payload,
this.contentTopic,
this.symmetricKey
this.symmetricKey,
)
}

public isOwner = (
/** Uncompressed. */
signerPublicKey: string
signerPublicKey: string,
): boolean => {
return this.publicKey === `0x${compressPublicKey(signerPublicKey)}`
}
Expand Down
2 changes: 1 addition & 1 deletion packages/status-js/src/client/community/get-reactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Reactions = {
export function getReactions(
reaction: EmojiReaction,
reactions: Reactions,
publicKey: string
publicKey: string,
): Reactions {
const { type, retracted } = reaction

Expand Down
4 changes: 2 additions & 2 deletions packages/status-js/src/client/community/is-encrypted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
} from '../../protos/communities_pb'

export function isEncrypted(
tokenPermissions: CommunityDescription['tokenPermissions']
tokenPermissions: CommunityDescription['tokenPermissions'],
): boolean {
return Object.values(tokenPermissions).some(
permission =>
permission.type === CommunityTokenPermission_Type.BECOME_MEMBER
permission.type === CommunityTokenPermission_Type.BECOME_MEMBER,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function mapChatMessage(
signerPublicKey: string
community: Community
chat: Chat
}
},
): ChatMessage {
const { messageId, chatUuid, signerPublicKey, community, chat } = props

Expand Down
2 changes: 1 addition & 1 deletion packages/status-js/src/client/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class LocalStorage implements Storage {
try {
window.localStorage.setItem(
this.#getStorageKey(key),
JSON.stringify(value)
JSON.stringify(value),
)
return true
} catch {
Expand Down
Loading

0 comments on commit 607e723

Please # to comment.