forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team-building.tsx
123 lines (109 loc) · 3.49 KB
/
team-building.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import logger from '../logger'
import * as I from 'immutable'
import * as Types from './types/team-building'
import * as RPCTypes from './types/rpc-gen'
const allServices: Array<Types.ServiceIdWithContact> = [
'keybase',
'contact',
'twitter',
'facebook',
'github',
'reddit',
'hackernews',
'pgp',
]
// We don't search pgp explicitly, and contact isn't implemented yet
const services: Array<Types.ServiceIdWithContact> = allServices.filter(s => s !== 'contact' && s !== 'pgp')
function isKeybaseUserId(userId: string) {
// Only keybase user id's do not have
return userId.indexOf('@') < 0
}
function followStateHelperWithId(
me: string,
followingState: I.Set<string>,
userId: string = ''
): Types.FollowingState {
if (isKeybaseUserId(userId)) {
if (userId === me) {
return 'You'
} else {
return followingState.has(userId) ? 'Following' : 'NotFollowing'
}
}
return 'NoState'
}
const SubStateFactory = I.Record<Types._TeamBuildingSubState>({
teamBuildingFinishedSelectedRole: 'writer',
teamBuildingFinishedSendNotification: true,
teamBuildingFinishedTeam: I.Set(),
teamBuildingSearchLimit: 11,
teamBuildingSearchQuery: '',
teamBuildingSearchResults: I.Map(),
teamBuildingSelectedRole: 'writer',
teamBuildingSelectedService: 'keybase',
teamBuildingSendNotification: true,
teamBuildingServiceResultCount: I.Map(),
teamBuildingTeamSoFar: I.Set(),
teamBuildingUserRecs: null,
})
const makeSubState = (): Types.TeamBuildingSubState => SubStateFactory()
const parseRawResultToUser = (
result: RPCTypes.APIUserSearchResult,
service: Types.ServiceIdWithContact
): Types.User | null => {
const serviceMap = Object.keys(result.servicesSummary || {}).reduce<{[key: string]: string}>(
(acc, service_name) => {
acc[service_name] = result.servicesSummary[service_name].username
return acc
},
{}
)
// Add the keybase service to the service map since it isn't there by default
if (result.keybase) {
serviceMap['keybase'] = result.keybase.username
}
if (service === 'keybase' && result.keybase) {
return {
id: result.keybase.username,
prettyName: result.keybase.fullName || result.keybase.username,
serviceMap,
}
} else if (service === 'keybase' && result.contact) {
return {
id: result.contact.assertion,
label: result.contact.displayLabel,
prettyName: result.contact.displayName,
serviceMap: {...serviceMap, keybase: result.contact.username},
}
} else if (result.imptofu) {
return {
id: result.imptofu.assertion,
label: result.imptofu.label,
prettyName: result.imptofu.prettyName,
serviceMap: {...serviceMap, keybase: result.imptofu.keybaseUsername},
}
} else if (result.service) {
if (result.service.serviceName !== service) {
// This shouldn't happen
logger.error(
`Search result's service_name is different than given service name. Expected: ${service} received ${
result.service.serviceName
}`
)
return null
}
const kbPrettyName = result.keybase && (result.keybase.fullName || result.keybase.username)
const prettyName = result.service.fullName || kbPrettyName || ``
const id = result.keybase
? result.keybase.username
: `${result.service.username}@${result.service.serviceName}`
return {
id,
prettyName,
serviceMap,
}
} else {
return null
}
}
export {followStateHelperWithId, makeSubState, allServices, services, parseRawResultToUser}