diff --git a/src/main/java/org/b3log/symphony/util/Vocation.java b/src/main/java/org/b3log/symphony/util/Vocation.java index 3a9e637f..2cbfdaf8 100644 --- a/src/main/java/org/b3log/symphony/util/Vocation.java +++ b/src/main/java/org/b3log/symphony/util/Vocation.java @@ -96,7 +96,7 @@ public static boolean refresh() { return false; } } catch (Exception e) { - LOGGER.log(Level.ERROR, "Failed to refresh Vocation Date. [vocationData=\"" + vocationData + "\"]", e); + LOGGER.log(Level.ERROR, "Failed to refresh Vocation Date. [vocationData=\"" + vocationData + "\"]"); return false; } } diff --git a/src/main/resources/js/chat.js b/src/main/resources/js/chat.js index 1d8dbc27..799ca937 100644 --- a/src/main/resources/js/chat.js +++ b/src/main/resources/js/chat.js @@ -46,7 +46,7 @@ var Chat = { reqRecentList = $.ajax({ url: Label.servePath + '/chat/get-list?apiKey=' + apiKey, type: 'GET', - async: false, + async: true, success: function (result) { if (0 === result.result) { let data = result.data; @@ -78,6 +78,7 @@ var Chat = { var reqLoadUser = $.ajax({ url: Label.servePath + "/user/" + toUser, type: "GET", + async: true, success: function (result) { if (result.code === -1) { alert('指定的用户名不存在,请检查后重试!'); @@ -108,7 +109,7 @@ var Chat = { $.ajax({ url: Label.servePath + '/chat/has-unread?apiKey=' + apiKey, type: 'GET', - async: false, + async: true, success: function (result) { let count = result.result; let list = result.data; @@ -119,6 +120,8 @@ var Chat = { }); } else { // 已选定用户,获取第一页聊天信息 + // 选中用户 + $("#chatTo" + toUser).css("background-color", "#f1f1f1"); // 状态 $("#chatStatus").html('和 ' + '' + toUser + ' ' + @@ -210,7 +213,8 @@ var Chat = { // 用户已读 $.ajax({ url: Label.servePath + "/chat/mark-as-read?apiKey=" + apiKey + "&fromUser=" + Chat.toUser, - type: "GET" + type: "GET", + async: true }); } } @@ -239,13 +243,13 @@ var Chat = { $.ajax({ url: Label.servePath + "/chat/mark-as-read?apiKey=" + apiKey + "&fromUser=" + Chat.toUser, type: "GET", - async: false + async: true }); // 加载未读消息 var loadUnread = $.ajax({ url: Label.servePath + '/chat/has-unread?apiKey=' + apiKey, type: 'GET', - async: false, + async: true, success: function (result) { let count = result.result; let list = result.data; @@ -254,10 +258,6 @@ var Chat = { }); } }); - $.when(loadUnread).done(function () { - // 选中用户 - $("#chatTo" + toUser).css("background-color", "#f1f1f1"); - }); } }); }); @@ -279,7 +279,7 @@ var Chat = { $.ajax({ url: Label.servePath + "/chat/get-message?apiKey=" + apiKey + "&toUser=" + Chat.toUser + "&page=" + Chat.page + "&pageSize=20", type: "GET", - async: false, + async: true, success: function (result) { try { result.data.length; @@ -448,7 +448,8 @@ var Chat = { revoke(oId) { $.ajax({ url: Label.servePath + "/chat/revoke?apiKey=" + apiKey + "&oId=" + oId, - type: "GET" + type: "GET", + async: true }); }, @@ -456,6 +457,7 @@ var Chat = { $.ajax({ url: Label.servePath + "/chat/mark-all-as-read?apiKey=" + apiKey, type: "GET", + async: true, success: function (result) { result.users.forEach((user) => { $("#chatTo" + user).css("background-color", ""); diff --git a/src/main/resources/js/chat.min.js b/src/main/resources/js/chat.min.js index b24a4728..a7567915 100644 --- a/src/main/resources/js/chat.min.js +++ b/src/main/resources/js/chat.min.js @@ -1,4 +1,4 @@ -var Chat={page:1,toUser:"",init:function(e){let a;if(void 0!==e){Chat.page=1;try{Chat.ws.close()}catch(e){}$("#chats").html(""),$("#chatTo"+Chat.toUser).css("background-color",""),Chat.toUser="",Chat.noMore=!1,a=e}else a=getQueryVariable("toUser");Chat.toUser=a,e=$.ajax({url:Label.servePath+"/chat/get-list?apiKey="+apiKey,type:"GET",async:!1,success:function(e){0===e.result&&0!==(e=e.data).length&&e.forEach(e=>{"文件传输助手"===e.receiverUserName?$("#fileTransferMsg").html(e.preview):e.senderUserName!=Label.currentUserName?$("#chatTo"+e.senderUserName).length<=0&&Chat.addToMessageList(e.senderUserName,e.senderAvatar,e.preview,e.receiverOnlineFlag):$("#chatTo"+e.receiverUserName).length<=0&&Chat.addToMessageList(e.receiverUserName,e.receiverAvatar,e.preview,e.receiverOnlineFlag)})}}),$.when(e).done(function(){var e;""!==a&&"FileTransfer"!==a&&(e=$.ajax({url:Label.servePath+"/user/"+a,type:"GET",success:function(e){-1===e.code&&(alert("指定的用户名不存在,请检查后重试!"),location.href=Label.servePath+"/chat"),$("#chatTo"+e.userName).length<=0&&Chat.addToMessageList(e.userName,e.userAvatarURL," "),a=e.userName,Chat.toUser=a}})),$.when(e).done(function(){var e;""===a?($("#chatStatus").html('请在左侧列表选择最近聊天的成员,或直接发起聊天。

 '),$("#chatWithInput").keypress(function(e){13==e.which&&Chat.startAChat()}),$.ajax({url:Label.servePath+"/chat/has-unread?apiKey="+apiKey,type:"GET",async:!1,success:function(e){e.result;e.data.forEach(e=>{$("#chatTo"+e.senderUserName).css("background-color","#fff4eb")})}})):($("#chatStatus").html('和 '+a+" 聊天中"),$("#buttons").show(),$(".pagination__chat").show(),Chat.editor=Util.newVditor({id:"messageContent",cache:!0,preview:{mode:"editor"},resize:{enable:!0,position:"bottom"},height:150,placeholder:"说点什么吧,友善第一哦。",toolbar:["emoji","link","upload","edit-mode",{name:"more",toolbar:["insert-after","fullscreen","preview","info","help"]}],ctrlEnter:function(){Chat.send()}}),Chat.ws=new WebSocket(chatChannelURL+a),Chat.ws.onopen=function(){console.log("Connected to chat channel websocket.")},Chat.ws.onmessage=function(e){var a,t,s,n,r,i,o,l,c,e=JSON.parse(e.data);"revoke"===e.type?$("#chat"+e.data).remove():-1===e.code?$("#chatContentTip").addClass("error").html(""):($("#chatContentTip").removeClass("error succ").html(""),a=e.oId,t=e.toId,e.fromId,s=e.time,n=e.content,r=e.preview.substring(0,10),i=10{$("#chatTo"+e.senderUserName).css("background-color","#fff4eb")})}}),$.when(e).done(function(){$("#chatTo"+a).css("background-color","#f1f1f1")}))})})},startAChat(){var e=$("#chatWithInput").val();""!==e&&Chat.init(e)},noMore:!1,moreLock:!1,loadMore(){Chat.moreLock||(Chat.moreLock=!0,Chat.noMore||$.ajax({url:Label.servePath+"/chat/get-message?apiKey="+apiKey+"&toUser="+Chat.toUser+"&page="+Chat.page+"&pageSize=20",type:"GET",async:!1,success:function(e){try{e.data.length}catch(e){Chat.noMore=!0}Chat.noMore||(Chat.page++,e.data.forEach(e=>{var a=e.oId,t=(e.toId,e.fromId,e.time),s=e.content,n=(e.preview.substring(0,10),e.preview.length,e.user_session,e.senderUserName),r=e.senderAvatar;e.receiverUserName,e.receiverAvatar;n===Label.currentUserName?Chat.addSelfMsg(a,n,r,s,t,!0):Chat.addTargetMsg(a,n,r,s,t,!0)}))}}),Chat.moreLock=!1)},send(){var e=Chat.editor.getValue();1024
  • 发送失败:超过 1024 字符,请修改后重试。
  • "):(Chat.ws.send(e),Chat.editor.setValue(""))},addToMessageList(e,a,t,s){var n=10\n
    \n
    \n
    \n '+e+'
    \n '+t.substring(0,10)+n+'\n
    \n
    '+s+"
    \n \n"),"none"===$("#messageListPanel").css("display")&&$("#messageListPanel").show()},addSelfMsg(e,a,t,s,n,r){!0===r?$("#chats").append('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+'\n
    \n \n ···\n \n \n 撤回\n \n
    \n
    '):$("#chats").prepend('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+'\n
    \n \n ···\n \n \n 撤回\n \n
    \n
    '),Util.listenUserCard()},addTargetMsg(e,a,t,s,n,r){!0===r?$("#chats").append('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+"\n
    \n
    \n
    "):$("#chats").prepend('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+"\n
    \n
    \n
    "),Util.listenUserCard()},revoke(e){$.ajax({url:Label.servePath+"/chat/revoke?apiKey="+apiKey+"&oId="+e,type:"GET"})},markAllAsRead(){$.ajax({url:Label.servePath+"/chat/mark-all-as-read?apiKey="+apiKey,type:"GET",success:function(e){e.users.forEach(e=>{$("#chatTo"+e).css("background-color","")})}})},loadEmojis:function(){let a=Chat.getEmojis(),t="";for(let e=0;e +var Chat={page:1,toUser:"",init:function(e){let a;if(void 0!==e){Chat.page=1;try{Chat.ws.close()}catch(e){}$("#chats").html(""),$("#chatTo"+Chat.toUser).css("background-color",""),Chat.toUser="",Chat.noMore=!1,a=e}else a=getQueryVariable("toUser");Chat.toUser=a,e=$.ajax({url:Label.servePath+"/chat/get-list?apiKey="+apiKey,type:"GET",async:!0,success:function(e){0===e.result&&0!==(e=e.data).length&&e.forEach(e=>{"文件传输助手"===e.receiverUserName?$("#fileTransferMsg").html(e.preview):e.senderUserName!=Label.currentUserName?$("#chatTo"+e.senderUserName).length<=0&&Chat.addToMessageList(e.senderUserName,e.senderAvatar,e.preview,e.receiverOnlineFlag):$("#chatTo"+e.receiverUserName).length<=0&&Chat.addToMessageList(e.receiverUserName,e.receiverAvatar,e.preview,e.receiverOnlineFlag)})}}),$.when(e).done(function(){var e;""!==a&&"FileTransfer"!==a&&(e=$.ajax({url:Label.servePath+"/user/"+a,type:"GET",success:function(e){-1===e.code&&(alert("指定的用户名不存在,请检查后重试!"),location.href=Label.servePath+"/chat"),$("#chatTo"+e.userName).length<=0&&Chat.addToMessageList(e.userName,e.userAvatarURL," "),a=e.userName,Chat.toUser=a}})),$.when(e).done(function(){var e;""===a?($("#chatStatus").html('请在左侧列表选择最近聊天的成员,或直接发起聊天。

     '),$("#chatWithInput").keypress(function(e){13==e.which&&Chat.startAChat()}),$.ajax({url:Label.servePath+"/chat/has-unread?apiKey="+apiKey,type:"GET",async:!0,success:function(e){e.result;e.data.forEach(e=>{$("#chatTo"+e.senderUserName).css("background-color","#fff4eb")})}})):($("#chatStatus").html('和 '+a+" 聊天中"),$("#buttons").show(),$(".pagination__chat").show(),Chat.editor=Util.newVditor({id:"messageContent",cache:!0,preview:{mode:"editor"},resize:{enable:!0,position:"bottom"},height:150,placeholder:"说点什么吧,友善第一哦。",toolbar:["emoji","link","upload","edit-mode",{name:"more",toolbar:["insert-after","fullscreen","preview","info","help"]}],ctrlEnter:function(){Chat.send()}}),Chat.ws=new WebSocket(chatChannelURL+a),Chat.ws.onopen=function(){console.log("Connected to chat channel websocket.")},Chat.ws.onmessage=function(e){var a,t,s,n,r,i,o,l,c,e=JSON.parse(e.data);"revoke"===e.type?$("#chat"+e.data).remove():-1===e.code?$("#chatContentTip").addClass("error").html("
    • "+e.msg+"
    "):($("#chatContentTip").removeClass("error succ").html(""),a=e.oId,t=e.toId,e.fromId,s=e.time,n=e.content,r=e.preview.substring(0,10),i=10{$("#chatTo"+e.senderUserName).css("background-color","#fff4eb")})}}),$.when(e).done(function(){$("#chatTo"+a).css("background-color","#f1f1f1")}))})})},startAChat(){var e=$("#chatWithInput").val();""!==e&&Chat.init(e)},noMore:!1,moreLock:!1,loadMore(){Chat.moreLock||(Chat.moreLock=!0,Chat.noMore||$.ajax({url:Label.servePath+"/chat/get-message?apiKey="+apiKey+"&toUser="+Chat.toUser+"&page="+Chat.page+"&pageSize=20",type:"GET",async:!0,success:function(e){try{e.data.length}catch(e){Chat.noMore=!0}Chat.noMore||(Chat.page++,e.data.forEach(e=>{var a=e.oId,t=(e.toId,e.fromId,e.time),s=e.content,n=(e.preview.substring(0,10),e.preview.length,e.user_session,e.senderUserName),r=e.senderAvatar;e.receiverUserName,e.receiverAvatar;n===Label.currentUserName?Chat.addSelfMsg(a,n,r,s,t,!0):Chat.addTargetMsg(a,n,r,s,t,!0)}))}}),Chat.moreLock=!1)},send(){var e=Chat.editor.getValue();1024
  • 发送失败:超过 1024 字符,请修改后重试。
  • "):(Chat.ws.send(e),Chat.editor.setValue(""))},addToMessageList(e,a,t,s){var n=10\n
    \n
    \n
    \n '+e+'
    \n '+t.substring(0,10)+n+'\n
    \n
    '+s+"
    \n \n"),"none"===$("#messageListPanel").css("display")&&$("#messageListPanel").show()},addSelfMsg(e,a,t,s,n,r){!0===r?$("#chats").append('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+'\n
    \n \n ···\n \n \n 撤回\n \n
    \n
    '):$("#chats").prepend('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+'\n
    \n \n ···\n \n \n 撤回\n \n
    \n
    '),Util.listenUserCard()},addTargetMsg(e,a,t,s,n,r){!0===r?$("#chats").append('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+"\n
    \n
    \n
    "):$("#chats").prepend('
    \n \n
    \n
    \n
    \n
    \n
    \n '+s+'\n
    \n
    \n '+n+"\n
    \n
    \n
    "),Util.listenUserCard()},revoke(e){$.ajax({url:Label.servePath+"/chat/revoke?apiKey="+apiKey+"&oId="+e,type:"GET"})},markAllAsRead(){$.ajax({url:Label.servePath+"/chat/mark-all-as-read?apiKey="+apiKey,type:"GET",async:!0,success:function(e){e.users.forEach(e=>{$("#chatTo"+e).css("background-color","")})}})},loadEmojis:function(){let a=Chat.getEmojis(),t="";for(let e=0;e
    `;$("#emojis").html(t)},confirmed:!1,delEmoji:function(a){if(!0===Chat.confirmed||confirm("确定要删除该表情包吗?")){Chat.confirmed=!0;var t=Chat.getEmojis();for(let e=0;e\n\n
    \n
    \n \n
    \n',"从URL导入表情包"),$("#fromURL").focus(),$("#fromURL").unbind(),$("#fromURL").bind("keypress",function(e){"13"==e.keyCode&&(Chat.addEmoji($("#fromURL").val()),Util.closeAlert())})},addEmoji:function(){for(let e=0;e'),$(".img-preview").css({"background-color":"#fff",position:"fixed"}))}),$(window).scroll(function(){1<$(this).scrollTop()?$("#goToTop").fadeIn():$("#goToTop").fadeOut()}),$("#goToTop a").click(function(){return $("html,body").animate({scrollTop:0},800),!1}),$("body").click(function(){$("details[open]").removeAttr("open")}),Chat.listenUploadEmojis(),Chat.loadEmojis();{let e=(new Date).getTime(),a=0;function t(){0!==a&&(clearTimeout(a),a=0),e=(new Date).getTime(),a=setTimeout(()=>{(new Date).getTime()-e<=700&&$("#emojiList").removeClass("showList")},null!==navigator.userAgent.match(/(phone|pad|pod|ios|Android|Mobile|BlackBerry|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian)/i)?0:600)}$("#emojiBtn").hover(function(){0!==a&&(clearTimeout(a),a=0),$("#emojiList").css("top","350px"),e=(new Date).getTime(),setTimeout(()=>0!==$("#emojiBtn:hover").length&&$("#emojiList").addClass("showList"),300)},t),$("#emojiList").hover(function(){0!==a&&(clearTimeout(a),a=0),e=(new Date).getTime()},t)}}); \ No newline at end of file