- 数据库:添加is_hot和hot_time字段 - Service层:实现toggleHot和getHotWorks方法 - 管理端API:添加设置热门和查询热门列表接口 - 用户端API:添加获取热门作品列表接口 - 实体类:更新Works和WorksResponse添加热门字段 - 文档:创建功能实现说明文档 后续需要: - 后台管理界面(Vue)添加热门设置按钮 - Android App添加热门Tab页
315 lines
8.9 KiB
Java
315 lines
8.9 KiB
Java
package com.example.livestreaming;
|
||
|
||
import com.example.livestreaming.net.MessageReaction;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.UUID;
|
||
|
||
public class ChatMessage {
|
||
public enum MessageStatus {
|
||
SENDING, // 发送中
|
||
SENT, // 已发送
|
||
READ // 已读
|
||
}
|
||
|
||
public enum MessageType {
|
||
TEXT, // 文本消息
|
||
IMAGE, // 图片消息
|
||
VOICE, // 语音消息
|
||
BURN_IMAGE
|
||
}
|
||
|
||
private String messageId;
|
||
private String username;
|
||
private String message; // 文本消息内容
|
||
private long timestamp;
|
||
private boolean isSystemMessage;
|
||
private boolean isGiftMessage; // 是否是礼物消息
|
||
private boolean isOutgoing; // 是否是自己发送的消息
|
||
private MessageStatus status;
|
||
private String avatarUrl; // 发送者头像 URL,后续从后端获取
|
||
|
||
// 新增字段:消息类型和媒体相关
|
||
private MessageType messageType; // 消息类型
|
||
private String mediaUrl; // 图片/语音的 URL(从后端获取)
|
||
private String localMediaPath; // 本地图片/语音路径(发送前使用)
|
||
private int voiceDuration; // 语音时长(秒)
|
||
private int imageWidth; // 图片宽度
|
||
private int imageHeight; // 图片高度
|
||
|
||
private Integer burnSeconds;
|
||
private Long viewedAt;
|
||
private Long burnAt;
|
||
private Boolean burned;
|
||
|
||
// 表情回应相关字段
|
||
private List<MessageReaction> reactions; // 表情回应列表
|
||
|
||
// 文本消息构造函数
|
||
public ChatMessage(String username, String message) {
|
||
this.messageId = UUID.randomUUID().toString();
|
||
this.username = username;
|
||
this.message = message;
|
||
this.timestamp = System.currentTimeMillis();
|
||
this.isSystemMessage = false;
|
||
this.isGiftMessage = false;
|
||
this.messageType = MessageType.TEXT;
|
||
// 如果是自己发送的消息,初始状态为发送中
|
||
this.isOutgoing = "我".equals(username);
|
||
this.status = this.isOutgoing ? MessageStatus.SENDING : MessageStatus.SENT;
|
||
}
|
||
|
||
// 系统消息构造函数
|
||
public ChatMessage(String message, boolean isSystemMessage) {
|
||
this.messageId = UUID.randomUUID().toString();
|
||
this.message = message;
|
||
this.timestamp = System.currentTimeMillis();
|
||
this.isSystemMessage = isSystemMessage;
|
||
this.isGiftMessage = false;
|
||
this.username = isSystemMessage ? "系统" : "匿名用户";
|
||
this.status = MessageStatus.SENT; // 系统消息默认已发送
|
||
this.messageType = MessageType.TEXT;
|
||
}
|
||
|
||
// 礼物消息构造函数
|
||
public ChatMessage(String username, String message, boolean isGiftMessage) {
|
||
this.messageId = UUID.randomUUID().toString();
|
||
this.username = username;
|
||
this.message = message;
|
||
this.timestamp = System.currentTimeMillis();
|
||
this.isSystemMessage = false;
|
||
this.isGiftMessage = isGiftMessage;
|
||
this.messageType = MessageType.TEXT;
|
||
this.status = MessageStatus.SENT;
|
||
}
|
||
|
||
// 完整构造函数(从后端数据构造)
|
||
public ChatMessage(String messageId, String username, String message, long timestamp,
|
||
boolean isSystemMessage, MessageStatus status) {
|
||
this.messageId = messageId;
|
||
this.username = username;
|
||
this.message = message;
|
||
this.timestamp = timestamp;
|
||
this.isSystemMessage = isSystemMessage;
|
||
this.status = status;
|
||
this.messageType = MessageType.TEXT;
|
||
this.isOutgoing = "我".equals(username);
|
||
}
|
||
|
||
// 完整构造函数(从后端数据构造,带 isOutgoing 参数)
|
||
public ChatMessage(String messageId, String username, String message, long timestamp,
|
||
boolean isSystemMessage, MessageStatus status, boolean isOutgoing) {
|
||
this.messageId = messageId;
|
||
this.username = username;
|
||
this.message = message;
|
||
this.timestamp = timestamp;
|
||
this.isSystemMessage = isSystemMessage;
|
||
this.status = status;
|
||
this.messageType = MessageType.TEXT;
|
||
this.isOutgoing = isOutgoing;
|
||
}
|
||
|
||
// 图片消息构造函数
|
||
public static ChatMessage createImageMessage(String username, String localPath) {
|
||
ChatMessage msg = new ChatMessage(username, "");
|
||
msg.messageType = MessageType.IMAGE;
|
||
msg.localMediaPath = localPath;
|
||
msg.status = "我".equals(username) ? MessageStatus.SENDING : MessageStatus.SENT;
|
||
return msg;
|
||
}
|
||
|
||
// 语音消息构造函数
|
||
public static ChatMessage createVoiceMessage(String username, String localPath, int duration) {
|
||
ChatMessage msg = new ChatMessage(username, "");
|
||
msg.messageType = MessageType.VOICE;
|
||
msg.localMediaPath = localPath;
|
||
msg.voiceDuration = duration;
|
||
msg.status = "我".equals(username) ? MessageStatus.SENDING : MessageStatus.SENT;
|
||
return msg;
|
||
}
|
||
|
||
public static ChatMessage createBurnImageMessage(String username, String localPath, Integer burnSeconds) {
|
||
ChatMessage msg = new ChatMessage(username, "");
|
||
msg.messageType = MessageType.BURN_IMAGE;
|
||
msg.localMediaPath = localPath;
|
||
msg.burnSeconds = burnSeconds;
|
||
msg.burned = false;
|
||
msg.status = "我".equals(username) ? MessageStatus.SENDING : MessageStatus.SENT;
|
||
return msg;
|
||
}
|
||
|
||
// Getters and Setters
|
||
public String getMessageId() {
|
||
return messageId;
|
||
}
|
||
|
||
public void setMessageId(String messageId) {
|
||
this.messageId = messageId;
|
||
}
|
||
|
||
public String getUsername() {
|
||
return username;
|
||
}
|
||
|
||
public String getMessage() {
|
||
return message;
|
||
}
|
||
|
||
public long getTimestamp() {
|
||
return timestamp;
|
||
}
|
||
|
||
public boolean isSystemMessage() {
|
||
return isSystemMessage;
|
||
}
|
||
|
||
public boolean isGiftMessage() {
|
||
return isGiftMessage;
|
||
}
|
||
|
||
public void setGiftMessage(boolean giftMessage) {
|
||
isGiftMessage = giftMessage;
|
||
}
|
||
|
||
public boolean isOutgoing() {
|
||
return isOutgoing;
|
||
}
|
||
|
||
public void setOutgoing(boolean outgoing) {
|
||
isOutgoing = outgoing;
|
||
}
|
||
|
||
public MessageStatus getStatus() {
|
||
return status;
|
||
}
|
||
|
||
public void setStatus(MessageStatus status) {
|
||
this.status = status;
|
||
}
|
||
|
||
public void setUsername(String username) {
|
||
this.username = username;
|
||
}
|
||
|
||
public void setMessage(String message) {
|
||
this.message = message;
|
||
}
|
||
|
||
public void setTimestamp(long timestamp) {
|
||
this.timestamp = timestamp;
|
||
}
|
||
|
||
public void setSystemMessage(boolean systemMessage) {
|
||
isSystemMessage = systemMessage;
|
||
}
|
||
|
||
public String getAvatarUrl() {
|
||
return avatarUrl;
|
||
}
|
||
|
||
public void setAvatarUrl(String avatarUrl) {
|
||
this.avatarUrl = avatarUrl;
|
||
}
|
||
|
||
public MessageType getMessageType() {
|
||
return messageType;
|
||
}
|
||
|
||
public void setMessageType(MessageType messageType) {
|
||
this.messageType = messageType;
|
||
}
|
||
|
||
public String getMediaUrl() {
|
||
return mediaUrl;
|
||
}
|
||
|
||
public void setMediaUrl(String mediaUrl) {
|
||
this.mediaUrl = mediaUrl;
|
||
}
|
||
|
||
public String getLocalMediaPath() {
|
||
return localMediaPath;
|
||
}
|
||
|
||
public void setLocalMediaPath(String localMediaPath) {
|
||
this.localMediaPath = localMediaPath;
|
||
}
|
||
|
||
public int getVoiceDuration() {
|
||
return voiceDuration;
|
||
}
|
||
|
||
public void setVoiceDuration(int voiceDuration) {
|
||
this.voiceDuration = voiceDuration;
|
||
}
|
||
|
||
public int getImageWidth() {
|
||
return imageWidth;
|
||
}
|
||
|
||
public void setImageWidth(int imageWidth) {
|
||
this.imageWidth = imageWidth;
|
||
}
|
||
|
||
public int getImageHeight() {
|
||
return imageHeight;
|
||
}
|
||
|
||
public void setImageHeight(int imageHeight) {
|
||
this.imageHeight = imageHeight;
|
||
}
|
||
|
||
public Integer getBurnSeconds() {
|
||
return burnSeconds;
|
||
}
|
||
|
||
public void setBurnSeconds(Integer burnSeconds) {
|
||
this.burnSeconds = burnSeconds;
|
||
}
|
||
|
||
public Long getViewedAt() {
|
||
return viewedAt;
|
||
}
|
||
|
||
public void setViewedAt(Long viewedAt) {
|
||
this.viewedAt = viewedAt;
|
||
}
|
||
|
||
public Long getBurnAt() {
|
||
return burnAt;
|
||
}
|
||
|
||
public void setBurnAt(Long burnAt) {
|
||
this.burnAt = burnAt;
|
||
}
|
||
|
||
public Boolean getBurned() {
|
||
return burned;
|
||
}
|
||
|
||
public void setBurned(Boolean burned) {
|
||
this.burned = burned;
|
||
}
|
||
|
||
public List<MessageReaction> getReactions() {
|
||
return reactions;
|
||
}
|
||
|
||
public void setReactions(List<MessageReaction> reactions) {
|
||
this.reactions = reactions;
|
||
}
|
||
|
||
public void addReaction(MessageReaction reaction) {
|
||
if (this.reactions == null) {
|
||
this.reactions = new ArrayList<>();
|
||
}
|
||
this.reactions.add(reaction);
|
||
}
|
||
|
||
public void removeReaction(String emoji) {
|
||
if (this.reactions != null) {
|
||
this.reactions.removeIf(r -> r.getEmoji().equals(emoji));
|
||
}
|
||
}
|
||
} |