메시지 삭제 기능 추가
This commit is contained in:
@@ -87,6 +87,7 @@
|
||||
font-weight: bold;
|
||||
margin-bottom:3px;
|
||||
color:white;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.message_input_form{
|
||||
@@ -141,6 +142,10 @@
|
||||
height: 1.2em;
|
||||
}
|
||||
|
||||
.msg_invalid{
|
||||
color:rgba(255,255,255,0.5);
|
||||
}
|
||||
|
||||
.msg_body{
|
||||
padding-left:64px;
|
||||
}
|
||||
@@ -153,6 +158,14 @@
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.btn-delete-msg{
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
margin:2px 2px 0 2px;
|
||||
font-size:8px;
|
||||
}
|
||||
|
||||
/*
|
||||
.public_message .msg_target{
|
||||
box-shadow: 2px 2px darkslategrey;
|
||||
|
||||
@@ -88,6 +88,7 @@ $mapTheme = $admin['map_theme'];
|
||||
<?=WebUtil::printJS('../e_lib/jquery-3.3.1.min.js')?>
|
||||
<?=WebUtil::printJS('../e_lib/jquery.redirect.js')?>
|
||||
<?=WebUtil::printJS('../e_lib/bootstrap.bundle.min.js')?>
|
||||
<?=WebUtil::printJS('../e_lib/moment.min.js')?>
|
||||
<?=WebUtil::printJS('../d_shared/common_path.js')?>
|
||||
<?=WebUtil::printJS('js/common.js')?>
|
||||
<?=WebUtil::printJS('js/main.js')?>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include('lib.php');
|
||||
include('func.php');
|
||||
|
||||
$session = Session::requireGameLogin([]);
|
||||
$userID = Session::getUserID();
|
||||
|
||||
$msgID = Util::getReq('msgID', 'int');
|
||||
if($msgID === null){
|
||||
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 <= 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);
|
||||
@@ -10,7 +10,7 @@ $userID = Session::getUserID();
|
||||
$reqTo = Util::getReq('to', 'int');
|
||||
$reqType = Util::getReq('type', 'string');
|
||||
|
||||
if(!$reqTo === null){
|
||||
if($reqTo === null){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 범위 입니다.'
|
||||
|
||||
+66
-4
@@ -47,6 +47,17 @@ function responseMessage(msgID, response){
|
||||
}).then(refreshMsg);
|
||||
}
|
||||
|
||||
function deleteMessage(msgID){
|
||||
$.ajax({
|
||||
url: 'j_msg_delete.php',
|
||||
type: 'post',
|
||||
dataType:'json',
|
||||
data: {
|
||||
msgID:msgID
|
||||
}
|
||||
}).then(refreshMsg);
|
||||
}
|
||||
|
||||
function refreshMsg(result){
|
||||
if(result && !result.result){
|
||||
alert(result.reason);
|
||||
@@ -79,6 +90,18 @@ function showOldMsg(msgType){
|
||||
}
|
||||
|
||||
function redrawMsg(deferred, addFront){
|
||||
function checkErasable(obj){
|
||||
|
||||
var now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
$('.btn-delete-msg').each(function(){
|
||||
var $btn = $(this);
|
||||
var eraseUntil = $btn.data('erase_until');
|
||||
if(eraseUntil < now){
|
||||
$btn.detach();
|
||||
}
|
||||
})
|
||||
return obj;
|
||||
}
|
||||
function checkClear(obj){
|
||||
if(!obj.result){
|
||||
var t = $.Deferred();
|
||||
@@ -167,6 +190,7 @@ function redrawMsg(deferred, addFront){
|
||||
|
||||
var needRefreshLastContact = (msgType == 'private');
|
||||
|
||||
var now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||
//list의 맨 앞이 가장 최신 메시지임.
|
||||
var $msgs = msgSource.map(function(msg){
|
||||
|
||||
@@ -199,6 +223,15 @@ function redrawMsg(deferred, addFront){
|
||||
else{
|
||||
msg.allowButton = true;
|
||||
}
|
||||
msg.myGeneralID = myGeneralID;
|
||||
msg.last5min = moment(msg.time).add(5, 'minute').format('YYYY-MM-DD HH:mm:ss');
|
||||
msg.now = now;
|
||||
if(msg.option && msg.option.invalid){
|
||||
msg.invalidType = 'msg_invalid';
|
||||
}
|
||||
else{
|
||||
msg.invalidType = 'msg_valid';
|
||||
}
|
||||
var msgHtml = TemplateEngine(messageTemplate, msg);
|
||||
|
||||
|
||||
@@ -212,11 +245,39 @@ function redrawMsg(deferred, addFront){
|
||||
$msg = $existMsg;
|
||||
}
|
||||
|
||||
if(msg.option && msg.option.parent){
|
||||
//parent는 삭제.
|
||||
$('#msg_{0}'.format(msg.option.parent)).detach();
|
||||
var hideMsg = false;
|
||||
if(msg.option){
|
||||
console.log(msg.option);
|
||||
if(msg.option.delete !== undefined){
|
||||
//delete는 삭제.
|
||||
$('#msg_{0}'.format(msg.option.delete)).detach();
|
||||
}
|
||||
if(msg.option.overwrite !== undefined){
|
||||
//overwrite는 숨기기.
|
||||
$.map(msg.option.overwrite, function (overwriteID) {
|
||||
console.log(overwriteID);
|
||||
var $msg = $('#msg_{0}'.format(overwriteID));
|
||||
$msg.find('.btn-delete-msg').detach();
|
||||
$msg.find('.msg_content').html('삭제된 메시지입니다.').removeClass('msg_valid').addClass('msg_invalid');
|
||||
});
|
||||
|
||||
}
|
||||
if(msg.option.hide){
|
||||
hideMsg = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(hideMsg){
|
||||
return null;
|
||||
}
|
||||
|
||||
$msg.find('.btn-delete-msg').click(function(){
|
||||
if(!confirm("삭제하시겠습니까?")){
|
||||
return false;
|
||||
}
|
||||
deleteMessage(msg.id);
|
||||
});
|
||||
|
||||
$msg.find('button.prompt_yes').click(function(){
|
||||
if(!confirm("수락하시겠습니까?")){
|
||||
return false;
|
||||
@@ -253,6 +314,7 @@ function redrawMsg(deferred, addFront){
|
||||
}
|
||||
|
||||
deferred
|
||||
.then(checkErasable)
|
||||
.then(checkClear)
|
||||
.then(registerSequence)
|
||||
.then(refineMessageObjs)
|
||||
@@ -459,7 +521,7 @@ function activateMessageForm(){
|
||||
jQuery(function($){
|
||||
|
||||
//tmp_template.html은 추후 msg.js에 통합될 수 있음
|
||||
var getTemplate = $.get('js/templates/message.html?3',function(obj){
|
||||
var getTemplate = $.get('js/templates/message.html?7',function(obj){
|
||||
messageTemplate = obj;
|
||||
});
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
</div>
|
||||
<div class="msg_body">
|
||||
<div class="msg_header">
|
||||
<%if(msgType != 'diplomacy' && src.id == myGeneralID && now <= last5min && invalidType == 'msg_valid'){%>
|
||||
<button type="button" data-erase_until="<%last5min%>" class="btn btn btn-outline-warning btn-sm btn-delete-msg" style='float:right'>❌</button>
|
||||
<%}%>
|
||||
<%if(msgType == 'private') {%>
|
||||
<%if(src.name == generalName){%>
|
||||
<span class="msg_target msg_<%src.colorType%>" style="background-color:<%src.color%>;">나</span
|
||||
@@ -37,9 +40,8 @@
|
||||
<span class="msg_target msg_<%src.colorType%>" style="background-color:<%src.color%>;"><%e(src.name)%>:<%src.nation%></span>
|
||||
<%} %>
|
||||
<span class="msg_time"><<%e(time)%>></span>
|
||||
</div>
|
||||
|
||||
<div class="msg_content"><%e(text)%></div>
|
||||
</div>
|
||||
<div class="msg_content <%invalidType%>"><%e(text)%></div>
|
||||
<%if(this.option && this.option.action) {%>
|
||||
<div class="msg_prompt">
|
||||
<button class="prompt_yes btn_prompt" <%allowButton?'':'disabled="disabled"'%>>>수락</button> <button class="prompt_no btn_prompt" <%allowButton?'':'disabled="disabled"'%>>거절</button>
|
||||
|
||||
@@ -333,7 +333,6 @@ class DiplomaticMessage extends Message{
|
||||
$this->dest->generalID = $receiverID;
|
||||
$this->dest->generalName = $general['name'];
|
||||
$this->msgOption['used'] = true;
|
||||
$this->invalidate();
|
||||
$this->validDiplomacy = false;
|
||||
|
||||
$josaYi = JosaUtil::pick($this->src->nationName, '이');
|
||||
@@ -345,9 +344,11 @@ class DiplomaticMessage extends Message{
|
||||
new \DateTime(),
|
||||
new \DateTime('9999-12-31'),
|
||||
[
|
||||
'delete'=>$this->id
|
||||
'delete'=>$this->id,
|
||||
'silence'=>true,
|
||||
]
|
||||
);
|
||||
$this->invalidate();
|
||||
$newMsg->send();
|
||||
|
||||
return self::ACCEPTED;
|
||||
|
||||
+82
-22
@@ -184,7 +184,7 @@ class Message
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getMessageByID(int $messageID) : Message
|
||||
public static function getMessageByID(int $messageID) : ?Message
|
||||
{
|
||||
$db = DB::db();
|
||||
$now = new \DateTime();
|
||||
@@ -265,6 +265,53 @@ class Message
|
||||
}, $db->query('SELECT * FROM `message` WHERE %l ORDER BY id DESC %? ', $where, $limitSql));
|
||||
}
|
||||
|
||||
public static function deleteMsg(int $msgID, int $generalID):?string{
|
||||
$msgObj = static::getMessageByID($msgID);
|
||||
if($msgObj=== null){
|
||||
return '메시지가 없습니다';
|
||||
}
|
||||
|
||||
if($msgObj->src->generalID != $generalID){
|
||||
return '본인의 메시지만 삭제할 수 있습니다.';
|
||||
}
|
||||
|
||||
$prev5min = new \DateTime();
|
||||
$prev5min->sub(new \DateInterval('PT5M'));
|
||||
|
||||
if($msgObj->date < $prev5min){
|
||||
return '5분 이내의 메시지만 삭제할 수 있습니다.';
|
||||
}
|
||||
|
||||
$msgOption = [
|
||||
'hide'=>true,
|
||||
'silence'=>true,
|
||||
'overwrite'=>[$msgObj->id]
|
||||
];
|
||||
|
||||
if($msgObj->msgType == Message::MSGTYPE_PRIVATE || $msgObj->msgType == Message::MSGTYPE_NATIONAL){
|
||||
$msgObj2 = static::getMessageByID($msgObj->msgOption['receiverMessageID']);
|
||||
if($msgObj2 !== null){
|
||||
$msgObj2->invalidate(null, false);
|
||||
$msgOption['overwrite'][] = [$msgObj2->id];
|
||||
}
|
||||
}
|
||||
|
||||
$in1min = new \DateTime();
|
||||
$in1min->add(new \DateInterval('PT1M'));
|
||||
$newMsg = new Message(
|
||||
$msgObj->msgType,
|
||||
$msgObj->src,
|
||||
$msgObj->dest,
|
||||
"req_del_msg",
|
||||
new \DateTime(),
|
||||
$in1min,
|
||||
$msgOption
|
||||
);
|
||||
$msgObj->invalidate(null, false);
|
||||
$newMsg->send(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function sendRaw(int $mailbox):array{
|
||||
//NOTE:: 여기선 검증하지 않는다.
|
||||
|
||||
@@ -302,7 +349,7 @@ class Message
|
||||
}
|
||||
|
||||
private function sendToSender():array{
|
||||
if($this->sendCnt > 0){
|
||||
if($this->sendCnt > 1){
|
||||
throw new \RuntimeException('이미 전송한 메일입니다.');
|
||||
}
|
||||
if($this->msgType === self::MSGTYPE_PRIVATE && $this->src->generalID !== $this->dest->generalID){
|
||||
@@ -315,15 +362,17 @@ class Message
|
||||
}
|
||||
|
||||
private function sendToReceiver() : array{
|
||||
if($this->sendCnt > 1 || $this->isInboxMail){
|
||||
if($this->sendCnt > 0 || $this->isInboxMail){
|
||||
throw new \RuntimeException('이미 전송한 메일입니다.');
|
||||
}
|
||||
|
||||
if($this->msgType === self::MSGTYPE_PRIVATE){
|
||||
//XXX: 알림을 이런식으로 보내는게 맞는가에 대한 의문 있음
|
||||
DB::db()->update('general', [
|
||||
'newmsg'=>1
|
||||
], 'no=%i',$this->dest->generalID);
|
||||
if(!($this->msgOption['silence']??false)){
|
||||
//XXX: 알림을 이런식으로 보내는게 맞는가에 대한 의문 있음
|
||||
DB::db()->update('general', [
|
||||
'newmsg'=>1
|
||||
], 'no=%i',$this->dest->generalID);
|
||||
}
|
||||
return $this->sendRaw($this->dest->generalID);
|
||||
}
|
||||
|
||||
@@ -339,18 +388,7 @@ class Message
|
||||
}
|
||||
|
||||
public function send(bool $sendDestOnly=false):int{
|
||||
if(!$sendDestOnly){
|
||||
list($senderMailbox, $sendID) = $this->sendToSender();
|
||||
if($sendID){
|
||||
$this->mailbox = $senderMailbox;
|
||||
$this->isInboxMail = false;
|
||||
$this->id = $sendID;
|
||||
$this->msgOption['senderMessageID'] = $sendID;
|
||||
$this->sendCnt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
list($receiverMailbox, $receiveID) = $this->sendToReceiver();
|
||||
[$receiverMailbox, $receiveID] = $this->sendToReceiver();
|
||||
if(!$receiveID && !$sendDestOnly){
|
||||
return $sendID;
|
||||
}
|
||||
@@ -358,17 +396,39 @@ class Message
|
||||
$this->isInboxMail = true;
|
||||
$this->id = $receiveID;
|
||||
$this->msgOption['receiverMessageID'] = $receiveID;
|
||||
$this->sendCnt = 2;
|
||||
$this->sendCnt = 1;
|
||||
|
||||
if(!$sendDestOnly){
|
||||
[$senderMailbox, $sendID] = $this->sendToSender();
|
||||
if($sendID){
|
||||
$this->mailbox = $senderMailbox;
|
||||
$this->isInboxMail = false;
|
||||
$this->id = $sendID;
|
||||
$this->msgOption['senderMessageID'] = $sendID;
|
||||
$this->sendCnt = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return $receiveID;
|
||||
}
|
||||
|
||||
public function invalidate(array $newMsgOption=null){
|
||||
public function invalidate(?array $newMsgOption=null, bool $hideMsg=true){
|
||||
if($newMsgOption !== null){
|
||||
$this->msgOption = $newMsgOption;
|
||||
}
|
||||
|
||||
$this->validUntil = new \DateTime('2000-12-31');
|
||||
$this->msgOption['invalid'] = true;
|
||||
|
||||
if($hideMsg){
|
||||
$this->validUntil = new \DateTime('2000-12-31');
|
||||
}
|
||||
else{
|
||||
if(key_exists('receiverMessageID', $this->msgOption)){
|
||||
$this->msgOption['originalText'] = $this->msg;
|
||||
}
|
||||
$this->msg = '삭제된 메시지입니다.';
|
||||
}
|
||||
|
||||
|
||||
$db = DB::db();
|
||||
$db->update('message', [
|
||||
|
||||
Reference in New Issue
Block a user