Skip to content

Commit 9862b65

Browse files
author
comsince
committed
优化群组通知显示
1 parent 4e0b4cd commit 9862b65

File tree

8 files changed

+212
-17
lines changed

8 files changed

+212
-17
lines changed

src/components/chatlist/chatlist.vue

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { mapState, mapActions ,mapGetters } from 'vuex'
3030
import ConversationType from '../../websocket/model/conversationType';
3131
import LocalStore from '../../websocket/store/localstore';
3232
import TimeUtils from '../../websocket/utils/timeUtils';
33+
import MessageConfig from '../../websocket/message/messageConfig';
34+
import NotificationMessageContent from '../../websocket/message/notification/notificationMessageContent';
3335
export default {
3436
computed: {
3537
...mapState([
@@ -52,25 +54,47 @@ export default {
5254
var protoConversationInfo = item.conversationInfo;
5355
var displayContent;
5456
if(protoConversationInfo.lastMessage){
55-
displayContent = protoConversationInfo.lastMessage.content.searchableContent;
56-
if(protoConversationInfo.lastMessage.content.type === 400){
57-
displayContent = '[网络电话]';
58-
}
59-
var isCurrentUser = protoConversationInfo.lastMessage.from === LocalStore.getUserId();
60-
if(protoConversationInfo.conversationType == ConversationType.Group && !isCurrentUser){
61-
var from = protoConversationInfo.lastMessage.from;
62-
var displayUserInfo = this.userInfoList.find(userInfo => userInfo.uid == from);
63-
var displayName = from;
64-
if(displayUserInfo){
65-
displayName = displayUserInfo.displayName;
66-
if(!displayName){
67-
displayName = displayUserInfo.mobile;
57+
var messageContent = MessageConfig.convert2MessageContent(protoConversationInfo.lastMessage.from,protoConversationInfo.lastMessage.content);
58+
if(messageContent && messageContent instanceof NotificationMessageContent){
59+
if(!messageContent.fromSelf){
60+
displayContent = this.getDisplayName(protoConversationInfo.lastMessage.from)+":"+messageContent.formatNotification();
61+
} else {
62+
displayContent = messageContent.formatNotification();
63+
}
64+
console.log("notification message "+displayContent);
65+
} else {
66+
displayContent = protoConversationInfo.lastMessage.content.searchableContent;
67+
if(protoConversationInfo.lastMessage.content.type === 400){
68+
displayContent = '[网络电话]';
69+
}
70+
var isCurrentUser = protoConversationInfo.lastMessage.from === LocalStore.getUserId();
71+
if(protoConversationInfo.conversationType == ConversationType.Group && !isCurrentUser){
72+
var from = protoConversationInfo.lastMessage.from;
73+
var displayUserInfo = this.userInfoList.find(userInfo => userInfo.uid == from);
74+
var displayName = from;
75+
if(displayUserInfo){
76+
displayName = displayUserInfo.displayName;
77+
if(!displayName){
78+
displayName = displayUserInfo.mobile;
79+
}
6880
}
81+
displayContent = displayName +":"+protoConversationInfo.lastMessage.content.searchableContent;
6982
}
70-
displayContent = displayName +":"+protoConversationInfo.lastMessage.content.searchableContent;
7183
}
84+
7285
}
7386
return displayContent;
87+
},
88+
getDisplayName(from){
89+
var displayUserInfo = this.userInfoList.find(userInfo => userInfo.uid == from);
90+
var displayName = from;
91+
if(displayUserInfo){
92+
displayName = displayUserInfo.displayName;
93+
if(!displayName){
94+
displayName = displayUserInfo.mobile;
95+
}
96+
}
97+
return displayName;
7498
}
7599
},
76100
filters: {

src/components/message/message.vue

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<ul v-if="selectedChat">
1414
<li v-bind:key = index v-for="(item, index) in selectedChat.protoMessages" class="message-item">
1515
<div v-if="isShowTime(index,selectedChat.protoMessages)" class="time"><span>{{item.timestamp | getTimeStringAutoShort2}}</span></div>
16-
<div v-if="item.content.type === 104" class="time"><span>{{notification(item.content.binaryContent,item.content.type)}}</span></div>
17-
<div v-if="item.content.type === 110" class="time"><span>{{notification(item.content.binaryContent,item.content.type)}}</span></div>
16+
<!-- <div v-if="item.content.type === 104" class="time"><span>{{notification(item.content.binaryContent,item.content.type)}}</span></div>
17+
<div v-if="item.content.type === 110" class="time"><span>{{notification(item.content.binaryContent,item.content.type)}}</span></div> -->
18+
<div v-if="isGroupNotification(item)" class="time"><span>{{groupNotification(item)}}</span></div>
1819
<div v-if="item.content.type === 90" class="time"><span>{{item.content.content}}</span></div>
1920
<div v-if="!isNotification(item.content.type)" class="main" :class="{ self: item.direction == 0 ? true : false }">
2021
<img class="avatar" width="36" height="36" :src="avatarSrc(item)"
@@ -68,6 +69,9 @@ import Vue from 'vue'
6869
Vue.use(Viewer)
6970
import CryptoJS from 'crypto-js'
7071
import groupInfo from '../menu/groupInfo'
72+
import MessageConfig from '../../websocket/message/messageConfig';
73+
import NotificationMessageContent from '../../websocket/message/notification/notificationMessageContent';
74+
import GroupNotificationContent from '../../websocket/message/notification/groupNotification';
7175
export default {
7276
components:{
7377
Xgplayer,
@@ -213,6 +217,35 @@ export default {
213217
return notificationContent;
214218
},
215219
220+
isGroupNotification(protoMessage){
221+
var contentClass = MessageConfig.getMessageContentClazz(protoMessage.content.type);
222+
var content = new contentClass();
223+
return content instanceof GroupNotificationContent;
224+
},
225+
226+
groupNotification(protoMessage){
227+
var displayContent;
228+
var messageContent = MessageConfig.convert2MessageContent(protoMessage.from,protoMessage.content);
229+
if(!messageContent.fromSelf){
230+
displayContent = this.getDisplayName(protoMessage.from)+":"+messageContent.formatNotification();
231+
} else {
232+
displayContent = messageContent.formatNotification();
233+
}
234+
return displayContent;
235+
},
236+
237+
getDisplayName(from){
238+
var displayUserInfo = this.userInfoList.find(userInfo => userInfo.uid == from);
239+
var displayName = from;
240+
if(displayUserInfo){
241+
displayName = displayUserInfo.displayName;
242+
if(!displayName){
243+
displayName = displayUserInfo.mobile;
244+
}
245+
}
246+
return displayName;
247+
},
248+
216249
isNotification(type){
217250
return type >= 80 && type <= 117
218251
},

src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ const mutations = {
454454
*/
455455
updateConversationIntro(state,groupInfos){
456456
for(var groupInfo of groupInfos){
457-
var stateConverstaionInfo = state.conversations.find(stateConverstaionInfo => stateConverstaionInfo.name === groupInfo.target);
457+
var stateConverstaionInfo = state.conversations.find(stateConverstaionInfo => stateConverstaionInfo.conversationInfo.target === groupInfo.target);
458458
if(stateConverstaionInfo){
459459
console.log("update conversation name "+stateConverstaionInfo.name);
460460
stateConverstaionInfo.name = groupInfo.name;

src/websocket/message/messageConfig.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import CallSignalMessageContent from '../../webrtc/message/callSignalMessageCont
1010
import ImageMessageContent from './imageMessageContent'
1111
import CallByeMessageContent from '../../webrtc/message/callByeMessageContent'
1212
import CallModifyMessageContent from '../../webrtc/message/callModifyMessageContent'
13+
import CreateGroupNotification from './notification/createGroupNotification'
14+
import ChangeGroupNameNotification from './notification/changeGroupNameNotification'
15+
import NotificationMessageContent from './notification/notificationMessageContent'
16+
import LocalStore from '../store/localstore'
1317
export default class MessageConfig{
1418
static getMessageContentClazz(type) {
1519
for (const content of MessageConfig.MessageContents) {
@@ -25,6 +29,24 @@ export default class MessageConfig{
2529
return UnknownMessageContent;
2630
}
2731

32+
static convert2MessageContent(from,protoMessageContent){
33+
var messageContent = null;
34+
var contentClazz = this.getMessageContentClazz(protoMessageContent.type);
35+
if(contentClazz != UnsupportMessageContent){
36+
let content = new contentClazz();
37+
try {
38+
content.decode(protoMessageContent);
39+
if (content instanceof NotificationMessageContent) {
40+
content.fromSelf = from === LocalStore.getUserId();
41+
}
42+
messageContent = content;
43+
}catch(error){
44+
console.log("decode message content error "+protoMessageContent);
45+
}
46+
}
47+
return messageContent;
48+
}
49+
2850

2951
static getMessageContentPersitFlag(type) {
3052
for (const content of MessageConfig.MessageContents) {
@@ -118,6 +140,7 @@ export default class MessageConfig{
118140
name: 'changeGroupNameNotification',
119141
flag: PersistFlag.Persist,
120142
type: MessageContentType.ChangeGroupName_Notification,
143+
contentClazz: ChangeGroupNameNotification
121144
},
122145
{
123146
name: 'changeGroupPortraitNotification',
@@ -128,6 +151,7 @@ export default class MessageConfig{
128151
name: 'createGroupNotification',
129152
flag: PersistFlag.Persist,
130153
type: MessageContentType.CreateGroup_Notification,
154+
contentClazz: CreateGroupNotification
131155
},
132156
{
133157
name: 'dismissGroupNotification',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import MessageContentType from "../messageContentType";
2+
3+
import GroupNotificationContent from "./groupNotification";
4+
import StringUtils from '../../utils/StringUtil'
5+
6+
export default class ChangeGroupNameNotification extends GroupNotificationContent {
7+
operator = '';
8+
name = '';
9+
10+
constructor(operator, name) {
11+
super(MessageContentType.ChangeGroupName_Notification);
12+
this.operator = operator;
13+
this.name = name;
14+
}
15+
16+
formatNotification() {
17+
if (this.fromSelf) {
18+
return '您修改群名称为:' + this.name;
19+
} else {
20+
return '修改群名称为:' + this.name;
21+
}
22+
}
23+
24+
encode() {
25+
let payload = super.encode();
26+
let obj = {
27+
g: this.groupId,
28+
n: this.name,
29+
o: this.operator,
30+
};
31+
payload.binaryContent = StringUtils.utf8_to_b64(JSON.stringify(obj));
32+
return payload;
33+
}
34+
35+
decode(payload) {
36+
super.decode(payload);
37+
let json = StringUtils.b64_to_utf8(payload.binaryContent)
38+
let obj = JSON.parse(json);
39+
this.groupId = obj.g;
40+
this.operator = obj.o;
41+
this.name = obj.n;
42+
}
43+
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import MessageContentType from '../messageContentType';
2+
3+
import GroupNotificationContent from './groupNotification';
4+
import StringUtils from '../../utils/StringUtil'
5+
6+
export default class CreateGroupNotification extends GroupNotificationContent {
7+
creator = '';
8+
groupName = '';
9+
10+
constructor(creator, groupName) {
11+
super(MessageContentType.CreateGroup_Notification);
12+
this.creator = creator;
13+
this.groupName = groupName;
14+
}
15+
16+
formatNotification() {
17+
if (this.fromSelf) {
18+
return '您创建了群组 ' + this.groupName;
19+
} else {
20+
return '创建了群组 ' + this.groupName;
21+
}
22+
}
23+
24+
encode() {
25+
let payload = super.encode();
26+
let obj = {
27+
g: this.groupId,
28+
n: this.groupName,
29+
o: this.creator,
30+
};
31+
payload.binaryContent = StringUtils.utf8_to_b64(JSON.stringify(obj));
32+
return payload;
33+
}
34+
35+
decode(payload) {
36+
super.decode(payload);
37+
let json = StringUtils.b64_to_utf8(payload.binaryContent)
38+
let obj = JSON.parse(json);
39+
this.groupId = obj.g;
40+
this.creator = obj.o;
41+
this.groupName = obj.n;
42+
}
43+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import NotificationMessageContent from "./notificationMessageContent";
2+
3+
export default class GroupNotificationContent extends NotificationMessageContent {
4+
groupId = '';
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import MessageContent from "../messageContent";
2+
export default class NotificationMessageContent extends MessageContent {
3+
// message#protoMessageToMessage时设置
4+
fromSelf = false;
5+
constructor(type) {
6+
super(type);
7+
}
8+
9+
digest(message) {
10+
var desc = '';
11+
try {
12+
desc = this.formatNotification(message);
13+
} catch (error) {
14+
console.log('disgest', error);
15+
}
16+
return desc;
17+
};
18+
19+
formatNotification(message) {
20+
return '..nofication..';
21+
}
22+
}

0 commit comments

Comments
 (0)