myUser getter

This commit is contained in:
Daniel Lugo 2020-06-23 19:14:11 -04:00
parent 9e0271bd98
commit dd97106aae

View file

@ -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')