mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-04 02:50:59 +08:00
Compare commits
20 Commits
feature/da
...
codex/add-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09c019e70b | ||
|
|
d2bd949ac8 | ||
|
|
605654ec99 | ||
|
|
88127fcf34 | ||
|
|
0a82f0036b | ||
|
|
3a979277e4 | ||
|
|
1c582fbbf1 | ||
|
|
92452da19a | ||
|
|
a2ccaae7aa | ||
|
|
23371d4433 | ||
|
|
e05d65cf49 | ||
|
|
aaf9b35a45 | ||
|
|
61c0336a78 | ||
|
|
69c913394f | ||
|
|
0ed9ad2f2a | ||
|
|
67e912381b | ||
|
|
a6a1c72a37 | ||
|
|
d77baa8a93 | ||
|
|
fce4832407 | ||
|
|
91c8cc9607 |
@@ -0,0 +1,35 @@
|
|||||||
|
package com.openisle.config;
|
||||||
|
|
||||||
|
import com.openisle.model.Channel;
|
||||||
|
import com.openisle.model.MessageConversation;
|
||||||
|
import com.openisle.repository.ChannelRepository;
|
||||||
|
import com.openisle.repository.MessageConversationRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ChannelInitializer implements CommandLineRunner {
|
||||||
|
private final ChannelRepository channelRepository;
|
||||||
|
private final MessageConversationRepository conversationRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) {
|
||||||
|
if (channelRepository.count() == 0) {
|
||||||
|
createChannel("吹水群", "闲聊讨论", "/default-avatar.svg");
|
||||||
|
createChannel("技术讨论群", "技术交流", "/default-avatar.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createChannel(String name, String description, String avatar) {
|
||||||
|
MessageConversation conversation = new MessageConversation();
|
||||||
|
conversation = conversationRepository.save(conversation);
|
||||||
|
Channel channel = new Channel();
|
||||||
|
channel.setName(name);
|
||||||
|
channel.setDescription(description);
|
||||||
|
channel.setAvatar(avatar);
|
||||||
|
channel.setConversation(conversation);
|
||||||
|
channelRepository.save(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,19 +92,20 @@ public class SecurityConfig {
|
|||||||
cfg.setAllowedHeaders(List.of("*"));
|
cfg.setAllowedHeaders(List.of("*"));
|
||||||
cfg.setAllowCredentials(true);
|
cfg.setAllowCredentials(true);
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
source.registerCorsConfiguration("/**", cfg);
|
source.registerCorsConfiguration("/api/**", cfg);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.csrf(csrf -> csrf.disable())
|
http.csrf(csrf -> csrf.disable())
|
||||||
.cors(Customizer.withDefaults()) // 让 Spring 自带 CorsFilter 处理预检
|
.cors(Customizer.withDefaults())
|
||||||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.headers(h -> h.frameOptions(f -> f.sameOrigin()))
|
||||||
|
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.exceptionHandling(eh -> eh.accessDeniedHandler(customAccessDeniedHandler))
|
.exceptionHandling(eh -> eh.accessDeniedHandler(customAccessDeniedHandler))
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||||
.requestMatchers("/ws/**").permitAll()
|
.requestMatchers("/api/ws/**", "/api/sockjs/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.POST, "/api/auth/**").permitAll()
|
.requestMatchers(HttpMethod.POST, "/api/auth/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/api/posts/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/api/posts/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/api/comments/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/api/comments/**").permitAll()
|
||||||
@@ -173,7 +174,8 @@ public class SecurityConfig {
|
|||||||
response.getWriter().write("{\"error\": \"Invalid or expired token\"}");
|
response.getWriter().write("{\"error\": \"Invalid or expired token\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!uri.startsWith("/api/auth") && !publicGet && !uri.startsWith("/ws")) {
|
} else if (!uri.startsWith("/api/auth") && !publicGet
|
||||||
|
&& !uri.startsWith("/api/ws") && !uri.startsWith("/api/sockjs")) {
|
||||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
response.getWriter().write("{\"error\": \"Missing token\"}");
|
response.getWriter().write("{\"error\": \"Missing token\"}");
|
||||||
|
|||||||
@@ -41,28 +41,38 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
// Registers the "/ws" endpoint, enabling SockJS fallback options so that alternate transports may be used if WebSocket is not available.
|
// 1) 原生 WebSocket(不带 SockJS)
|
||||||
registry.addEndpoint("/ws")
|
registry.addEndpoint("/api/ws")
|
||||||
// 安全改进:使用具体的允许源,而不是通配符
|
.setAllowedOriginPatterns(
|
||||||
.setAllowedOrigins(
|
"https://staging.open-isle.com",
|
||||||
"http://127.0.0.1:8080",
|
"https://www.staging.open-isle.com",
|
||||||
"http://127.0.0.1:3000",
|
websiteUrl,
|
||||||
"http://127.0.0.1:3001",
|
websiteUrl.replace("://www.", "://"),
|
||||||
"http://127.0.0.1",
|
"http://localhost:*",
|
||||||
"http://localhost:8080",
|
"http://127.0.0.1:*",
|
||||||
"http://localhost:3000",
|
"http://192.168.7.98:*",
|
||||||
"http://localhost:3001",
|
"http://30.211.97.238:*"
|
||||||
"http://localhost",
|
);
|
||||||
"http://30.211.97.238:3000",
|
|
||||||
"http://30.211.97.238",
|
// 2) SockJS 回退:单独路径
|
||||||
"http://192.168.7.98",
|
registry.addEndpoint("/api/sockjs")
|
||||||
"http://192.168.7.98:3000",
|
.setAllowedOriginPatterns(
|
||||||
websiteUrl,
|
"https://staging.open-isle.com",
|
||||||
websiteUrl.replace("://www.", "://")
|
"https://www.staging.open-isle.com",
|
||||||
|
websiteUrl,
|
||||||
|
websiteUrl.replace("://www.", "://"),
|
||||||
|
"http://localhost:*",
|
||||||
|
"http://127.0.0.1:*",
|
||||||
|
"http://192.168.7.98:*",
|
||||||
|
"http://30.211.97.238:*"
|
||||||
)
|
)
|
||||||
.withSockJS();
|
.withSockJS()
|
||||||
|
.setWebSocketEnabled(true)
|
||||||
|
.setSessionCookieNeeded(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureClientInboundChannel(ChannelRegistration registration) {
|
public void configureClientInboundChannel(ChannelRegistration registration) {
|
||||||
registration.interceptors(new ChannelInterceptor() {
|
registration.interceptors(new ChannelInterceptor() {
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package com.openisle.controller;
|
||||||
|
|
||||||
|
import com.openisle.dto.ChannelDto;
|
||||||
|
import com.openisle.model.Channel;
|
||||||
|
import com.openisle.model.MessageParticipant;
|
||||||
|
import com.openisle.model.MessageConversation;
|
||||||
|
import com.openisle.model.User;
|
||||||
|
import com.openisle.repository.ChannelRepository;
|
||||||
|
import com.openisle.repository.MessageParticipantRepository;
|
||||||
|
import com.openisle.repository.UserRepository;
|
||||||
|
import com.openisle.repository.MessageRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/channels")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ChannelController {
|
||||||
|
private final ChannelRepository channelRepository;
|
||||||
|
private final MessageParticipantRepository participantRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final MessageRepository messageRepository;
|
||||||
|
|
||||||
|
private Long getCurrentUserId(Authentication auth) {
|
||||||
|
User user = userRepository.findByUsername(auth.getName()).orElseThrow(() -> new IllegalArgumentException("User not found"));
|
||||||
|
return user.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<ChannelDto>> listChannels(Authentication auth) {
|
||||||
|
Long userId = auth == null ? null : getCurrentUserId(auth);
|
||||||
|
List<ChannelDto> channels = channelRepository.findAll().stream()
|
||||||
|
.map(c -> toDto(c, userId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return ResponseEntity.ok(channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/join")
|
||||||
|
public ResponseEntity<Void> joinChannel(@PathVariable Long id, Authentication auth) {
|
||||||
|
Channel channel = channelRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Channel not found"));
|
||||||
|
Long userId = getCurrentUserId(auth);
|
||||||
|
boolean exists = channel.getConversation().getParticipants().stream().anyMatch(p -> p.getUser().getId().equals(userId));
|
||||||
|
if (!exists) {
|
||||||
|
MessageParticipant participant = new MessageParticipant();
|
||||||
|
participant.setConversation(channel.getConversation());
|
||||||
|
participant.setUser(userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")));
|
||||||
|
participantRepository.save(participant);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelDto toDto(Channel channel, Long userId) {
|
||||||
|
ChannelDto dto = new ChannelDto();
|
||||||
|
dto.setId(channel.getId());
|
||||||
|
dto.setName(channel.getName());
|
||||||
|
dto.setDescription(channel.getDescription());
|
||||||
|
dto.setAvatar(channel.getAvatar());
|
||||||
|
if (channel.getConversation() != null) {
|
||||||
|
MessageConversation conversation = channel.getConversation();
|
||||||
|
dto.setConversationId(conversation.getId());
|
||||||
|
dto.setMemberCount(conversation.getParticipants().size());
|
||||||
|
if (userId != null) {
|
||||||
|
MessageParticipant self = conversation.getParticipants().stream()
|
||||||
|
.filter(p -> p.getUser().getId().equals(userId))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
if (self != null) {
|
||||||
|
var lastRead = self.getLastReadAt();
|
||||||
|
dto.setUnreadCount(messageRepository
|
||||||
|
.countByConversationIdAndCreatedAtAfterAndSenderIdNot(conversation.getId(),
|
||||||
|
lastRead == null ? java.time.LocalDateTime.of(1970,1,1,0,0) : lastRead,
|
||||||
|
userId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,14 @@ public class MessageController {
|
|||||||
return ResponseEntity.ok(toDto(message));
|
return ResponseEntity.ok(toDto(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/conversations/{conversationId}/messages")
|
||||||
|
public ResponseEntity<MessageDto> sendMessageToConversation(@PathVariable Long conversationId,
|
||||||
|
@RequestBody ContentRequest req,
|
||||||
|
Authentication auth) {
|
||||||
|
Message message = messageService.sendMessageToConversation(getCurrentUserId(auth), conversationId, req.getContent());
|
||||||
|
return ResponseEntity.ok(toDto(message));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/conversations/{conversationId}/read")
|
@PostMapping("/conversations/{conversationId}/read")
|
||||||
public ResponseEntity<Void> markAsRead(@PathVariable Long conversationId, Authentication auth) {
|
public ResponseEntity<Void> markAsRead(@PathVariable Long conversationId, Authentication auth) {
|
||||||
messageService.markConversationAsRead(conversationId, getCurrentUserId(auth));
|
messageService.markConversationAsRead(conversationId, getCurrentUserId(auth));
|
||||||
@@ -114,4 +122,16 @@ public class MessageController {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ContentRequest {
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
16
backend/src/main/java/com/openisle/dto/ChannelDto.java
Normal file
16
backend/src/main/java/com/openisle/dto/ChannelDto.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.openisle.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class ChannelDto {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String avatar;
|
||||||
|
private Long conversationId;
|
||||||
|
private int memberCount;
|
||||||
|
private long unreadCount;
|
||||||
|
}
|
||||||
@@ -10,4 +10,5 @@ public class ConversationDetailDto {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private List<UserSummaryDto> participants;
|
private List<UserSummaryDto> participants;
|
||||||
private Page<MessageDto> messages;
|
private Page<MessageDto> messages;
|
||||||
|
private ChannelDto channel;
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.openisle.dto;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -14,4 +15,5 @@ public class ConversationDto {
|
|||||||
private List<UserSummaryDto> participants;
|
private List<UserSummaryDto> participants;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private long unreadCount;
|
private long unreadCount;
|
||||||
|
private ChannelDto channel;
|
||||||
}
|
}
|
||||||
27
backend/src/main/java/com/openisle/model/Channel.java
Normal file
27
backend/src/main/java/com/openisle/model/Channel.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package com.openisle.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "channels")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Channel {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "conversation_id")
|
||||||
|
private MessageConversation conversation;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.openisle.repository;
|
||||||
|
|
||||||
|
import com.openisle.model.Channel;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface ChannelRepository extends JpaRepository<Channel, Long> {
|
||||||
|
Optional<Channel> findByConversationId(Long conversationId);
|
||||||
|
}
|
||||||
@@ -8,6 +8,9 @@ import com.openisle.repository.MessageConversationRepository;
|
|||||||
import com.openisle.repository.MessageParticipantRepository;
|
import com.openisle.repository.MessageParticipantRepository;
|
||||||
import com.openisle.repository.MessageRepository;
|
import com.openisle.repository.MessageRepository;
|
||||||
import com.openisle.repository.UserRepository;
|
import com.openisle.repository.UserRepository;
|
||||||
|
import com.openisle.repository.ChannelRepository;
|
||||||
|
import com.openisle.model.Channel;
|
||||||
|
import com.openisle.dto.ChannelDto;
|
||||||
import com.openisle.dto.ConversationDetailDto;
|
import com.openisle.dto.ConversationDetailDto;
|
||||||
import com.openisle.dto.ConversationDto;
|
import com.openisle.dto.ConversationDto;
|
||||||
import com.openisle.dto.MessageDto;
|
import com.openisle.dto.MessageDto;
|
||||||
@@ -33,6 +36,7 @@ public class MessageService {
|
|||||||
private final MessageConversationRepository conversationRepository;
|
private final MessageConversationRepository conversationRepository;
|
||||||
private final MessageParticipantRepository participantRepository;
|
private final MessageParticipantRepository participantRepository;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final ChannelRepository channelRepository;
|
||||||
private final SimpMessagingTemplate messagingTemplate;
|
private final SimpMessagingTemplate messagingTemplate;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -82,6 +86,39 @@ public class MessageService {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Message sendMessageToConversation(Long senderId, Long conversationId, String content) {
|
||||||
|
User sender = userRepository.findById(senderId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Sender not found"));
|
||||||
|
MessageConversation conversation = conversationRepository.findById(conversationId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Conversation not found"));
|
||||||
|
|
||||||
|
Message message = new Message();
|
||||||
|
message.setConversation(conversation);
|
||||||
|
message.setSender(sender);
|
||||||
|
message.setContent(content);
|
||||||
|
message = messageRepository.save(message);
|
||||||
|
|
||||||
|
conversation.setLastMessage(message);
|
||||||
|
conversationRepository.save(conversation);
|
||||||
|
|
||||||
|
MessageDto messageDto = toDto(message);
|
||||||
|
String conversationDestination = "/topic/conversation/" + conversation.getId();
|
||||||
|
messagingTemplate.convertAndSend(conversationDestination, messageDto);
|
||||||
|
|
||||||
|
conversation.getParticipants().forEach(p -> {
|
||||||
|
if (!p.getUser().getId().equals(senderId)) {
|
||||||
|
String userDestination = "/topic/user/" + p.getUser().getId() + "/messages";
|
||||||
|
messagingTemplate.convertAndSend(userDestination, messageDto);
|
||||||
|
long unreadCount = getUnreadMessageCount(p.getUser().getId());
|
||||||
|
String recipientUsername = p.getUser().getUsername();
|
||||||
|
messagingTemplate.convertAndSendToUser(recipientUsername, "/queue/unread-count", unreadCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
private MessageDto toDto(Message message) {
|
private MessageDto toDto(Message message) {
|
||||||
MessageDto dto = new MessageDto();
|
MessageDto dto = new MessageDto();
|
||||||
dto.setId(message.getId());
|
dto.setId(message.getId());
|
||||||
@@ -98,6 +135,19 @@ public class MessageService {
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ChannelDto toDto(Channel channel) {
|
||||||
|
ChannelDto dto = new ChannelDto();
|
||||||
|
dto.setId(channel.getId());
|
||||||
|
dto.setName(channel.getName());
|
||||||
|
dto.setDescription(channel.getDescription());
|
||||||
|
dto.setAvatar(channel.getAvatar());
|
||||||
|
if (channel.getConversation() != null) {
|
||||||
|
dto.setConversationId(channel.getConversation().getId());
|
||||||
|
dto.setMemberCount(channel.getConversation().getParticipants().size());
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
public MessageConversation findOrCreateConversation(Long user1Id, Long user2Id) {
|
public MessageConversation findOrCreateConversation(Long user1Id, Long user2Id) {
|
||||||
User user1 = userRepository.findById(user1Id)
|
User user1 = userRepository.findById(user1Id)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("User1 not found"));
|
.orElseThrow(() -> new IllegalArgumentException("User1 not found"));
|
||||||
@@ -154,6 +204,9 @@ public class MessageService {
|
|||||||
})
|
})
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
channelRepository.findByConversationId(conversation.getId())
|
||||||
|
.ifPresent(channel -> dto.setChannel(toDto(channel)));
|
||||||
|
|
||||||
MessageParticipant self = conversation.getParticipants().stream()
|
MessageParticipant self = conversation.getParticipants().stream()
|
||||||
.filter(p -> p.getUser().getId().equals(userId))
|
.filter(p -> p.getUser().getId().equals(userId))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
@@ -191,6 +244,8 @@ public class MessageService {
|
|||||||
detailDto.setId(conversation.getId());
|
detailDto.setId(conversation.getId());
|
||||||
detailDto.setParticipants(participants);
|
detailDto.setParticipants(participants);
|
||||||
detailDto.setMessages(messageDtoPage);
|
detailDto.setMessages(messageDtoPage);
|
||||||
|
channelRepository.findByConversationId(conversation.getId())
|
||||||
|
.ifPresent(channel -> detailDto.setChannel(toDto(channel)));
|
||||||
|
|
||||||
return detailDto;
|
return detailDto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +1,83 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue'
|
||||||
import { Client } from '@stomp/stompjs';
|
import { Client } from '@stomp/stompjs'
|
||||||
import SockJS from 'sockjs-client/dist/sockjs.min.js';
|
import SockJS from 'sockjs-client/dist/sockjs.min.js'
|
||||||
import { useRuntimeConfig } from '#app';
|
import { useRuntimeConfig } from '#app'
|
||||||
|
|
||||||
const client = ref(null);
|
const client = ref(null)
|
||||||
const isConnected = ref(false);
|
const isConnected = ref(false)
|
||||||
|
|
||||||
const connect = (token) => {
|
const connect = (token) => {
|
||||||
if (isConnected.value) {
|
if (isConnected.value) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl;
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
const socketUrl = `${API_BASE_URL}/ws`;
|
const socketUrl = `${API_BASE_URL}/api/sockjs`
|
||||||
|
|
||||||
const socket = new SockJS(socketUrl);
|
const socket = new SockJS(socketUrl)
|
||||||
const stompClient = new Client({
|
const stompClient = new Client({
|
||||||
webSocketFactory: () => socket,
|
webSocketFactory: () => socket,
|
||||||
connectHeaders: {
|
connectHeaders: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
debug: function (str) {
|
debug: function (str) {},
|
||||||
},
|
reconnectDelay: 5000,
|
||||||
reconnectDelay: 5000,
|
heartbeatIncoming: 4000,
|
||||||
heartbeatIncoming: 4000,
|
heartbeatOutgoing: 4000,
|
||||||
heartbeatOutgoing: 4000,
|
})
|
||||||
});
|
|
||||||
|
|
||||||
stompClient.onConnect = (frame) => {
|
stompClient.onConnect = (frame) => {
|
||||||
isConnected.value = true;
|
isConnected.value = true
|
||||||
};
|
}
|
||||||
|
|
||||||
stompClient.onStompError = (frame) => {
|
stompClient.onStompError = (frame) => {
|
||||||
console.error('WebSocket STOMP error:', frame);
|
console.error('WebSocket STOMP error:', frame)
|
||||||
};
|
}
|
||||||
|
|
||||||
stompClient.activate();
|
stompClient.activate()
|
||||||
client.value = stompClient;
|
client.value = stompClient
|
||||||
};
|
}
|
||||||
|
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
if (client.value) {
|
if (client.value) {
|
||||||
isConnected.value = false;
|
isConnected.value = false
|
||||||
client.value.deactivate();
|
client.value.deactivate()
|
||||||
client.value = null;
|
client.value = null
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const subscribe = (destination, callback) => {
|
const subscribe = (destination, callback) => {
|
||||||
|
if (!isConnected.value || !client.value || !client.value.connected) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
if (!isConnected.value || !client.value || !client.value.connected) {
|
try {
|
||||||
return null;
|
const subscription = client.value.subscribe(destination, (message) => {
|
||||||
}
|
try {
|
||||||
|
if (destination.includes('/queue/unread-count')) {
|
||||||
|
callback(message)
|
||||||
|
} else {
|
||||||
|
const parsedMessage = JSON.parse(message.body)
|
||||||
|
callback(parsedMessage)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
callback(message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
return subscription
|
||||||
const subscription = client.value.subscribe(destination, (message) => {
|
} catch (error) {
|
||||||
try {
|
return null
|
||||||
if (destination.includes('/queue/unread-count')) {
|
}
|
||||||
callback(message);
|
}
|
||||||
} else {
|
|
||||||
const parsedMessage = JSON.parse(message.body);
|
|
||||||
callback(parsedMessage);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
callback(message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return subscription;
|
|
||||||
} catch (error) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function useWebSocket() {
|
export function useWebSocket() {
|
||||||
return {
|
return {
|
||||||
client,
|
client,
|
||||||
isConnected,
|
isConnected,
|
||||||
connect,
|
connect,
|
||||||
disconnect,
|
disconnect,
|
||||||
subscribe,
|
subscribe,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="chat-container">
|
<div class="chat-container">
|
||||||
<div v-if="!loading && otherParticipant" class="chat-header">
|
<div v-if="!loading" class="chat-header">
|
||||||
<NuxtLink to="/message-box" class="back-button">
|
<NuxtLink to="/message-box" class="back-button">
|
||||||
<i class="fas fa-arrow-left"></i>
|
<i class="fas fa-arrow-left"></i>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<h2 class="participant-name">{{ otherParticipant.username }}</h2>
|
<h2 class="participant-name">{{ channel ? channel.name : otherParticipant?.username }}</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="messages-list" ref="messagesListEl">
|
<div class="messages-list" ref="messagesListEl">
|
||||||
@@ -65,6 +65,7 @@ let subscription = null
|
|||||||
|
|
||||||
const messages = ref([])
|
const messages = ref([])
|
||||||
const participants = ref([])
|
const participants = ref([])
|
||||||
|
const channel = ref(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const sending = ref(false)
|
const sending = ref(false)
|
||||||
const error = ref(null)
|
const error = ref(null)
|
||||||
@@ -126,6 +127,7 @@ async function fetchMessages(page = 0) {
|
|||||||
|
|
||||||
if (page === 0) {
|
if (page === 0) {
|
||||||
participants.value = conversationData.participants
|
participants.value = conversationData.participants
|
||||||
|
channel.value = conversationData.channel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since the backend sorts by descending, we need to reverse for correct chat order
|
// Since the backend sorts by descending, we need to reverse for correct chat order
|
||||||
@@ -173,33 +175,43 @@ async function loadMoreMessages() {
|
|||||||
async function sendMessage(content, clearInput) {
|
async function sendMessage(content, clearInput) {
|
||||||
if (!content.trim()) return
|
if (!content.trim()) return
|
||||||
|
|
||||||
const recipient = otherParticipant.value
|
|
||||||
if (!recipient) {
|
|
||||||
toast.error('无法确定收信人')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
sending.value = true
|
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
|
sending.value = true
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/messages`, {
|
let url
|
||||||
|
let body
|
||||||
|
if (channel.value) {
|
||||||
|
url = `${API_BASE_URL}/api/messages/conversations/${conversationId}/messages`
|
||||||
|
body = { content: content }
|
||||||
|
} else {
|
||||||
|
const recipient = otherParticipant.value
|
||||||
|
if (!recipient) {
|
||||||
|
toast.error('无法确定收信人')
|
||||||
|
sending.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
url = `${API_BASE_URL}/api/messages`
|
||||||
|
body = { recipientId: recipient.id, content: content }
|
||||||
|
}
|
||||||
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(body),
|
||||||
recipientId: recipient.id,
|
|
||||||
content: content,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
if (!response.ok) throw new Error('发送失败')
|
if (!response.ok) throw new Error('发送失败')
|
||||||
|
|
||||||
const newMessage = await response.json()
|
const newMessage = await response.json()
|
||||||
messages.value.push(newMessage)
|
messages.value.push({
|
||||||
|
...newMessage,
|
||||||
|
src: newMessage.sender.avatar,
|
||||||
|
iconClick: () => {
|
||||||
|
navigateTo(`/users/${newMessage.sender.id}`, { replace: true })
|
||||||
|
},
|
||||||
|
})
|
||||||
clearInput()
|
clearInput()
|
||||||
|
|
||||||
// Use a more reliable scroll approach
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
}, 100)
|
}, 100)
|
||||||
@@ -277,7 +289,13 @@ watch(isConnected, (newValue) => {
|
|||||||
subscription = subscribe(`/topic/conversation/${conversationId}`, (message) => {
|
subscription = subscribe(`/topic/conversation/${conversationId}`, (message) => {
|
||||||
// 避免重复显示当前用户发送的消息
|
// 避免重复显示当前用户发送的消息
|
||||||
if (message.sender.id !== currentUser.value.id) {
|
if (message.sender.id !== currentUser.value.id) {
|
||||||
messages.value.push(message)
|
messages.value.push({
|
||||||
|
...message,
|
||||||
|
src: message.sender.avatar,
|
||||||
|
iconClick: () => {
|
||||||
|
navigateTo(`/users/${message.sender.id}`, { replace: true })
|
||||||
|
},
|
||||||
|
})
|
||||||
// 实时收到消息时自动标记为已读
|
// 实时收到消息时自动标记为已读
|
||||||
markConversationAsRead()
|
markConversationAsRead()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -445,6 +463,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.message-input-area {
|
.message-input-area {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
|
margin-right: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-container,
|
.loading-container,
|
||||||
@@ -453,4 +472,15 @@ onUnmounted(() => {
|
|||||||
padding: 50px;
|
padding: 50px;
|
||||||
color: var(--text-color-secondary);
|
color: var(--text-color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.messages-list {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-input-area {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,50 +1,105 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="messages-container">
|
<div class="messages-container">
|
||||||
<div v-if="loading" class="loading-message">
|
<div class="tabs">
|
||||||
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
<div
|
||||||
|
class="tab"
|
||||||
|
:class="{ active: activeTab === 'messages' }"
|
||||||
|
@click="activeTab = 'messages'"
|
||||||
|
>
|
||||||
|
站内信
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="tab"
|
||||||
|
:class="{ active: activeTab === 'channels' }"
|
||||||
|
@click="activeTab = 'channels'"
|
||||||
|
>
|
||||||
|
频道
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else-if="error" class="error-container">
|
<div v-if="activeTab === 'messages'">
|
||||||
<div class="error-text">{{ error }}</div>
|
<div v-if="loading" class="loading-message">
|
||||||
</div>
|
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
||||||
|
|
||||||
<div v-else-if="conversations.length === 0" class="empty-container">
|
|
||||||
<div class="empty-text">暂无会话</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
v-for="convo in conversations"
|
|
||||||
:key="convo.id"
|
|
||||||
class="conversation-item"
|
|
||||||
@click="goToConversation(convo.id)"
|
|
||||||
>
|
|
||||||
<div class="conversation-avatar">
|
|
||||||
<img
|
|
||||||
:src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
|
|
||||||
:alt="getOtherParticipant(convo)?.username || '用户'"
|
|
||||||
class="avatar-img"
|
|
||||||
@error="handleAvatarError"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="conversation-content">
|
<div v-else-if="error" class="error-container">
|
||||||
<div class="conversation-header">
|
<div class="error-text">{{ error }}</div>
|
||||||
<div class="participant-name">
|
</div>
|
||||||
{{ getOtherParticipant(convo)?.username || '未知用户' }}
|
|
||||||
</div>
|
<div v-else-if="conversations.length === 0" class="empty-container">
|
||||||
<div class="message-time">
|
<div class="empty-text">暂无会话</div>
|
||||||
{{ formatTime(convo.lastMessage?.createdAt || convo.createdAt) }}
|
</div>
|
||||||
</div>
|
|
||||||
|
<div
|
||||||
|
v-for="convo in conversations"
|
||||||
|
:key="convo.id"
|
||||||
|
class="conversation-item"
|
||||||
|
@click="goToConversation(convo.id)"
|
||||||
|
>
|
||||||
|
<div class="conversation-avatar">
|
||||||
|
<img
|
||||||
|
:src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
|
||||||
|
:alt="getOtherParticipant(convo)?.username || '用户'"
|
||||||
|
class="avatar-img"
|
||||||
|
@error="handleAvatarError"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="last-message-row">
|
<div class="conversation-content">
|
||||||
<div class="last-message">
|
<div class="conversation-header">
|
||||||
{{
|
<div class="participant-name">
|
||||||
convo.lastMessage ? stripMarkdownLength(convo.lastMessage.content, 100) : '暂无消息'
|
{{ getOtherParticipant(convo)?.username || '未知用户' }}
|
||||||
}}
|
</div>
|
||||||
|
<div class="message-time">
|
||||||
|
{{ formatTime(convo.lastMessage?.createdAt || convo.createdAt) }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="convo.unreadCount > 0" class="unread-count-badge">
|
|
||||||
{{ convo.unreadCount }}
|
<div class="last-message-row">
|
||||||
|
<div class="last-message">
|
||||||
|
{{
|
||||||
|
convo.lastMessage ? stripMarkdownLength(convo.lastMessage.content, 100) : '暂无消息'
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
<div v-if="convo.unreadCount > 0" class="unread-count-badge">
|
||||||
|
{{ convo.unreadCount }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
<div v-if="channelsLoading" class="loading-message">
|
||||||
|
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="channelsError" class="error-container">
|
||||||
|
<div class="error-text">{{ channelsError }}</div>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="channels.length === 0" class="empty-container">
|
||||||
|
<div class="empty-text">暂无频道</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="channel in channels"
|
||||||
|
:key="channel.id"
|
||||||
|
class="conversation-item"
|
||||||
|
@click="goToChannel(channel)"
|
||||||
|
>
|
||||||
|
<div class="conversation-avatar" style="position: relative">
|
||||||
|
<img
|
||||||
|
:src="channel.avatar || '/default-avatar.svg'"
|
||||||
|
:alt="channel.name"
|
||||||
|
class="avatar-img"
|
||||||
|
@error="handleAvatarError"
|
||||||
|
/>
|
||||||
|
<span v-if="channel.unreadCount > 0" class="unread-dot"></span>
|
||||||
|
</div>
|
||||||
|
<div class="conversation-content">
|
||||||
|
<div class="conversation-header">
|
||||||
|
<div class="participant-name">{{ channel.name }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="last-message-row">
|
||||||
|
<div class="last-message">{{ channel.description }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -63,9 +118,13 @@ import TimeManager from '~/utils/time'
|
|||||||
import { stripMarkdownLength } from '~/utils/markdown'
|
import { stripMarkdownLength } from '~/utils/markdown'
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
|
const activeTab = ref('messages')
|
||||||
const conversations = ref([])
|
const conversations = ref([])
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref(null)
|
const error = ref(null)
|
||||||
|
const channels = ref([])
|
||||||
|
const channelsLoading = ref(true)
|
||||||
|
const channelsError = ref(null)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const currentUser = ref(null)
|
const currentUser = ref(null)
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -88,7 +147,7 @@ async function fetchConversations() {
|
|||||||
throw new Error(`HTTP error! status: ${response.status}`)
|
throw new Error(`HTTP error! status: ${response.status}`)
|
||||||
}
|
}
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
conversations.value = data
|
conversations.value = data.filter((c) => !c.channel)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = '无法加载会话列表。'
|
error.value = '无法加载会话列表。'
|
||||||
} finally {
|
} finally {
|
||||||
@@ -96,6 +155,28 @@ async function fetchConversations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchChannels() {
|
||||||
|
const token = getToken()
|
||||||
|
if (!token) {
|
||||||
|
toast.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/channels`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
})
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`)
|
||||||
|
}
|
||||||
|
channels.value = await response.json()
|
||||||
|
} catch (e) {
|
||||||
|
channelsError.value = '无法加载频道。'
|
||||||
|
} finally {
|
||||||
|
channelsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取对话中的另一个参与者(非当前用户)
|
// 获取对话中的另一个参与者(非当前用户)
|
||||||
function getOtherParticipant(conversation) {
|
function getOtherParticipant(conversation) {
|
||||||
if (!currentUser.value || !conversation.participants) return null
|
if (!currentUser.value || !conversation.participants) return null
|
||||||
@@ -119,6 +200,7 @@ onActivated(async () => {
|
|||||||
|
|
||||||
if (currentUser.value) {
|
if (currentUser.value) {
|
||||||
await fetchConversations()
|
await fetchConversations()
|
||||||
|
await fetchChannels()
|
||||||
refreshGlobalUnreadCount() // Refresh global count when entering the list
|
refreshGlobalUnreadCount() // Refresh global count when entering the list
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
if (token && !isConnected.value) {
|
if (token && !isConnected.value) {
|
||||||
@@ -140,6 +222,7 @@ watch(isConnected, (newValue) => {
|
|||||||
|
|
||||||
subscription = subscribe(destination, (message) => {
|
subscription = subscribe(destination, (message) => {
|
||||||
fetchConversations()
|
fetchConversations()
|
||||||
|
fetchChannels()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -154,6 +237,19 @@ onUnmounted(() => {
|
|||||||
function goToConversation(id) {
|
function goToConversation(id) {
|
||||||
router.push(`/message-box/${id}`)
|
router.push(`/message-box/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function goToChannel(channel) {
|
||||||
|
const token = getToken()
|
||||||
|
if (!token) {
|
||||||
|
toast.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await fetch(`${API_BASE_URL}/api/channels/${channel.id}/join`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
})
|
||||||
|
router.push(`/message-box/${channel.conversationId}`)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -162,6 +258,22 @@ function goToConversation(id) {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
display: flex;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab {
|
||||||
|
padding: 8px 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab.active {
|
||||||
|
border-bottom: 2px solid var(--primary-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
.loading-message {
|
.loading-message {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -280,10 +392,20 @@ function goToConversation(id) {
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.unread-dot {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
background-color: #f56c6c;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
/* 响应式设计 */
|
/* 响应式设计 */
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.messages-container {
|
.messages-container {
|
||||||
padding: 16px 12px;
|
padding: 10px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.messages-title {
|
.messages-title {
|
||||||
@@ -295,7 +417,7 @@ function goToConversation(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.conversation-item {
|
.conversation-item {
|
||||||
padding: 12px 16px;
|
padding: 6px 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar-img {
|
.avatar-img {
|
||||||
@@ -315,34 +437,4 @@ function goToConversation(id) {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 480px) {
|
|
||||||
.messages-container {
|
|
||||||
padding: 12px 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.conversations-list {
|
|
||||||
max-height: 400px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.conversation-item {
|
|
||||||
padding: 10px 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.avatar-img {
|
|
||||||
width: 36px;
|
|
||||||
height: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.conversation-avatar {
|
|
||||||
margin-right: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 大屏幕设备 */
|
|
||||||
@media (min-width: 1024px) {
|
|
||||||
.conversations-list {
|
|
||||||
max-height: 700px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user