Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
HereIsYui authored Sep 27, 2024
2 parents 3d05d25 + 19980f7 commit 29629e1
Show file tree
Hide file tree
Showing 11 changed files with 1,336 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ public void addChatRoomMsg(final RequestContext context) {
String userId = currentUser.optString(Keys.OBJECT_ID);

if (content.startsWith("[redpacket]") && content.endsWith("[/redpacket]")) {
LOGGER.log(Level.INFO, "Sent red packet [content={}], userName={}]", content, userName);
// 是否收税
Boolean collectTaxes = false;
// 税率
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/b3log/symphony/processor/IndexProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
import org.b3log.symphony.util.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.InputStream;
import java.math.BigDecimal;
Expand Down Expand Up @@ -533,7 +537,23 @@ public synchronized void showIndex(final RequestContext context) {
dataModel.put("need2fa", "no");
}

dataModel.put(Common.MESSAGES, ChatroomProcessor.getMessages(1,"html"));
List<JSONObject> messages = ChatroomProcessor.getMessages(1,"html");
for (JSONObject message : messages) {
String content = message.optString("content");
Document doc = Jsoup.parse(content);

// 获取所有的 img 标签
Elements imgElements = doc.select("img");
for (Element img : imgElements) {
String src = img.attr("src");
// 在 src 后面加上 ?imageView2/0/w/150/h/150/interlace/0/q/90
img.attr("src", src + "?imageView2/0/w/150/h/150/interlace/0/q/90");
}

// 更新 message 中的 content 字段
message.put("content", doc.html());
}
dataModel.put(Common.MESSAGES, messages);

makeIndexData(dataModel);

Expand Down
17 changes: 16 additions & 1 deletion src/main/resources/js/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ var ChatRoomChannel = {
" </a>\n" +
" </div>\n" +
" <div class=\"vditor-reset comment " + Label.chatRoomPictureStatus + "\">\n" +
" " + newContent + "\n" +
" " + ChatRoomChannel.filterContent(newContent) + "\n" +
" </div>\n" +
" </div>\n" +
"</li>");
Expand Down Expand Up @@ -549,6 +549,21 @@ var ChatRoomChannel = {
}, 10000);
}
},
/**
* 过滤消息中的图片
* */
filterContent: function(content){
console.log(content);
let dom = document.createElement("div");
dom.innerHTML = content;
let imgList = dom.querySelectorAll('img');
imgList.forEach(ele=>{
//if(ele.src.startsWith('https://file.fishpi.cn')){
ele.src = ele.src + '?imageView2/0/w/150/h/150/interlace/0/q/90'
//}
})
return dom.innerHTML;
},
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/js/channel.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/js/chat-room.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ border-bottom: none;
dom.innerHTML = content;
let imgList = dom.querySelectorAll('img');
imgList.forEach(ele=>{
ele.setAttribute('originalsrc', ele.src);
if(ele.src.startsWith('https://file.fishpi.cn')){
ele.src = ele.src.split('?')[0] + '?imageView2/0/w/150/h/150/interlace/0/q/90'
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/js/chat-room.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 29629e1

Please sign in to comment.