-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from xmtp/break-up-utils
- Loading branch information
Showing
8 changed files
with
62 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Long from 'long' | ||
|
||
export function dateToNs(date: Date): Long { | ||
return Long.fromNumber(date.valueOf()).multiply(1_000_000) | ||
} | ||
|
||
export function nsToDate(ns: Long): Date { | ||
return new Date(ns.divide(1_000_000).toNumber()) | ||
} | ||
|
||
export const toNanoString = (d: Date | undefined): undefined | string => { | ||
return d && dateToNs(d).toString() | ||
} | ||
|
||
export const fromNanoString = (s: string | undefined): undefined | Date => { | ||
if (!s) { | ||
return undefined | ||
} | ||
return nsToDate(Long.fromString(s)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './topic' | ||
export * from './async' | ||
export * from './date' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const buildContentTopic = (name: string): string => | ||
`/xmtp/0/${name}/proto` | ||
|
||
export const buildDirectMessageTopic = ( | ||
sender: string, | ||
recipient: string | ||
): string => { | ||
const members = [sender, recipient] | ||
members.sort() | ||
return buildContentTopic(`dm-${members.join('-')}`) | ||
} | ||
|
||
export const buildDirectMessageTopicV2 = (randomString: string): string => { | ||
return buildContentTopic(`m-${randomString}`) | ||
} | ||
|
||
export const buildUserContactTopic = (walletAddr: string): string => { | ||
return buildContentTopic(`contact-${walletAddr}`) | ||
} | ||
|
||
export const buildUserIntroTopic = (walletAddr: string): string => { | ||
return buildContentTopic(`intro-${walletAddr}`) | ||
} | ||
|
||
export const buildUserInviteTopic = (walletAddr: string): string => { | ||
return buildContentTopic(`invite-${walletAddr}`) | ||
} | ||
export const buildUserPrivateStoreTopic = (walletAddr: string): string => { | ||
return buildContentTopic(`privatestore-${walletAddr}`) | ||
} |