From c060e05553f30e90ed57a728351cfce2325ba4df Mon Sep 17 00:00:00 2001 From: Hide_D Date: Wed, 22 Feb 2023 01:29:00 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC=20j=5F=20=EC=BD=94=EB=93=9C=EB=A5=BC=20API?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20-=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=A0=84=EC=86=A1=20-=20=EC=B5=9C=EA=B7=BC=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=8B=A0=20-=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98?= =?UTF-8?q?=EC=8B=A0=20-=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20-=20=EC=97=B0=EB=9D=BD=EC=B2=98=20=EC=88=98?= =?UTF-8?q?=EC=8B=A0=20-=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phan/config.php | 6 - hwe/j_msg_contact_list.php | 19 -- hwe/j_msg_decide_opt.php | 63 ------- hwe/j_msg_delete.php | 74 -------- hwe/j_msg_get_old.php | 120 ------------ hwe/j_msg_get_recent.php | 122 ------------ hwe/j_msg_submit.php | 208 --------------------- hwe/sammo/API/Message/GetOldMessage.php | 8 +- hwe/sammo/API/Message/GetRecentMessage.php | 2 +- hwe/ts/msg.ts | 150 +++++++-------- 10 files changed, 73 insertions(+), 699 deletions(-) delete mode 100644 hwe/j_msg_contact_list.php delete mode 100644 hwe/j_msg_decide_opt.php delete mode 100644 hwe/j_msg_delete.php delete mode 100644 hwe/j_msg_get_old.php delete mode 100644 hwe/j_msg_get_recent.php delete mode 100644 hwe/j_msg_submit.php diff --git a/.phan/config.php b/.phan/config.php index 973c8369..81d2215e 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -98,12 +98,6 @@ return [ 'hwe/j_load_scenarios.php', 'hwe/j_map.php', 'hwe/j_map_recent.php', - 'hwe/j_msg_contact_list.php', - 'hwe/j_msg_decide_opt.php', - 'hwe/j_msg_delete.php', - 'hwe/j_msg_get_old.php', - 'hwe/j_msg_get_recent.php', - 'hwe/j_msg_submit.php', 'hwe/j_myBossInfo.php', 'hwe/j_raise_event.php', 'hwe/j_select_npc.php', diff --git a/hwe/j_msg_contact_list.php b/hwe/j_msg_contact_list.php deleted file mode 100644 index 46c2d0ad..00000000 --- a/hwe/j_msg_contact_list.php +++ /dev/null @@ -1,19 +0,0 @@ -setReadOnly(); - -if(!Session::getInstance()->generalID){ - Json::die([ - "nation"=>[] - ]); -} - -//NOTE: 모든 국가, 모든 장수에 대해서 같은 결과라면 캐싱 가능하지 않을까? - -Json::die([ - "nation"=>getMailboxList() -]); \ No newline at end of file diff --git a/hwe/j_msg_decide_opt.php b/hwe/j_msg_decide_opt.php deleted file mode 100644 index 039f1260..00000000 --- a/hwe/j_msg_decide_opt.php +++ /dev/null @@ -1,63 +0,0 @@ -setReadOnly(); - - -$generalID = Session::getInstance()->generalID; - -if (!$generalID) { - Json::die([ - 'result'=>false, - 'reason'=>'로그인하지 않음' - ]); -} - -$jsonPost = Json::decode(Util::getPost('data', 'string', '{}')); - -$msgID = Util::toInt($jsonPost['msgID']??null); -$msgResponse = $jsonPost['response']??null; - -if ($msgID === null || !is_bool($msgResponse)) { - Json::die([ - 'result'=>false, - 'reason'=>'올바르지 않은 인자' - ]); -} - -$general = DB::db()->queryFirstRow('SELECT `no`, `name`, `nation`, `officer_level`, `npc`, `gold`, `rice`, `troop`, `aux` from `general` where `no` = %i', $generalID); -if(!$general){ - Json::die([ - 'result'=>false, - 'reason'=>'존재하지 않는 장수' - ]); -} - -$msg = Message::getMessageByID($msgID); -if($msg === null){ - Json::die([ - 'result'=>false, - 'reason'=>'올바르지 않은 메시지' - ]); -} -$reason = 'success'; -$gameStor = KVStorage::getStorage(DB::db(), 'game_env'); -$gameStor->cacheAll(); -if($msgResponse){ - $result = $msg->agreeMessage($general['no'], $reason); -} -else{ - $result = $msg->declineMessage($general['no'], $reason); -} - - -Json::die([ - 'result' => $result!==DiplomaticMessage::INVALID, - 'reason' => $reason -]); \ No newline at end of file diff --git a/hwe/j_msg_delete.php b/hwe/j_msg_delete.php deleted file mode 100644 index e65fac43..00000000 --- a/hwe/j_msg_delete.php +++ /dev/null @@ -1,74 +0,0 @@ -false, - 'reason'=>'올바르지 않은 범위 입니다.' - ]); -} - -$lastMsgGet = Json::decode($session->lastMsgGet)??[]; -$now = new \DateTime(); -$delayTime = false; -if(count($lastMsgGet) >= 10){ - try{ - if($lastMsgGet[0] !== 'string'){ - throw new \Exception('Why not string?'); - } - $first = new \DateTime($lastMsgGet[0]); - $diff = $first->diff($now); - if($diff->days == 0 && $diff->h > 0 && $diff->i == 0 && $diff->s <= 5){ - $delayTime = true; - } - array_shift($lastMsgGet); - } - catch(\Exception $e){ - $lastMsgGet = []; - } -} -$lastMsgGet[] = $now; -$session->lastMsgGet = Json::encode($lastMsgGet); - -if($delayTime){ - sleep(1); -} -$session->setReadOnly(); - -list($generalID, $nationID, $generalName) = DB::db()->queryFirstList( - 'select `no`, `nation`, `name` from `general` where owner = %i', - $userID -); - -if($nationID === null){ - Json::die([ - 'result'=>false, - 'reason'=>'장수가 사망했습니다.' - ]); -} - -$reason = Message::deleteMsg($msgID, $generalID); -if($reason === null){ - $result = [ - 'result'=>true, - 'reason'=>'success' - ]; -} -else{ - $result = [ - 'result'=>false, - 'reason'=>$reason - ]; -} - - -Json::die($result); \ No newline at end of file diff --git a/hwe/j_msg_get_old.php b/hwe/j_msg_get_old.php deleted file mode 100644 index 03d9f8ce..00000000 --- a/hwe/j_msg_get_old.php +++ /dev/null @@ -1,120 +0,0 @@ -false, - 'reason'=>'올바르지 않은 범위 입니다.' - ]); -} -if($reqType === null || !in_array($reqType, ['private', 'public', 'national', 'diplomacy'])){ - Json::die([ - 'result'=>false, - 'reason'=>'올바르지 않은 타입입니다.' - ]); -} - -$lastMsgGet = Json::decode($session->lastMsgGet)??[]; -$now = new \DateTime(); -$delayTime = false; -if(count($lastMsgGet) >= 10){ - try{ - if($lastMsgGet[0] !== 'string'){ - throw new \Exception('Why not string?'); - } - $first = new \DateTime($lastMsgGet[0]); - $diff = $first->diff($now); - if($diff->days == 0 && $diff->h > 0 && $diff->i == 0 && $diff->s <= 1){ - $delayTime = true; - } - array_shift($lastMsgGet); - } - catch(\Exception $e){ - $lastMsgGet = []; - } -} -$lastMsgGet[] = $now; -$session->lastMsgGet = Json::encode($lastMsgGet); - -if($delayTime){ - sleep(1); -} -$session->setReadOnly(); - -$me = DB::db()->queryFirstRow('SELECT `no`,`name`,`nation`,`officer_level`,`con`,`picture`,`imgsvr`,penalty,permission FROM general WHERE `owner`=%i', $userID); - -if($me === null){ - Json::die([ - 'result'=>false, - 'reason'=>'장수가 사망했습니다.' - ]); -} - -[$generalID, $nationID, $generalName] = [$me['no'], $me['nation'], $me['name']]; -$permission = checkSecretPermission($me, false); - -$result = [ - 'private'=>[], - 'public'=>[], - 'national'=>[], - 'diplomacy'=>[], - 'result'=>true, - 'keepRecent'=>true, - 'sequence'=>0, - 'nationID'=>$nationID, - 'generalName'=>$generalName, -]; -$result['result'] = true; - -$nextSequence = $reqTo; - -if($reqType == 'private'){ - $result['private'] = array_map(function(Message $msg) use (&$nextSequence){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld($generalID, MessageType::private, $reqTo, 15)); -} -else if($reqType == 'public'){ - $result['public'] = array_map(function(Message $msg)use (&$nextSequence){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_PUBLIC, MessageType::public, $reqTo, 15)); -} -else if($reqType == 'national'){ - $result['national'] = array_map(function(Message $msg)use (&$nextSequence){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, MessageType::national, $reqTo, 15)); -} -else{ - $result['diplomacy'] = array_map(function(Message $msg)use (&$nextSequence, $permission){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - $values = $msg->toArray(); - if($msg->dest->nationID != 0 && $permission < 3){ - $values['text'] = '(외교 메시지입니다)';//TODO: 외교서신이라 읽을 수 없음을 보여줘야함 - $values['option']['invalid'] = true; - } - return $values; - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, MessageType::diplomacy, $reqTo, 15)); -} - -Json::die($result); \ No newline at end of file diff --git a/hwe/j_msg_get_recent.php b/hwe/j_msg_get_recent.php deleted file mode 100644 index 9f6afee3..00000000 --- a/hwe/j_msg_get_recent.php +++ /dev/null @@ -1,122 +0,0 @@ -lastMsgGet)??[]; -$now = new \DateTime(); -$delayTime = false; -if(count($lastMsgGet) >= 10){ - try{ - if(!is_string($lastMsgGet[0])){ - throw new \Exception('Why not string?'); - } - $first = new \DateTime($lastMsgGet[0]); - $diff = $first->diff($now); - if($diff->days == 0 && $diff->h > 0 && $diff->i == 0 && $diff->s <= 1){ - $delayTime = true; - } - array_shift($lastMsgGet); - } - catch(\Exception $e){ - $lastMsgGet = []; - } -} -$lastMsgGet[] = TimeUtil::now(); -$session->lastMsgGet = Json::encode($lastMsgGet); - -if($delayTime){ - usleep(200); -} -$session->setReadOnly(); - - -$db = DB::db(); -$me = $db->queryFirstRow('SELECT `no`,`name`,`nation`,`officer_level`,`con`,`picture`,`imgsvr`,penalty,permission FROM general WHERE `owner`=%i', $userID); - -if($me === null){ - Json::die([ - 'result'=>false, - 'reason'=>'장수가 사망했습니다.' - ]); -} - -[$generalID, $nationID, $generalName] = [$me['no'], $me['nation'], $me['name']]; -$permission = checkSecretPermission($me, false); - -$result = []; -$result['result'] = true; -$result['keepRecent'] = false; -$nextSequence = $reqSequence; -$minSequence = $reqSequence; -$lastType = null; - -$result['private'] = array_map(function(Message $msg) use (&$nextSequence, &$minSequence, &$lastType){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - if($msg->id <= $minSequence){ - $minSequence = $msg->id; - $lastType = 'private'; - } - return $msg->toArray(); -}, Message::getMessagesFromMailBox($generalID, MessageType::private, 15, $reqSequence)); - -$result['public'] = array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - if($msg->id <= $minSequence){ - $minSequence = $msg->id; - $lastType = 'public'; - } - return $msg->toArray(); -}, Message::getMessagesFromMailBox(Message::MAILBOX_PUBLIC, MessageType::public, 15, $reqSequence)); - -$result['national'] = array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - if($msg->id <= $minSequence){ - $minSequence = $msg->id; - $lastType = 'national'; - } - return $msg->toArray(); -}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, MessageType::national, 15, $reqSequence)); - -$result['diplomacy']= array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType, $permission){ - if($msg->id > $nextSequence){ - $nextSequence = $msg->id; - } - if($msg->id <= $minSequence){ - $minSequence = $msg->id; - $lastType = 'diplomacy'; - } - $values = $msg->toArray(); - if($msg->dest->nationID != 0 && $permission < 3){ - $values['text'] = '(외교 메시지입니다)';//TODO: 외교서신이라 읽을 수 없음을 보여줘야함 - $values['option']['invalid'] = true; - } - return $values; -}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, MessageType::diplomacy, 15, $reqSequence)); - -if($lastType !== null){ - array_pop($result[$lastType]); - $result['keepRecent'] = true; -} -else if($reqSequence <= 0){ - $result['keepRecent'] = true; -} - -$result['sequence'] = $nextSequence; -$result['nationID'] = $nationID; -$result['generalName'] = $generalName; -Json::die($result); \ No newline at end of file diff --git a/hwe/j_msg_submit.php b/hwe/j_msg_submit.php deleted file mode 100644 index 0d8d8860..00000000 --- a/hwe/j_msg_submit.php +++ /dev/null @@ -1,208 +0,0 @@ -rule('required', ['mailbox','text']); -$v->rule('integer', 'mailbox'); -$v->rule('lengthMin', 'text', 1); - -if(!$v->validate()){ - Json::die([ - 'result'=>false, - 'reason'=>$v->errorStr(), - 'msgID'=>null - ]); -} - -$mailbox = (int)$post['mailbox']; -$text = trim(StringUtil::cutStringForWidth($post['text'], 199, '')); - -$session = Session::requireGameLogin([ - 'msgID'=>null -]); -$userID = Session::getUserID(); -//NOTE: 전송 메시지 시간 계산을 위해 Session을 쓰기 가능 상태로 열어둠. - -increaseRefresh('서신전달', 1); - -if(getBlockLevel() == 1 || getBlockLevel() == 3) { - Json::die([ - 'result' => false, - 'reason' => '차단되었습니다.', - 'msgID'=>null - ]); -} - -/** - * 메시지 전송 코드. - * - * TODO: 장기적으로 ajax는 한곳에 모을 필요가 있을 듯. - */ - -$now = new \DateTime(); -$unlimited = new \DateTime('9999-12-31'); - -$db = DB::db(); -$me = $db->queryFirstRow('SELECT `no`,`name`,`nation`,`officer_level`,`con`,`picture`,`imgsvr`,penalty,permission,belong FROM general WHERE `owner`=%i', $userID); - -if(!$me){ - $session->logoutGame(); - Json::die([ - 'result' => false, - 'reason' => '로그인되지 않았습니다.', - 'msgID' => null - ]); -} - -$con = checkLimit($me['con']); -if($con >= 2) { - Json::die([ - 'result' => false, - 'reason' => '접속 제한입니다.', - 'msgID' => null - ]); - } - -$me['icon'] = GetImageURL($me['imgsvr'], $me['picture']); -$permission = checkSecretPermission($me); -$srcNation = getNationStaticInfo($me['nation']); - -$src = new MessageTarget($me['no'], $me['name'], $srcNation['nation'], $srcNation['name'], $srcNation['color'], $me['icon']); - -// 전체 메세지 -if($mailbox == Message::MAILBOX_PUBLIC) { - $msg = new Message( - MessageType::public, - $src, - $src, - $text, - $now, - $unlimited, - [] - ); - $msgID = $msg->send(); - Json::die([ - 'result' => true, - 'reason' => 'SUCCESS', - 'msgID' => $msgID - ]); - - -} - -// 국가 메세지 -if($mailbox >= Message::MAILBOX_NATIONAL) { - - if($permission < 4){ - $destNationID = $me['nation']; - } - else{ - $destNationID = $mailbox - Message::MAILBOX_NATIONAL; - } - - if($destNationID == $me['nation']){ - $msgType = MessageType::national; - } - else{ - $msgType = MessageType::diplomacy; - } - - $destNation = getNationStaticInfo($destNationID); - - $dest = new MessageTarget(0, '', $destNation['nation'], $destNation['name'], $destNation['color']); - - $msg = new Message( - $msgType, - $src, - $dest, - $text, - $now, - $unlimited, - [] - ); - $msgID = $msg->send(); - Json::die([ - 'result' => true, - 'reason' => 'SUCCESS', - 'msgID' => $msgID - ]); -} - -// 개인 메세지 -if($mailbox > 0) { - $lastMsg = new \DateTime($session->lastMsg??'0000-00-00'); - - $msg_interval = $now->getTimestamp() - $lastMsg->getTimestamp(); - //NOTE: 여기서 유저 레벨을 구별할 코드가 필요할까? - if($msg_interval < 2){ - Json::die([ - 'result' => false, - 'reason' => '개인메세지는 2초당 1건만 보낼 수 있습니다!', - 'msgID' => null - ]); - } - - $session->lastMsg = $now->format('Y-m-d H:i:s'); - - $destUser = $db->queryFirstRow('SELECT `no`,`name`,`nation`,`officer_level`,`con`,`picture`,`imgsvr`,permission,penalty FROM general WHERE `no`=%i',$mailbox); - - if(!$destUser){ - Json::die([ - 'result' => false, - 'reason' => '존재하지 않는 유저입니다.', - 'msgID' => null - ]); - } - - $destPermission = checkSecretPermission($destUser, false); - if($permission == 4 && $destPermission == 4 && $destUser['nation'] != $me['nation']){ - Json::die([ - 'result' => false, - 'reason' => '외교권자끼리는 메시지를 보낼 수 없습니다.', - 'msgID' => null - ]); - } - - $destNation = getNationStaticInfo($destUser['nation']); - - $dest = new MessageTarget( - $destUser['no'], - $destUser['name'], - $destNation['nation'], - $destNation['name'], - $destNation['color'], - GetImageURL($destUser['imgsvr'], $destUser['picture']) - ); - - $msg = new Message( - MessageType::private, - $src, - $dest, - $text, - $now, - $unlimited, - [] - ); - $msgID = $msg->send(); - Json::die([ - 'result' => true, - 'reason' => 'SUCCESS', - 'msgID' => $msgID - ]); -} - -Json::die([ - 'result' => false, - 'reason' => '알 수 없는 에러', - 'msgID' => null -]); diff --git a/hwe/sammo/API/Message/GetOldMessage.php b/hwe/sammo/API/Message/GetOldMessage.php index 36bbe2a2..36f38f30 100644 --- a/hwe/sammo/API/Message/GetOldMessage.php +++ b/hwe/sammo/API/Message/GetOldMessage.php @@ -20,10 +20,10 @@ class GetOldMessage extends \sammo\BaseAPI { $v = new Validator($this->args); $v->rule('required', [ - 'sequence', + 'to', 'type', - ])->rule('int', 'to') - ->rule('string', 'type'); + ])->rule('integer', 'to') + ->rule('in', 'type', ['private', 'public', 'national', 'diplomacy']); if (!$v->validate()) { return $v->errorStr(); } @@ -82,7 +82,7 @@ class GetOldMessage extends \sammo\BaseAPI [$generalID, $nationID, $generalName] = [$me['no'], $me['nation'], $me['name']]; $permission = checkSecretPermission($me, false); - $reqTo = $this->args['reqTo']; + $reqTo = $this->args['to']; $result = [ MessageType::private->value => [], diff --git a/hwe/sammo/API/Message/GetRecentMessage.php b/hwe/sammo/API/Message/GetRecentMessage.php index ca037df9..815ba283 100644 --- a/hwe/sammo/API/Message/GetRecentMessage.php +++ b/hwe/sammo/API/Message/GetRecentMessage.php @@ -19,7 +19,7 @@ class GetRecentMessage extends \sammo\BaseAPI public function validateArgs(): ?string { $v = new Validator($this->args); - $v->rule('int', 'sequence'); + $v->rule('integer', 'sequence'); if (!$v->validate()) { return $v->errorStr(); } diff --git a/hwe/ts/msg.ts b/hwe/ts/msg.ts index 85ff9193..f8ef59a4 100644 --- a/hwe/ts/msg.ts +++ b/hwe/ts/msg.ts @@ -6,7 +6,7 @@ import axios from 'axios'; import { convertFormData } from '@util/convertFormData'; import { isBrightColor } from "@util/isBrightColor"; import { unwrap } from '@util/unwrap'; -import _ from 'lodash-es'; +import _, { isError, isString } from 'lodash-es'; import { addMinutes } from 'date-fns'; import { parseTime } from '@util/parseTime'; import { formatTime } from '@util/formatTime'; @@ -15,6 +15,7 @@ import { isNotNull } from '@util/isNotNull'; import { unwrap_any } from '@util/unwrap_any'; import { setAxiosXMLHttpRequest } from '@util/setAxiosXMLHttpRequest'; import { exportWindow } from '@util/exportWindow'; +import { SammoAPI } from './SammoAPI'; const messageTemplate = `
= {}; async function responseMessage(msgID: number, responseAct: boolean): Promise { - const response = await axios({ - url: 'j_msg_decide_opt.php', - method: 'post', - responseType: 'json', - data: convertFormData({ - data: JSON.stringify({ - msgID: msgID, - response: responseAct - }) - }) - }); - - const result: InvalidResponse = response.data; - if (!result.result) { - alert(result.reason); + try{ + await SammoAPI.Message.DecideMessageResponse({msgID, response: responseAct}); + location.reload(); + } + catch(e){ + if(isString(e)){ + alert(e); + } + if(isError(e)){ + alert(e.message); + } + console.error(e); } - location.reload(); } async function deleteMessage(msgID: number): Promise { - const response = await axios({ - url: 'j_msg_delete.php', - method: 'post', - responseType: 'json', - data: convertFormData({ - msgID: msgID, - }) - }); - const result: InvalidResponse | MsgResponse = response.data; - if (!result.result) { - throw result.reason; + try{ + await SammoAPI.Message.DeleteMessage({msgID}); + } + catch(e){ + if(isString(e)){ + alert(e); + } + if(isError(e)){ + alert(e.message); + } + console.error(e); } return await refreshMsg(); } @@ -206,37 +203,34 @@ export async function refreshMsg(): Promise { exportWindow(refreshMsg, 'refreshMsg'); async function fetchRecentMsg(): Promise { - const response = await axios({ - url: 'j_msg_get_recent.php', - method: 'post', - responseType: 'json', - data: convertFormData({ - sequence: lastSequence ?? 0 - }) - }); - const result: InvalidResponse | MsgResponse = response.data; - if (!result.result) { - throw result.reason; + try { + console.log(lastSequence); + return await SammoAPI.Message.GetRecentMessage({sequence: lastSequence ?? -1}); + } + catch (e) { + console.error(e); + throw e; } - return result; } async function showOldMsg(msgType: MsgType): Promise { - const response = await axios({ - url: 'j_msg_get_old.php', - responseType: 'json', - method: 'post', - data: convertFormData({ - to: minMsgSeq[msgType], + try{ + const response = await SammoAPI.Message.GetOldMessage({ type: msgType, - }) - }); - const result: InvalidResponse | MsgResponse = response.data; - if (!result.result) { - throw result.reason; + to: minMsgSeq[msgType], + }); + return redrawMsg(response, false); + } + catch(e){ + if(isString(e)){ + alert(e); + } + if(isError(e)){ + alert(e.message); + } + console.error(e); + throw e; } - - return redrawMsg(result, false); } function redrawMsg(msgResponse: MsgResponse, addFront: boolean): MsgResponse { @@ -419,26 +413,26 @@ function redrawMsg(msgResponse: MsgResponse, addFront: boolean): MsgResponse { return null; } - $msg.find('.btn-delete-msg').click(function () { + $msg.find('.btn-delete-msg').on('click', async function () { if (!confirm("삭제하시겠습니까?")) { return false; } - void deleteMessage(msg.id); + await deleteMessage(msg.id); }); - $msg.find('button.prompt_yes').click(function () { + $msg.find('button.prompt_yes').on('click', async function () { if (!confirm("수락하시겠습니까?")) { return false; } - void responseMessage(msg.id, true); + await responseMessage(msg.id, true); }); - $msg.find('button.prompt_no').click(function () { + $msg.find('button.prompt_no').on('click', async function () { if (!confirm("거절하시겠습니까?")) { return false; } - void responseMessage(msg.id, false); + await responseMessage(msg.id, false); }); if ($existMsg.length) { @@ -641,30 +635,26 @@ function activateMessageForm() { } }); - $msgSubmit.click(async function () { + $msgSubmit.on('click', async function () { - const text = $.trim(unwrap_any($msgInput.val())); - $msgInput.val('').focus(); + const text = _.trim(unwrap_any($msgInput.val())); + $msgInput.val('').trigger('focus'); const targetMailbox = unwrap_any($mailboxList.val()); console.log(targetMailbox, text); - const response = await axios({ - url: 'j_msg_submit.php', - method: 'post', - responseType: 'json', - data: convertFormData({ - data: JSON.stringify({ - mailbox: parseInt(targetMailbox), - text: text - }) - }) - }) - const result: InvalidResponse = response.data; - if (!result.result) { - alert(result.reason); + try{ + await SammoAPI.Message.SendMessage({ + mailbox: parseInt(targetMailbox), + text, + }); + await refreshMsg(); + } + catch(e){ + alert(e); + await refreshMsg(); + return; } - await refreshMsg(); }); } @@ -679,11 +669,7 @@ $(async function ($) { }).then((v) => registerGlobal(v.data)); //sender_list.json 은 서버측에선 캐시 가능한 데이터임. - const senderListP = axios({ - url: 'j_msg_contact_list.php', - method: 'post', - responseType: 'json' - }).then(v => v.data); + const senderListP = SammoAPI.Message.GetContactList(); const messageListP = fetchRecentMsg();