Browse Source

用户封禁和群封禁增加提示语

master
xsx 1 year ago
parent
commit
3634be2f55
  1. 6
      im-platform/src/main/java/com/bx/implatform/vo/GroupVO.java
  2. 5
      im-platform/src/main/java/com/bx/implatform/vo/UserVO.java
  3. 10
      im-uniapp/App.vue
  4. 12
      im-uniapp/components/chat-group-readed/chat-group-readed.vue
  5. 71
      im-uniapp/pages/chat/chat-box.vue
  6. 35
      im-uniapp/store/chatStore.js
  7. 75
      im-web/src/components/chat/ChatBox.vue
  8. 2
      im-web/src/components/chat/ChatInput.vue
  9. 35
      im-web/src/store/chatStore.js
  10. 5
      im-web/src/view/Home.vue

6
im-platform/src/main/java/com/bx/implatform/vo/GroupVO.java

@ -50,5 +50,11 @@ public class GroupVO {
@Schema(description = "是否已退出")
private Boolean quit;
@Schema(description = "账号是否被封禁")
private Boolean isBanned;
@Schema(description = "被封禁原因")
private String reason;
}

5
im-platform/src/main/java/com/bx/implatform/vo/UserVO.java

@ -43,4 +43,9 @@ public class UserVO {
@Schema(description = "是否在线")
private Boolean online;
@Schema(description = "账号是否被封禁")
private Boolean isBanned;
@Schema(description = "被封禁原因")
private String reason;
}

10
im-uniapp/App.vue

@ -169,7 +169,7 @@ export default {
//
this.chatStore.openChat(chatInfo);
//
this.chatStore.insertMessage(msg);
this.chatStore.insertMessage(msg, chatInfo);
//
this.playAudioTip();
@ -192,6 +192,10 @@ export default {
}
//
if (msg.type == enums.MESSAGE_TYPE.RECEIPT) {
let chatInfo = {
type: 'GROUP',
targetId: msg.groupId
}
//
let msgInfo = {
id: msg.id,
@ -199,7 +203,7 @@ export default {
readedCount: msg.readedCount,
receiptOk: msg.receiptOk
};
this.chatStore.updateMessage(msgInfo)
this.chatStore.updateMessage(msgInfo,chatInfo)
return;
}
//
@ -259,7 +263,7 @@ export default {
//
this.chatStore.openChat(chatInfo);
//
this.chatStore.insertMessage(msg);
this.chatStore.insertMessage(msg, chatInfo);
//
this.playAudioTip();
},

12
im-uniapp/components/chat-group-readed/chat-group-readed.vue

@ -79,12 +79,18 @@ export default {
})
this.items[0] = `已读(${this.readedMembers.length})`;
this.items[1] = `未读(${this.unreadMembers.length})`;
//
this.chatStore.updateMessage({
let chatInfo = {
type: 'GROUP',
targetId: this.msgInfo.groupId
}
let msgInfo = {
id: this.msgInfo.id,
groupId: this.msgInfo.groupId,
readedCount: this.readedMembers.length
})
}
//
this.chatStore.updateMessage(msgInfo, chatInfo)
})
},
onClickItem(e) {

71
im-uniapp/pages/chat/chat-box.vue

@ -155,6 +155,11 @@ export default {
this.switchChatTabBox('none');
},
onSendRecord(data) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let msgInfo = {
content: JSON.stringify(data),
type: this.$enums.MESSAGE_TYPE.AUDIO,
@ -164,7 +169,7 @@ export default {
this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.chatStore.insertMessage(m);
this.chatStore.insertMessage(m, this.chat);
//
this.moveChatToTop();
//
@ -260,6 +265,17 @@ export default {
sendTextMessage() {
this.editorCtx.getContents({
success: (e) => {
//
this.editorCtx.clear();
this.atUserIds = [];
this.isReceipt = false;
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let sendText = this.isReceipt ? "【回执消息】" : "";
e.delta.ops.forEach((op) => {
if (op.insert.image) {
@ -286,6 +302,7 @@ export default {
}
// id
this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.chatStore.insertMessage(m, this.chat);
@ -294,10 +311,6 @@ export default {
}).finally(() => {
//
this.scrollToBottom();
//
this.atUserIds = [];
this.isReceipt = false;
this.editorCtx.clear();
});
}
})
@ -379,6 +392,11 @@ export default {
})
},
onUploadImageBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let data = {
originUrl: file.path,
thumbUrl: file.path
@ -399,7 +417,7 @@ export default {
// id
this.fillTargetId(msgInfo, this.chat.targetId);
//
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
//
this.moveChatToTop();
// file
@ -416,15 +434,20 @@ export default {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
})
},
onUploadImageFail(file, err) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail';
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
},
onUploadFileBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let data = {
name: file.name,
size: file.size,
@ -445,7 +468,7 @@ export default {
// id
this.fillTargetId(msgInfo, this.chat.targetId);
//
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
//
this.moveChatToTop();
// file
@ -467,13 +490,13 @@ export default {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
})
},
onUploadFileFail(file, res) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail';
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
},
onDeleteMessage(msgInfo) {
uni.showModal({
@ -481,7 +504,7 @@ export default {
content: '确认删除消息?',
success: (res) => {
if (!res.cancel) {
this.chatStore.deleteMessage(msgInfo);
this.chatStore.deleteMessage(msgInfo, this.chat);
uni.showToast({
title: "删除成功",
icon: "none"
@ -505,7 +528,7 @@ export default {
msgInfo.type = this.$enums.MESSAGE_TYPE.RECALL;
msgInfo.content = '你撤回了一条消息';
msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL;
this.chatStore.insertMessage(msgInfo);
this.chatStore.insertMessage(msgInfo, this.chat);
})
}
}
@ -697,6 +720,22 @@ export default {
});
// #endif
},
showBannedTip() {
let msgInfo = {
tmpId: this.generateId(),
sendId: this.mine.id,
sendTime: new Date().getTime(),
type: this.$enums.MESSAGE_TYPE.TIP_TEXT
}
if (this.chat.type == "PRIVATE") {
msgInfo.recvId = this.mine.id
msgInfo.content = "该用户已被管理员封禁,原因:" + this.friend.reason
} else {
msgInfo.groupId = this.group.id;
msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
}
this.chatStore.insertMessage(msgInfo, this.chat);
},
reCalChatMainHeight() {
const sysInfo = uni.getSystemInfoSync();
let h = sysInfo.windowHeight;
@ -753,6 +792,10 @@ export default {
}
return this.chat.unreadCount;
},
isBanned() {
return (this.chat.type == "PRIVATE" && this.friend.isBanned) ||
(this.chat.type == "GROUP" && this.group.isBanned)
},
atUserItems() {
let atUsers = [];
this.atUserIds.forEach((id) => {
@ -815,7 +858,7 @@ export default {
//
this.listenKeyBoard();
//
this.$nextTick(()=>this.reCalChatMainHeight())
this.$nextTick(() => this.reCalChatMainHeight())
},
onShow() {
if (this.needScrollToBottom) {

35
im-uniapp/store/chatStore.js

@ -141,9 +141,9 @@ export default defineStore('chatStore', {
this.saveToStorage();
}
},
insertMessage(msgInfo) {
insertMessage(msgInfo, chatInfo) {
// 获取对方id或群id
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
let type = chatInfo.type;
// 记录消息的最大id
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > this.privateMsgMaxId) {
this.privateMsgMaxId = msgInfo.id;
@ -152,7 +152,7 @@ export default defineStore('chatStore', {
this.groupMsgMaxId = msgInfo.id;
}
// 如果是已存在消息,则覆盖旧的消息数据
let chat = this.findChat(msgInfo);
let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo);
if (message) {
Object.assign(message, msgInfo);
@ -228,9 +228,9 @@ export default defineStore('chatStore', {
chat.stored = false;
this.saveToStorage();
},
updateMessage(msgInfo) {
updateMessage(msgInfo, chatInfo) {
// 获取对方id或群id
let chat = this.findChat(msgInfo);
let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo);
if (message) {
// 属性拷贝
@ -239,9 +239,9 @@ export default defineStore('chatStore', {
this.saveToStorage();
}
},
deleteMessage(msgInfo) {
deleteMessage(msgInfo, chatInfo) {
// 获取对方id或群id
let chat = this.findChat(msgInfo);
let chat = this.findChat(chatInfo);
for (let idx in chat.messages) {
// 已经发送成功的,根据id删除
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) {
@ -261,7 +261,7 @@ export default defineStore('chatStore', {
updateChatFromFriend(friend) {
let chat = this.findChatByFriend(friend.id)
if (chat && (chat.headImage != friend.headImageThumb ||
chat.showName != friend.nickName)) {
chat.showName != friend.nickName)) {
// 更新会话中的群名和头像
chat.headImage = friend.headImageThumb;
chat.showName = friend.nickName;
@ -272,7 +272,7 @@ export default defineStore('chatStore', {
updateChatFromGroup(group) {
let chat = this.findChatByGroup(group.id);
if (chat && (chat.headImage != group.headImageThumb ||
chat.showName != group.showGroupName)) {
chat.showName != group.showGroupName)) {
// 更新会话中的群名称和头像
chat.headImage = group.headImageThumb;
chat.showName = group.showGroupName;
@ -390,21 +390,10 @@ export default defineStore('chatStore', {
}
}
},
findChat: (state) => (msgInfo) => {
findChat: (state) => (chat) => {
let chats = state.curChats;
// 获取对方id或群id
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo
.sendId;
let chat = null;
for (let idx in chats) {
if (chats[idx].type == type &&
chats[idx].targetId === targetId) {
chat = chats[idx];
break;
}
}
return chat;
let idx = state.findChatIdx(chat);
return chats[idx];
},
findChatByFriend: (state) => (fid) => {
return state.curChats.find(chat => chat.type == 'PRIVATE' &&

75
im-web/src/components/chat/ChatBox.vue

@ -161,15 +161,20 @@ export default {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
})
},
onImageFail(e, file) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
},
onImageBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let url = URL.createObjectURL(file);
let data = {
originUrl: url,
@ -191,7 +196,7 @@ export default {
// id
this.fillTargetId(msgInfo, this.chat.targetId);
//
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
//
this.moveChatToTop();
//
@ -213,15 +218,20 @@ export default {
msgInfo.id = m.id;
this.isReceipt = false;
this.refreshPlaceHolder();
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
})
},
onFileFail(e, file) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
},
onFileBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let url = URL.createObjectURL(file);
let data = {
name: file.name,
@ -243,7 +253,7 @@ export default {
// id
this.fillTargetId(msgInfo, this.chat.targetId);
//
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
//
this.moveChatToTop();
//
@ -285,6 +295,12 @@ export default {
this.showRecord = false;
},
showPrivateVideo(mode) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let rtcInfo = {
mode: mode,
isHost: true,
@ -294,6 +310,11 @@ export default {
this.$eventBus.$emit("openPrivateVideo", rtcInfo);
},
onGroupVideo() {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
//
let ids = [this.mine.id];
let maxChannel = this.$store.state.configStore.webrtc.maxChannel;
@ -329,6 +350,11 @@ export default {
this.showHistory = false;
},
onSendRecord(data) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let msgInfo = {
content: JSON.stringify(data),
type: 3,
@ -338,7 +364,7 @@ export default {
this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
this.$store.commit("insertMessage", [m, this.chat]);
//
this.moveChatToTop();
//
@ -364,6 +390,11 @@ export default {
async sendMessage(fullList) {
this.resetEditor();
this.readedMessage();
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let sendText = this.isReceipt ? "【回执消息】" : "";
let promiseList = [];
for (let i = 0; i < fullList.length; i++) {
@ -421,7 +452,7 @@ export default {
this.lockMessage = true;
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
this.$store.commit("insertMessage", [m, this.chat]);
//
this.moveChatToTop();
}).finally(() => {
@ -465,7 +496,7 @@ export default {
msgInfo.type = 10;
msgInfo.content = '你撤回了一条消息';
msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL;
this.$store.commit("insertMessage", msgInfo);
this.$store.commit("insertMessage", [msgInfo, this.chat]);
})
});
},
@ -482,7 +513,7 @@ export default {
this.$http({
url: url,
method: 'put'
}).then(() => { })
}).then(() => {})
},
loadReaded(fId) {
this.$http({
@ -588,6 +619,22 @@ export default {
})
}
},
showBannedTip() {
let msgInfo = {
tmpId: this.generateId(),
sendId: this.mine.id,
sendTime: new Date().getTime(),
type: this.$enums.MESSAGE_TYPE.TIP_TEXT
}
if (this.chat.type == "PRIVATE") {
msgInfo.recvId = this.mine.id
msgInfo.content = "该用户已被管理员封禁,原因:" + this.friend.reason
} else {
msgInfo.groupId = this.group.id;
msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
}
this.$store.commit("insertMessage", [msgInfo, this.chat]);
},
generateId() {
// id
return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
@ -616,13 +663,17 @@ export default {
return 0;
}
return this.chat.messages.length;
},
isBanned() {
return (this.chat.type == "PRIVATE" && this.friend.isBanned) ||
(this.chat.type == "GROUP" && this.group.isBanned)
}
},
watch: {
chat: {
handler(newChat, oldChat) {
if (newChat.targetId > 0 && (!oldChat || newChat.type != oldChat.type ||
newChat.targetId != oldChat.targetId)) {
newChat.targetId != oldChat.targetId)) {
if (this.chat.type == "GROUP") {
this.loadGroup(this.chat.targetId);
} else {
@ -831,4 +882,4 @@ export default {
}
}
</style>
</style>

2
im-web/src/components/chat/ChatInput.vue

@ -443,7 +443,7 @@ export default {
if (node.dataset.id) {
tempText += node.innerHTML;
atUserIds.push(node.dataset.id)
} else {
} else if(node.outerHtml) {
tempText += node.outerHtml;
}
}

35
im-web/src/store/chatStore.js

@ -137,8 +137,8 @@ export default {
this.commit("saveToStorage");
}
},
insertMessage(state, msgInfo) {
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
insertMessage(state, [msgInfo, chatInfo]) {
let type = chatInfo.type;
// 记录消息的最大id
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) {
state.privateMsgMaxId = msgInfo.id;
@ -147,7 +147,7 @@ export default {
state.groupMsgMaxId = msgInfo.id;
}
// 如果是已存在消息,则覆盖旧的消息数据
let chat = this.getters.findChat(msgInfo);
let chat = this.getters.findChat(chatInfo);
let message = this.getters.findMessage(chat, msgInfo);
if (message) {
Object.assign(message, msgInfo);
@ -178,7 +178,8 @@ export default {
chat.lastSendTime = msgInfo.sendTime;
chat.sendNickName = msgInfo.sendNickName;
// 未读加1
if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED && msgInfo.type != MESSAGE_TYPE.TIP_TEXT) {
if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED &&
msgInfo.type != MESSAGE_TYPE.TIP_TEXT) {
chat.unreadCount++;
}
// 是否有人@我
@ -216,9 +217,9 @@ export default {
chat.stored = false;
this.commit("saveToStorage");
},
updateMessage(state, msgInfo) {
updateMessage(state, [msgInfo, chatInfo]) {
// 获取对方id或群id
let chat = this.getters.findChat(msgInfo);
let chat = this.getters.findChat(chatInfo);
let message = this.getters.findMessage(chat, msgInfo);
if (message) {
// 属性拷贝
@ -227,8 +228,8 @@ export default {
this.commit("saveToStorage");
}
},
deleteMessage(state, msgInfo) {
let chat = this.getters.findChat(msgInfo);
deleteMessage(state, [msgInfo, chatInfo]) {
let chat = this.getters.findChat(chatInfo);
for (let idx in chat.messages) {
// 已经发送成功的,根据id删除
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) {
@ -289,7 +290,7 @@ export default {
});
// 将消息一次性装载回来
state.chats = cacheChats;
// 清空缓存,不再使用
// 清空缓存
cacheChats = null;
this.commit("saveToStorage");
},
@ -384,20 +385,10 @@ export default {
}
}
},
findChat: (state, getters) => (msgInfo) => {
findChat: (state, getters) => (chat) => {
let chats = getters.findChats();
// 获取对方id或群id
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo.sendId;
let chat = null;
for (let idx in chats) {
if (chats[idx].type == type &&
chats[idx].targetId === targetId) {
chat = chats[idx];
break;
}
}
return chat;
let idx = getters.findChatIdx(chat);
return chats[idx];
},
findChatByFriend: (state, getters) => (fid) => {
let chats = getters.findChats();

5
im-web/src/view/Home.vue

@ -201,7 +201,7 @@ export default {
//
this.$store.commit("openChat", chatInfo);
//
this.$store.commit("insertMessage", msg);
this.$store.commit("insertMessage", [msg, chatInfo]);
//
if (!msg.selfSend && this.$msgType.isNormal(msg.type) &&
msg.status != this.$enums.MESSAGE_STATUS.READED) {
@ -251,7 +251,6 @@ export default {
})
},
insertGroupMessage(group, msg) {
let chatInfo = {
type: 'GROUP',
targetId: group.id,
@ -261,7 +260,7 @@ export default {
//
this.$store.commit("openChat", chatInfo);
//
this.$store.commit("insertMessage", msg);
this.$store.commit("insertMessage", [msg, chatInfo]);
//
if (!msg.selfSend && msg.type <= this.$enums.MESSAGE_TYPE.VIDEO &&
msg.status != this.$enums.MESSAGE_STATUS.READED) {

Loading…
Cancel
Save