|
@@ -664,6 +664,7 @@
|
|
|
role: role || "user",
|
|
role: role || "user",
|
|
|
isImage: true,
|
|
isImage: true,
|
|
|
imageUrl: imageUrls[0],
|
|
imageUrl: imageUrls[0],
|
|
|
|
|
+ images: imageUrls,
|
|
|
content: content,
|
|
content: content,
|
|
|
});
|
|
});
|
|
|
continue;
|
|
continue;
|
|
@@ -815,18 +816,54 @@
|
|
|
return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
|
|
return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function normalizeShareMessagesForRender(messages) {
|
|
|
|
|
+ var list = Array.isArray(messages) ? messages : [];
|
|
|
|
|
+ return list.map(function (msg) {
|
|
|
|
|
+ if (!msg || typeof msg !== "object") return msg;
|
|
|
|
|
+ var m = Object.assign({}, msg);
|
|
|
|
|
+ var imgs = Array.isArray(m.images) ? m.images.slice() : [];
|
|
|
|
|
+ if (!imgs.length && m.imageUrl) imgs = [m.imageUrl];
|
|
|
|
|
+ if (!imgs.length && m.image) imgs = [m.image];
|
|
|
|
|
+ imgs = imgs
|
|
|
|
|
+ .map(function (u) {
|
|
|
|
|
+ return String(u || "").trim();
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter(function (u) {
|
|
|
|
|
+ return /^https?:\/\//i.test(u);
|
|
|
|
|
+ });
|
|
|
|
|
+ if (m.isImage || imgs.length) {
|
|
|
|
|
+ if (!imgs.length) return m;
|
|
|
|
|
+ m.isImage = true;
|
|
|
|
|
+ m.imageUrl = imgs[0];
|
|
|
|
|
+ m.images = imgs;
|
|
|
|
|
+ }
|
|
|
|
|
+ return m;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function renderUserImageBubbleHtml(msg) {
|
|
|
|
|
+ var imgs = Array.isArray(msg.images) && msg.images.length ? msg.images : [];
|
|
|
|
|
+ if (!imgs.length && msg.imageUrl) imgs = [msg.imageUrl];
|
|
|
|
|
+ if (!imgs.length) return "";
|
|
|
|
|
+ var html = "";
|
|
|
|
|
+ for (var i = 0; i < imgs.length; i++) {
|
|
|
|
|
+ html +=
|
|
|
|
|
+ '<div class="row row--user"><div class="user-bubble"><img class="user-bubble__image" src="' +
|
|
|
|
|
+ escHtml(imgs[i]) +
|
|
|
|
|
+ '" alt="图片" loading="lazy" decoding="async" /></div></div>';
|
|
|
|
|
+ }
|
|
|
|
|
+ return html;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function renderMessages(messages) {
|
|
function renderMessages(messages) {
|
|
|
var html = "";
|
|
var html = "";
|
|
|
- var list = Array.isArray(messages) ? messages : [];
|
|
|
|
|
|
|
+ var list = normalizeShareMessagesForRender(messages);
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
var msg = list[i];
|
|
var msg = list[i];
|
|
|
if (!msg) continue;
|
|
if (!msg) continue;
|
|
|
if (msg.role === "user") {
|
|
if (msg.role === "user") {
|
|
|
- if (msg.isImage && msg.imageUrl) {
|
|
|
|
|
- html +=
|
|
|
|
|
- '<div class="row row--user"><div class="user-bubble"><img class="user-bubble__image" src="' +
|
|
|
|
|
- escHtml(msg.imageUrl) +
|
|
|
|
|
- '" alt="图片" loading="lazy" decoding="async" /></div></div>';
|
|
|
|
|
|
|
+ if (msg.isImage && (msg.imageUrl || (msg.images && msg.images.length))) {
|
|
|
|
|
+ html += renderUserImageBubbleHtml(msg);
|
|
|
var imageUserText = String(msg.content || "").trim();
|
|
var imageUserText = String(msg.content || "").trim();
|
|
|
if (imageUserText) {
|
|
if (imageUserText) {
|
|
|
html +=
|
|
html +=
|
|
@@ -892,7 +929,7 @@
|
|
|
var msg = list[i];
|
|
var msg = list[i];
|
|
|
if (!msg) continue;
|
|
if (!msg) continue;
|
|
|
if (msg.role === "user") {
|
|
if (msg.role === "user") {
|
|
|
- if (msg.isImage && msg.imageUrl) {
|
|
|
|
|
|
|
+ if (msg.isImage && (msg.imageUrl || (msg.images && msg.images.length))) {
|
|
|
count += 1;
|
|
count += 1;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|