import { User } from './types/redux' ; import fetch from './utils/fetch' ; function saveUsername ( username ) { window . localStorage . setItem ( 'username' , username ) ; } param username param password param os param browser param environment export async function register ( username , password , os = '' , browser = '' , environment = '' ) { const [ err , user ] = await fetch ( 'register' , { username , password , os , browser , environment , } ) ; if ( err ) { return null ; } saveUsername ( user . username ) ; return user ; } param username param password param os param browser param environment export async function login ( username , password , os = '' , browser = '' , environment = '' ) { const [ err , user ] = await fetch ( 'login' , { username , password , os , browser , environment , } ) ; if ( err ) { return null ; } saveUsername ( user . username ) ; return user ; } param token param os param browser param environment export async function loginByToken ( token , os = '' , browser = '' , environment = '' ) { const [ err , user ] = await fetch ( 'loginByToken' , { token , os , browser , environment , } , { toast : false } ) ; if ( err ) { return null ; } saveUsername ( user . username ) ; return user ; } param os param browser param environment export async function guest ( os = '' , browser = '' , environment = '' ) { const [ err , res ] = await fetch ( 'guest' , { os , browser , environment } ) ; if ( err ) { return null ; } return res ; } param avatar export async function changeAvatar ( avatar ) { const [ error ] = await fetch ( 'changeAvatar' , { avatar } ) ; return ! error ; } param oldPassword param newPassword export async function changePassword ( oldPassword , newPassword ) { const [ error ] = await fetch ( 'changePassword' , { oldPassword , newPassword , } ) ; return ! error ; } param username export async function changeUsername ( username ) { const [ error ] = await fetch ( 'changeUsername' , { username , } ) ; return ! error ; } param groupId param name export async function changeGroupName ( groupId , name ) { const [ error ] = await fetch ( 'changeGroupName' , { groupId , name } ) ; return ! error ; } param groupId param name export async function changeGroupAvatar ( groupId , avatar ) { const [ error ] = await fetch ( 'changeGroupAvatar' , { groupId , avatar } ) ; return ! error ; } param name export async function createGroup ( name ) { const [ , group ] = await fetch ( 'createGroup' , { name } ) ; return group ; } param groupId export async function deleteGroup ( groupId ) { const [ error ] = await fetch ( 'deleteGroup' , { groupId } ) ; return ! error ; } param groupId export async function joinGroup ( groupId ) { const [ , group ] = await fetch ( 'joinGroup' , { groupId } ) ; return group ; } param groupId export async function leaveGroup ( groupId ) { const [ error ] = await fetch ( 'leaveGroup' , { groupId } ) ; return ! error ; } param userId export async function addFriend ( userId ) { const [ , user ] = await fetch < User > ( 'addFriend' , { userId } ) ; return user ; } param userId export async function deleteFriend ( userId ) { const [ err ] = await fetch ( 'deleteFriend' , { userId } ) ; return ! err ; } param linkmanId param existCount export async function getLinkmanHistoryMessages ( linkmanId , existCount ) { const [ , messages ] = await fetch ( 'getLinkmanHistoryMessages' , { linkmanId , existCount } ) ; return messages ; } param existCount export async function getDefaultGroupHistoryMessages ( existCount ) { const [ , messages ] = await fetch ( 'getDefaultGroupHistoryMessages' , { existCount } ) ; return messages ; } param keywords export async function search ( keywords ) { const [ , result ] = await fetch ( 'search' , { keywords } ) ; return result ; } param keywords export async function searchExpression ( keywords ) { const [ , result ] = await fetch ( 'searchExpression' , { keywords } ) ; return result ; } param to param type param content export async function sendMessage ( to , type , content ) { return fetch ( 'sendMessage' , { to , type , content } ) ; } param messageId export async function deleteMessage ( messageId ) { const [ err ] = await fetch ( 'deleteMessage' , { messageId } ) ; return ! err ; } param groupId export async function getGroupOnlineMembers ( groupId ) { const [ , members ] = await fetch ( 'getGroupOnlineMembers' , { groupId } ) ; return members ; } /**
 * 获取默认群组的在线用户列表
 */ export async function getDefaultGroupOnlineMembers ( ) { const [ , members ] = await fetch ( 'getDefaultGroupOnlineMembers' ) ; return members ; } param username export async function sealUser ( username ) { const [ err ] = await fetch ( 'sealUser' , { username } ) ; return ! err ; } param ip export async function sealIp ( ip ) { const [ err ] = await fetch ( 'sealIp' , { ip } ) ; return ! err ; } param userId export async function sealUserOnlineIp ( userId ) { const [ err ] = await fetch ( 'sealUserOnlineIp' , { userId } ) ; return ! err ; } /**
 * 获取封禁用户列表
 */ export async function getSealList ( ) { const [ , sealList ] = await fetch ( 'getSealList' ) ; return sealList ; } param username export async function resetUserPassword ( username ) { const [ , res ] = await fetch ( 'resetUserPassword' , { username } ) ; return res ; } param username param tag export async function setUserTag ( username , tag ) { const [ err ] = await fetch ( 'setUserTag' , { username , tag } ) ; return ! err ; } param userId export async function getUserIps ( userId ) { const [ , res ] = await fetch ( 'getUserIps' , { userId } ) ; return res ; } export async function getUserOnlineStatus ( userId ) { const [ , res ] = await fetch ( 'getUserOnlineStatus' , { userId } ) ; return res && res . isOnline ; } export async function setNotificationToken ( token ) { const [ , res ] = await fetch ( 'setNotificationToken' , { token } , { toast : false } ) ; return res && res . isOK ; }