Эх сурвалжийг харах

Merge branch 'feature/v1.2.6' into dev/v1.2.6_rjj

renjiaojiao 2 жил өмнө
parent
commit
cf3b06ed77

+ 8 - 1
rpc/messagecenter/internal/logic/savemessagelogic.go

@@ -31,8 +31,15 @@ func NewSaveMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveM
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
+	chatMap := map[int]bool{
+		2:  true, //2:点对点消息
+		3:  true, //3:群消息
+		9:  true, //9:其它系统消息 (除客服以外的)
+		10: true, //10:群撤回(自己看到的)
+		11: true, //11:群撤回(其他人看到的)
+	}
 	fool, error_message, content, messageId, nowTime := func() (fool bool, errorMsg string, content string, messageId, nowInt int64) {
-		if in.ItemType != 2 && in.ItemType != 3 && in.ItemType != 9 {
+		if !chatMap[in.ItemType] {
 			return m.SaveMessage(in)
 		} else {
 			return m.Chat(in)

+ 42 - 36
service/message_mail_box.go

@@ -139,7 +139,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 							"" as groupMember
 						FROM
 							socialize_summary a
-							INNER JOIN base_position b ON ( a.my_position_id = %d %s  AND a.your_position_id = b.id )
+							INNER JOIN base_position b ON ( a.my_position_id = %d %s  AND a.your_position_id = b.id AND a.chat_group_id = 0 )
 							INNER JOIN base_user c ON ( b.user_id = c.id )
 							LEFT JOIN socialize_message d ON ( a.message_id = d.id )
 							ORDER BY a.timestamp DESC LIMIT 0,500
@@ -177,24 +177,23 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 							d.type,
 							d.create_time,
 							a.unread as number,
-							c.timestamp,
+							a.timestamp,
 							"" as phone,
 							b.groupMember
 						FROM
-							socialize_chat_group_person a
-							INNER JOIN %s b ON ( a.position_id = %d AND a.chat_group_id = b.id)
-							INNER JOIN socialize_summary c ON ( b.id = c.chat_group_id )
-							LEFT JOIN socialize_message d ON ( c.message_id = d.id ) 
+							socialize_summary a
+							INNER JOIN %s b ON ( a.my_position_id = %d AND a.chat_group_id > 0 AND a.chat_group_id = b.id)
+							LEFT JOIN socialize_message d ON ( a.message_id = d.id ) 
 						ORDER BY c.timestamp DESC LIMIT 0,500
 						) `, GroupNameSql, in.PositionId)
+		if oneSql != "" {
+			sqlArr = append(sqlArr, oneSql)
+		}
+		if groupSql != "" {
+			sqlArr = append(sqlArr, groupSql)
+		}
 		switch in.QueryType {
 		case 1: //分享列表
-			if oneSql != "" {
-				sqlArr = append(sqlArr, oneSql)
-			}
-			if groupSql != "" {
-				sqlArr = append(sqlArr, groupSql)
-			}
 			if len(sqlArr) > 1 {
 				allSql = strings.Join(sqlArr, " UNION ALL ")
 			} else {
@@ -202,12 +201,6 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 			}
 		default:
 			//历史会话列表
-			if oneSql != "" {
-				sqlArr = append(sqlArr, oneSql)
-			}
-			if groupSql != "" {
-				sqlArr = append(sqlArr, groupSql)
-			}
 			if serviceSql != "" {
 				sqlArr = append(sqlArr, serviceSql)
 			}
@@ -1031,7 +1024,8 @@ func (b MessaggeService) AppraiseMessage(in *messagecenter.AppraiseReq) error {
 // 聊天
 // 包含 1v1 ,群聊,群发
 /*
-入参 appid,title,content,sendid,link,item,messagetype,receiverIds,groupIds
+类型;1:站内信消息 2:点对点消息 3:群消息 4:机器人消息 5:客服消息  6系统信息 7:客服自动回复  8:评价 9:其它系统消息 (除客服以外的) 10:撤回(自己看到的)  11:撤回(其他人看到的)
+群撤回自己看到的和用户看到的不一样
 */
 func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
 	now := time.Now()
@@ -1040,12 +1034,14 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 	fool = IC.BaseMysql.ExecTx("消息存储", func(tx *sql.Tx) bool {
 		isGroup := len(in.GroupIds) > 0
 		isOneToOne := len(in.ReceiverIds) > 0
+		isWithdrawByMyself := in.ItemType == 10
+		isWithdrawByOthers := in.ItemType == 11
 		createperson := strconv.Itoa(int(in.SendId))
 		messageId = MessageAdd(tx, in.Appid, in.Title, in.Content, createperson, in.Link, in.Item, in.Type)
 		//是否客服介入
 		isCustomerServiceAccess := 0
 		//除客服消息以外的系统消息
-		if in.ItemType == 9 {
+		if in.ItemType == 9 || in.ItemType == 10 || in.ItemType == 11 {
 			in.ItemType = 6
 		}
 		//群聊
@@ -1057,17 +1053,23 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 			fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "chat_group_id", "isread"}
 			for _, v := range in.GroupIds {
 				args := []interface{}{}
-				args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
-				groupUser := GetUserByGroupId(tx, v, in.SendId)
-				for _, vv := range groupUser {
-					log.Println("获取到群组下员工:", vv)
-					args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
+				//发送人自己
+				if !isWithdrawByOthers {
+					args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
+				}
+				if !isWithdrawByMyself {
+					groupUser := GetUserByGroupId(tx, v, in.SendId)
+					for _, vv := range groupUser {
+						log.Println("获取到群组下员工:", vv)
+						//接收人其他用户
+						args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
+						//最后一次聊天
+						SocializeSummaryAddOrUpdate(tx, v, vv, 0, messageId, isCustomerServiceAccess, nowTime)
+					}
+					//更新未读消息
+					GroupUserUnReadUpdate(tx, groupUser)
 				}
 				MessageMailBoxAdd(tx, fieids, args)
-				//最后一次聊天
-				SocializeSummaryAddOrUpdate(tx, v, 0, 0, messageId, isCustomerServiceAccess, nowTime)
-				//更新未读消息
-				GroupUserUnReadUpdate(tx, groupUser)
 			}
 		}
 		//1v1
@@ -1078,15 +1080,19 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 			}
 			fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "isread"}
 			args := []interface{}{}
-			args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, 1)
-			for _, v := range in.ReceiverIds {
-				args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, v, 2, 2, v, nowTime, 0)
+			if !isWithdrawByOthers {
+				args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, 1)
+			}
+			if !isWithdrawByMyself {
+				for _, v := range in.ReceiverIds {
+					args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, v, 2, 2, v, nowTime, 0)
 
-				//最后一次聊天
-				SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
-				SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
+					//最后一次聊天
+					SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
+					SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
+				}
+				MessageMailBoxAdd(tx, fieids, args)
 			}
-			MessageMailBoxAdd(tx, fieids, args)
 		}
 		return true
 	})