Compare commits

...

11 Commits

Author SHA1 Message Date
Tim
ad481cffca feat: add floating new message indicator 2025-09-07 23:57:06 +08:00
tim
68a82fa2ec fix: 回复ui 2025-09-07 23:50:11 +08:00
tim
cab8cd06dc fix: 频道聊天,点击写个回复没反应,点击小箭头才行 #916 2025-09-07 22:46:55 +08:00
Tim
b77a96938a Merge pull request #915 from nagisa77/feature/article_ui_fix
Article UI fixes
2025-09-07 14:14:56 +08:00
Tim
df4a707e3a Merge pull request #914 from nagisa77/feature/article_ui_fix
Article UI Fixes
2025-09-07 13:58:42 +08:00
Tim
14ee5faa1f Merge pull request #913 from nagisa77/feature/sidebar-logic
fix: 更新分类选择
2025-09-07 13:38:56 +08:00
Tim
2eebc1c004 Merge pull request #911 from nagisa77/feature/sidebar-logic
feat: 侧边栏按钮样式逻辑修改
2025-09-07 13:23:05 +08:00
Tim
135a6b8c51 Merge pull request #910 from nagisa77/codex/analyze-and-refactor-case
Fix point history balance recalculation
2025-09-07 12:48:04 +08:00
Tim
c43e4b85bc Test recalculation updates balance 2025-09-07 12:47:44 +08:00
Tim
fb3a2839db Merge pull request #909 from Linindoo/main
修复纯数字用户名的用户个人首页 404 问题(注册和修改校验用户名不能为纯数字)
2025-09-07 11:14:40 +08:00
zhoujia
5534573a19 创建和更新用户名校验增加校验,不允许纯数字用户名 2025-09-05 15:08:22 +08:00
12 changed files with 177 additions and 25 deletions

View File

@@ -10,6 +10,7 @@ import java.util.List;
public interface PointHistoryRepository extends JpaRepository<PointHistory, Long> {
List<PointHistory> findByUserOrderByIdDesc(User user);
List<PointHistory> findByUserOrderByIdAsc(User user);
long countByUser(User user);
List<PointHistory> findByUserAndCreatedAtAfterOrderByCreatedAtDesc(User user, LocalDateTime createdAt);

View File

@@ -225,17 +225,20 @@ public class PointService {
*/
public int recalculateUserPoints(User user) {
// 获取用户所有的积分历史记录(由于@Where注解已删除的记录会被自动过滤
List<PointHistory> histories = pointHistoryRepository.findByUserOrderByIdDesc(user);
List<PointHistory> histories = pointHistoryRepository.findByUserOrderByIdAsc(user);
int totalPoints = 0;
for (PointHistory history : histories) {
totalPoints += history.getAmount();
// 重新计算每条历史记录的余额
history.setBalance(totalPoints);
}
// 更新用户积分
// 批量更新历史记录及用户积分
pointHistoryRepository.saveAll(histories);
user.setPoint(totalPoints);
userRepository.save(user);
return totalPoints;
}

View File

@@ -1,6 +1,7 @@
package com.openisle.service;
import com.openisle.exception.FieldException;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;
/**
@@ -17,6 +18,11 @@ public class UsernameValidator {
if (username == null || username.isEmpty()) {
throw new FieldException("username", "Username cannot be empty");
}
if (NumberUtils.isDigits(username)) {
throw new FieldException("username", "Username cannot be pure number");
}
}
}

View File

@@ -0,0 +1,67 @@
package com.openisle.service;
import com.openisle.model.PointHistory;
import com.openisle.model.PointHistoryType;
import com.openisle.model.Role;
import com.openisle.model.User;
import com.openisle.repository.PointHistoryRepository;
import com.openisle.repository.UserRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
@DataJpaTest
@Import(PointService.class)
class PointServiceRecalculateUserPointsTest {
@Autowired
private PointService pointService;
@Autowired
private UserRepository userRepository;
@Autowired
private PointHistoryRepository pointHistoryRepository;
@Test
void recalculatesBalanceAfterDeletion() {
User user = new User();
user.setUsername("u");
user.setEmail("u@example.com");
user.setPassword("p");
user.setRole(Role.USER);
userRepository.save(user);
PointHistory h1 = new PointHistory();
h1.setUser(user);
h1.setType(PointHistoryType.POST);
h1.setAmount(30);
h1.setBalance(30);
h1.setCreatedAt(LocalDateTime.now().minusMinutes(2));
pointHistoryRepository.save(h1);
PointHistory h2 = new PointHistory();
h2.setUser(user);
h2.setType(PointHistoryType.COMMENT);
h2.setAmount(10);
h2.setBalance(40);
h2.setCreatedAt(LocalDateTime.now().minusMinutes(1));
pointHistoryRepository.save(h2);
user.setPoint(40);
userRepository.save(user);
pointHistoryRepository.delete(h1);
int total = pointService.recalculateUserPoints(user);
assertEquals(10, total);
assertEquals(10, userRepository.findById(user.getId()).orElseThrow().getPoint());
assertEquals(10, pointHistoryRepository.findById(h2.getId()).orElseThrow().getBalance());
}
}

View File

@@ -18,7 +18,9 @@
--background-color-blur: rgba(255, 255, 255, 0.57);
--menu-border-color: lightgray;
--normal-border-color: lightgray;
--menu-selected-background-color: rgba(242, 242, 242, 0.884);
--menu-selected-background-color: rgba(88, 241, 255, 0.166);
--normal-light-background-color: rgba(242, 242, 242, 0.884);
--menu-selected-background-color-hover: rgba(242, 242, 242, 0.884);
--menu-text-color: rgb(99, 99, 99);
--scroller-background-color: rgba(130, 175, 180, 0.5);
/* --normal-background-color: rgb(241, 241, 241); */
@@ -58,6 +60,8 @@
--menu-border-color: #555;
--normal-border-color: #555;
--menu-selected-background-color: rgba(255, 255, 255, 0.1);
--normal-light-background-color: rgba(255, 255, 255, 0.1);
--menu-selected-background-color-hover: rgba(17, 182, 197, 0.082);
--menu-text-color: rgb(173, 173, 173);
/* --normal-background-color: #000000; */
--normal-background-color: #333;
@@ -162,7 +166,7 @@ body {
padding-left: 1em;
border-left: 4px solid #d0d7de;
color: var(--blockquote-text-color);
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
padding-top: 1px;
padding-bottom: 1px;
}
@@ -295,7 +299,7 @@ body {
/* 鼠标悬停行高亮 */
.info-content-text tbody tr:hover {
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
transition: background-color 0.2s ease;
}

View File

@@ -316,6 +316,10 @@ const gotoTag = (t) => {
align-items: center;
}
.menu-item:hover {
background-color: var(--menu-selected-background-color-hover);
}
.menu-item.selected {
font-weight: bold;
background-color: var(--menu-selected-background-color);
@@ -407,7 +411,7 @@ const gotoTag = (t) => {
}
.section-item:hover {
background-color: var(--menu-selected-background-color);
background-color: var(--menu-selected-background-color-hover);
}
.section-item-text-count {

View File

@@ -136,7 +136,7 @@ export default {
left: 0;
width: 100%;
height: 100%;
background: var(--menu-selected-background-color);
background: var(--normal-light-background-color);
display: flex;
align-items: center;
justify-content: center;

View File

@@ -331,11 +331,11 @@ onMounted(async () => {
.reactions-viewer-item.placeholder,
.reactions-viewer-single-item.selected {
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
}
.reaction-option.selected {
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
}
@media (max-width: 768px) {

View File

@@ -65,16 +65,17 @@
class="article-item"
v-for="article in articles"
:key="article.id"
@click="navigateTo(`/posts/${article.id}`)"
>
<div class="article-main-container">
<NuxtLink class="article-item-title main-item" :to="`/posts/${article.id}`">
<NuxtLink class="article-item-title main-item">
<pin v-if="article.pinned" theme="outline" class="pinned-icon" />
<gift v-if="article.type === 'LOTTERY'" class="lottery-icon" />
<ranking-list v-else-if="article.type === 'POLL'" class="poll-icon" />
<star v-if="!article.rssExcluded" class="featured-icon" />
{{ article.title }}
</NuxtLink>
<NuxtLink class="article-item-description main-item" :to="`/posts/${article.id}`">
<NuxtLink class="article-item-description main-item">
{{ sanitizeDescription(article.description) }}
</NuxtLink>
<div class="article-info-container main-item">
@@ -488,6 +489,11 @@ const sanitizeDescription = (text) => stripMarkdown(text)
border-bottom: 1px solid var(--normal-border-color);
}
.article-item:hover {
background-color: var(--menu-selected-background-color-hover);
cursor: pointer;
}
.article-main-container,
.header-item.main-item {
width: calc(60% - 20px);

View File

@@ -36,7 +36,11 @@
</div>
</div>
<div v-if="item.replyTo" class="reply-preview info-content-text">
<div class="reply-author">{{ item.replyTo.sender.username }}</div>
<div class="reply-header">
<next class="reply-icon" />
<BaseImage class="reply-avatar" :src="item.replyTo.sender.avatar" alt="avatar" />
<div class="reply-author">{{ item.replyTo.sender.username }}:</div>
</div>
<div class="reply-content" v-html="renderMarkdown(item.replyTo.content)"></div>
</div>
<div class="message-content">
@@ -48,7 +52,7 @@
:content-id="item.id"
@update:modelValue="(v) => (item.reactions = v)"
>
<div class="reply-btn"><next @click="setReply(item)" /> 写个回复...</div>
<div @click="setReply(item)" class="reply-btn"><next /> 写个回复...</div>
</ReactionsGroup>
</template>
</BaseTimeline>
@@ -63,11 +67,21 @@
</div>
<div class="message-input-area">
<div
v-if="newMessagesCount > 0 && !isUserNearBottom"
class="new-message-container"
@click="handleScrollToBottom"
>
<double-down />
<div class="new-message-count">{{ newMessagesCount }}条新消息</div>
</div>
<div v-if="replyTo" class="active-reply">
正在回复 {{ replyTo.sender.username }}:
{{ stripMarkdownLength(replyTo.content, 50) }}
<close-icon class="close-reply" @click="replyTo = null" />
</div>
<MessageEditor :loading="sending" @submit="sendMessage" />
</div>
</div>
@@ -120,6 +134,7 @@ const isChannel = ref(false)
const isFloatMode = computed(() => route.query.float !== undefined)
const floatRoute = useState('messageFloatRoute')
const replyTo = ref(null)
const newMessagesCount = ref(0)
const isUserNearBottom = ref(true)
function updateNearBottom() {
@@ -127,6 +142,9 @@ function updateNearBottom() {
if (!el) return
const threshold = 40 // px
isUserNearBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight <= threshold
if (isUserNearBottom.value) {
newMessagesCount.value = 0
}
}
const hasMoreMessages = computed(() => currentPage.value < totalPages.value - 1)
@@ -170,6 +188,11 @@ function scrollToBottomInstant() {
el.scrollTop = el.scrollHeight
}
function handleScrollToBottom() {
scrollToBottomSmooth()
newMessagesCount.value = 0
}
async function fetchMessages(page = 0) {
if (page === 0) {
loading.value = true
@@ -301,6 +324,7 @@ async function sendMessage(content, clearInput) {
await nextTick()
// 仅“发送消息成功后”才平滑滚动到底部
scrollToBottomSmooth()
newMessagesCount.value = 0
} catch (e) {
toast.error(e.message)
} finally {
@@ -373,6 +397,8 @@ const subscribeToConversation = () => {
if (isUserNearBottom.value) {
scrollToBottomSmooth()
} else {
newMessagesCount.value += 1
}
} catch (e) {
console.error('Failed to parse websocket message', e)
@@ -454,7 +480,6 @@ function goBack() {
}
.chat-container.float {
height: 100vh;
}
.chat-header {
@@ -555,6 +580,25 @@ function goBack() {
gap: 10px;
}
.new-message-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 5px;
cursor: pointer;
border: 1px solid var(--normal-border-color);
border-radius: 20px;
padding: 3px 6px;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
width: fit-content;
position: absolute;
bottom: calc(100% + 20px);
left: 50%;
transform: translateX(-50%);
z-index: 10;
background-color: var(--background-color);
}
.user-name {
font-size: 14px;
font-weight: 600;
@@ -585,11 +629,6 @@ function goBack() {
border-bottom-left-radius: 4px;
}
.message-input-area {
margin-left: 20px;
margin-right: 20px;
}
.loading-container {
display: flex;
justify-content: center;
@@ -606,6 +645,19 @@ function goBack() {
.message-input-area {
margin-left: 10px;
margin-right: 10px;
position: relative;
}
.reply-icon {
color: var(--primary-color);
margin-right: 5px;
}
.reply-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 5px;
}
.reply-preview {
@@ -614,12 +666,19 @@ function goBack() {
border-left: 5px solid var(--primary-color);
margin-bottom: 5px;
font-size: 13px;
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
}
.reply-header {
display: flex;
flex-direction: row;
align-items: center;
}
.reply-author {
font-weight: bold;
margin-bottom: 2px;
opacity: 0.5;
}
.reply-btn {
@@ -634,7 +693,7 @@ function goBack() {
}
.active-reply {
background-color: var(--bg-color-soft);
background-color: var(--normal-light-background-color);
padding: 5px 10px;
border-left: 5px solid var(--primary-color);
margin-bottom: 5px;

View File

@@ -419,7 +419,7 @@ function minimize() {
}
.conversation-item:hover {
background-color: var(--menu-selected-background-color);
background-color: var(--normal-light-background-color);
}
.conversation-avatar {

View File

@@ -73,6 +73,7 @@ import {
RobotOne,
Server,
Protection,
DoubleDown,
} from '@icon-park/vue-next'
export default defineNuxtPlugin((nuxtApp) => {
@@ -149,4 +150,5 @@ export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('RobotOne', RobotOne)
nuxtApp.vueApp.component('ServerIcon', Server)
nuxtApp.vueApp.component('Protection', Protection)
nuxtApp.vueApp.component('DoubleDown', DoubleDown)
})