myUser getter
This commit is contained in:
parent
9e0271bd98
commit
dd97106aae
1 changed files with 49 additions and 0 deletions
|
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
* @format
|
||||
*/
|
||||
const Common = require('shock-common')
|
||||
|
||||
const Key = require('../key')
|
||||
const Utils = require('../utils')
|
||||
|
||||
|
|
@ -39,4 +41,51 @@ exports.userToIncomingID = async pub => {
|
|||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Common.SchemaTypes.User>}
|
||||
*/
|
||||
const getMyUser = async () => {
|
||||
const oldProfile = await Utils.tryAndWait(
|
||||
(_, user) => new Promise(res => user.get(Key.PROFILE).load(res)),
|
||||
v => typeof v !== 'object'
|
||||
)
|
||||
|
||||
const bio = await Utils.tryAndWait(
|
||||
(_, user) => user.get(Key.BIO).then(),
|
||||
v => typeof v !== 'string'
|
||||
)
|
||||
|
||||
const lastSeenApp = await Utils.tryAndWait(
|
||||
(_, user) => user.get(Key.LAST_SEEN_APP).then(),
|
||||
v => typeof v !== 'number'
|
||||
)
|
||||
|
||||
const lastSeenNode = await Utils.tryAndWait(
|
||||
(_, user) => user.get(Key.LAST_SEEN_NODE).then(),
|
||||
v => typeof v !== 'number'
|
||||
)
|
||||
|
||||
const publicKey = await Utils.tryAndWait(
|
||||
(_, user) => Promise.resolve(user.is && user.is.pub),
|
||||
v => typeof v !== 'string'
|
||||
)
|
||||
|
||||
/** @type {Common.SchemaTypes.User} */
|
||||
const u = {
|
||||
avatar: oldProfile.avatar,
|
||||
// @ts-ignore
|
||||
bio,
|
||||
displayName: oldProfile.displayName,
|
||||
// @ts-ignore
|
||||
lastSeenApp,
|
||||
// @ts-ignore
|
||||
lastSeenNode,
|
||||
// @ts-ignore
|
||||
publicKey
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
module.exports.getMyUser = getMyUser
|
||||
module.exports.Follows = require('./follows')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue