From 46ae4669ea14385987e957a4d6d287d1d10a4edf Mon Sep 17 00:00:00 2001 From: hide_d Date: Tue, 31 Aug 2021 02:35:50 +0900 Subject: [PATCH] =?UTF-8?q?misc:=20msg=20template=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/js/templates/message.html | 48 -------------------- hwe/ts/msg.ts | 82 +++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 67 deletions(-) delete mode 100644 hwe/js/templates/message.html diff --git a/hwe/js/templates/message.html b/hwe/js/templates/message.html deleted file mode 100644 index efd63516..00000000 --- a/hwe/js/templates/message.html +++ /dev/null @@ -1,48 +0,0 @@ -
-
- <%if(src.icon){ %> - - <%} else {%> - - <%}%> -
-
-
- <%if(!this.option.action && src.id == myGeneralID && now <= last5min && invalidType == 'msg_valid' && !deletable){%> - - <%}%> - <%if(msgType == 'private') {%> - <%if(src.name == generalName){%> - <%e(dest.name)%>:<%dest.nation%> - <%}else{%> - <%e(src.name)%>:<%src.nation%> - <%}%> - <%} else if(msgType == 'national' && src.nation_id == dest.nation_id){%> - <%e(src.name)%> - <%} else if(msgType == 'national' || msgType == 'diplomacy'){%> - <%if(src.nation_id == nationID){%> - <%e(src.name)%><%dest.nation%> - <%}else{%> - <%e(src.name)%>:<%src.nation%> - <%}%> - <%} else {%> - <%e(src.name)%>:<%src.nation%> - <%} %> - <<%e(time)%>> -
-
<%linkifyStr(text)%>
- <%if(this.option && this.option.action) {%> -
- -
<%} %>
\ No newline at end of file diff --git a/hwe/ts/msg.ts b/hwe/ts/msg.ts index 94318fc6..22424d41 100644 --- a/hwe/ts/msg.ts +++ b/hwe/ts/msg.ts @@ -15,7 +15,55 @@ import { isNotNull } from './util/isNotNull'; import { unwrap_any } from './util/unwrap_any'; import { setAxiosXMLHttpRequest } from './util/setAxiosXMLHttpRequest'; import { exportWindow } from './util/exportWindow'; -let messageTemplate: string | undefined; + +const messageTemplate = `
+
+ <%if(src.icon){ %> + + <%} else {%> + + <%}%> +
+
+
+ <%if(!this.option.action && src.id == myGeneralID && now <= last5min && invalidType == 'msg_valid' && !deletable){%> + + <%}%> + <%if(msgType == 'private') {%> + <%if(src.name == generalName){%> + <%e(dest.name)%>:<%dest.nation%> + <%}else{%> + <%e(src.name)%>:<%src.nation%> + <%}%> + <%} else if(msgType == 'national' && src.nation_id == dest.nation_id){%> + <%e(src.name)%> + <%} else if(msgType == 'national' || msgType == 'diplomacy'){%> + <%if(src.nation_id == nationID){%> + <%e(src.name)%><%dest.nation%> + <%}else{%> + <%e(src.name)%>:<%src.nation%> + <%}%> + <%} else {%> + <%e(src.name)%>:<%src.nation%> + <%} %> + <<%e(time)%>> +
+
<%linkifyStr(text)%>
+ <%if(this.option && this.option.action) {%> +
+ +
<%} %>
`; let myGeneralID: number | undefined; //let isChief: boolean | undefined; let lastSequence: number | undefined; @@ -115,21 +163,21 @@ type BasicInfoResponse = { let generalList: Record = {}; -async function responseMessage(msgID: number, responseAct: boolean):Promise { +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 + msgID: msgID, + response: responseAct }) }) }); const result: InvalidResponse = response.data; - if(!result.result){ + if (!result.result) { alert(result.reason); } location.reload(); @@ -271,8 +319,8 @@ function redrawMsg(msgResponse: MsgResponse, addFront: boolean): MsgResponse { } const dest = { - ...(msg.dest??msg.src), - colorType: isBrightColor((msg.dest??msg.src).color) ? 'bright' as const : 'dark' as const, + ...(msg.dest ?? msg.src), + colorType: isBrightColor((msg.dest ?? msg.src).color) ? 'bright' as const : 'dark' as const, }; if (!dest.nation) { @@ -623,32 +671,28 @@ function activateMessageForm() { $(async function ($) { setAxiosXMLHttpRequest(); - //tmp_template.html은 추후 msg.js에 통합될 수 있음 - const getTemplateP = axios('js/templates/message.html?12').then(obj=>{messageTemplate=obj.data}); - //basic_info.json은 세션값에 따라 동적으로 바뀌는 데이터임. const basicInfoP = axios({ url: 'j_basic_info.php', method: 'post', responseType: 'json' - }).then((v)=>registerGlobal(v.data)); + }).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); + responseType: 'json' + }).then(v => v.data); const messageListP = fetchRecentMsg(); + await basicInfoP + const senderList = await senderListP; + refreshMailboxList(senderList); + activateMessageForm(); - void Promise.all([basicInfoP, senderListP]).then(([, senderList])=>{ - refreshMailboxList(senderList); - activateMessageForm(); - }); - - const [messageList, ] = await Promise.all([messageListP, getTemplateP, basicInfoP, senderListP]) + const messageList = await messageListP; redrawMsg(messageList, true); $('.load_old_message').click(function () { const $this = $(this);