2021-07-20 14:15:15 +02:00
|
|
|
import { exists, isArray } from './misc'
|
2019-11-28 11:37:32 +01:00
|
|
|
import { FollowState } from '@shared/models'
|
|
|
|
|
|
|
|
function isFollowStateValid (value: FollowState) {
|
|
|
|
if (!exists(value)) return false
|
|
|
|
|
|
|
|
return value === 'pending' || value === 'accepted'
|
|
|
|
}
|
|
|
|
|
2021-07-20 14:15:15 +02:00
|
|
|
function isRemoteHandleValid (value: string) {
|
|
|
|
if (!exists(value)) return false
|
|
|
|
if (typeof value !== 'string') return false
|
|
|
|
|
|
|
|
return value.includes('@')
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEachUniqueHandleValid (handles: string[]) {
|
|
|
|
return isArray(handles) &&
|
|
|
|
handles.every(handle => {
|
|
|
|
return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:37:32 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-20 14:15:15 +02:00
|
|
|
isFollowStateValid,
|
|
|
|
isRemoteHandleValid,
|
|
|
|
isEachUniqueHandleValid
|
2019-11-28 11:37:32 +01:00
|
|
|
}
|