Browse Source

Merge branch 'dev/v1.2.6_zxl' of SocialPlatform/messageCenter into feature/v1.2.6

王浩 2 years ago
parent
commit
24957c0fce

+ 2 - 2
api/messagecenter/internal/logic/messageaddlogic.go

@@ -53,9 +53,9 @@ func (l *MessageAddLogic) MessageAdd(req *types.MessageEntity) (*types.CommonRes
 		OwnType:     req.OwnType,
 		OwnType:     req.OwnType,
 		Title:       req.Title,
 		Title:       req.Title,
 		SendId:      quitl.Int64All(encrypt.SE.Decode4Hex(req.SendId)),
 		SendId:      quitl.Int64All(encrypt.SE.Decode4Hex(req.SendId)),
-		Content:     quitl.ObjToString(quitl.If(req.Type == 3 || req.Type == 4, fsw.Repl(req.Content), htmlFilter.Sanitize(fsw.Repl(req.Content)))),
+		Content:     quitl.ObjToString(quitl.If(req.Type == 3 || req.Type == 4 || req.Type == 5, fsw.Repl(req.Content), htmlFilter.Sanitize(fsw.Repl(req.Content)))),
 		Item:        req.Item,
 		Item:        req.Item,
-		Type:        req.Type,
+		Type:        quitl.Int64All(quitl.If(req.Type == 5, 1, req.Type)),
 		Link:        req.Link,
 		Link:        req.Link,
 		Appid:       req.Appid,
 		Appid:       req.Appid,
 		ItemType:    req.ItemType,
 		ItemType:    req.ItemType,

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

@@ -31,7 +31,7 @@ func NewSaveMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveM
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
 	// todo: add your logic here and delete this line
 	// todo: add your logic here and delete this line
 	m := service.MessaggeService{}
 	m := service.MessaggeService{}
-	chatMap := map[int]bool{
+	chatMap := map[int64]bool{
 		2:  true, //2:点对点消息
 		2:  true, //2:点对点消息
 		3:  true, //3:群消息
 		3:  true, //3:群消息
 		9:  true, //9:其它系统消息 (除客服以外的)
 		9:  true, //9:其它系统消息 (除客服以外的)

+ 95 - 65
service/message_mail_box.go

@@ -1075,6 +1075,8 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 				//发送人自己
 				//发送人自己
 				if !isWithdrawByOthers {
 				if !isWithdrawByOthers {
 					args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
 					args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
+					//最后一次聊天
+					SocializeSummaryAddOrUpdate(tx, v, in.SendId, 0, messageId, isCustomerServiceAccess, nowTime)
 				}
 				}
 				if !isWithdrawByMyself {
 				if !isWithdrawByMyself {
 					groupUser := GetUserByGroupId(tx, v, in.SendId)
 					groupUser := GetUserByGroupId(tx, v, in.SendId)
@@ -1083,10 +1085,8 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 						//接收人其他用户
 						//接收人其他用户
 						args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
 						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)
+						SocializeSummaryAddOrUpdate(tx, v, 0, vv, messageId, isCustomerServiceAccess, nowTime)
 					}
 					}
-					//更新未读消息
-					GroupUserUnReadUpdate(tx, groupUser)
 				}
 				}
 				MessageMailBoxAdd(tx, fieids, args)
 				MessageMailBoxAdd(tx, fieids, args)
 			}
 			}
@@ -1108,7 +1108,7 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
 
 
 					//最后一次聊天
 					//最后一次聊天
 					SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
 					SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
-					SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
+					// SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
 				}
 				}
 				MessageMailBoxAdd(tx, fieids, args)
 				MessageMailBoxAdd(tx, fieids, args)
 			}
 			}
@@ -1161,73 +1161,103 @@ func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
 }
 }
 
 
 // 最后一次聊天存储
 // 最后一次聊天存储
+//1v1是双方的
+//群聊是发送人和其他人的
 func SocializeSummaryAddOrUpdate(tx *sql.Tx, groupId, myPositionId, yourPositionId, messageId int64, isCustomerServiceAccess int, timestamp string) bool {
 func SocializeSummaryAddOrUpdate(tx *sql.Tx, groupId, myPositionId, yourPositionId, messageId int64, isCustomerServiceAccess int, timestamp string) bool {
 	//判断是否存在
 	//判断是否存在
 	if groupId > 0 {
 	if groupId > 0 {
-		if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where chat_group_id =?`, util.SOCIALIZE_SUMMARY), groupId) > 0 {
-			//存在更新
-			return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"chat_group_id": groupId,
-			}, map[string]interface{}{
-				"message_id": messageId,
-				"timestamp":  timestamp,
-			})
-		} else {
-			//新增
-			return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"chat_group_id": groupId,
-				"message_id":    messageId,
-				"timestamp":     timestamp,
-			}) > 0
-		}
-	}
-	if yourPositionId > 0 {
-		ok_my := true
-		ok_your := true
-		//发送方
-		if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), myPositionId, yourPositionId) > 0 {
-			//存在更新
-			ok_my = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"my_position_id":   myPositionId,
-				"your_position_id": yourPositionId,
-			}, map[string]interface{}{
-				"message_id": messageId,
-				"timestamp":  timestamp,
-			})
+		isSend := myPositionId != 0
+		if isSend {
+			if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where chat_group_id =? and my_position_id =?`, util.SOCIALIZE_SUMMARY), groupId, myPositionId) > 0 {
+				//存在更新
+				return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"chat_group_id":  groupId,
+					"my_position_id": myPositionId,
+				}, map[string]interface{}{
+					"message_id": messageId,
+					"timestamp":  timestamp,
+				})
+			} else {
+				//新增
+				return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"chat_group_id":  groupId,
+					"my_position_id": myPositionId,
+					"message_id":     messageId,
+					"timestamp":      timestamp,
+					"unread":         0,
+				}) > 0
+			}
 		} else {
 		} else {
-			//新增
-			ok_my = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"my_position_id":          myPositionId,
-				"your_position_id":        yourPositionId,
-				"message_id":              messageId,
-				"timestamp":               timestamp,
-				"unread":                  0,
-				"customer_service_access": isCustomerServiceAccess,
-			}) > 0
+			if r := IC.BaseMysql.SelectBySql(fmt.Sprintf(`select unread from %s where chat_group_id =? and my_position_id =?`, util.SOCIALIZE_SUMMARY), groupId, yourPositionId); r != nil && len(*r) > 0 {
+				//存在更新
+				return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"chat_group_id":  groupId,
+					"my_position_id": yourPositionId,
+				}, map[string]interface{}{
+					"message_id": messageId,
+					"timestamp":  timestamp,
+					"unread":     gconv.Int((*r)[0]["unread"]) + 1,
+				})
+			} else {
+				//新增
+				return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"chat_group_id":  groupId,
+					"my_position_id": yourPositionId,
+					"message_id":     messageId,
+					"timestamp":      timestamp,
+					"unread":         1,
+				}) > 0
+			}
 		}
 		}
-		//接收方
-		if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), yourPositionId, myPositionId) > 0 {
-			//存在更新
-			ok_your = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"my_position_id":   yourPositionId,
-				"your_position_id": myPositionId,
-			}, map[string]interface{}{
-				"message_id": messageId,
-				"timestamp":  timestamp,
-				"unread":     1,
-			})
-		} else {
-			//新增
-			ok_your = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
-				"my_position_id":          yourPositionId,
-				"your_position_id":        myPositionId,
-				"message_id":              messageId,
-				"timestamp":               timestamp,
-				"unread":                  1,
-				"customer_service_access": isCustomerServiceAccess,
-			}) > 0
+	} else {
+		if yourPositionId > 0 {
+			ok_my := true
+			ok_your := true
+			//发送方
+			if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), myPositionId, yourPositionId) > 0 {
+				//存在更新
+				ok_my = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"my_position_id":   myPositionId,
+					"your_position_id": yourPositionId,
+				}, map[string]interface{}{
+					"message_id": messageId,
+					"timestamp":  timestamp,
+				})
+			} else {
+				//新增
+				ok_my = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"my_position_id":          myPositionId,
+					"your_position_id":        yourPositionId,
+					"message_id":              messageId,
+					"timestamp":               timestamp,
+					"unread":                  0,
+					"customer_service_access": isCustomerServiceAccess,
+				}) > 0
+			}
+			//接收方
+			if r := IC.BaseMysql.SelectBySql(fmt.Sprintf(`select id,unread from %s where my_position_id =? and your_position_id =? limit 1`, util.SOCIALIZE_SUMMARY), yourPositionId, myPositionId); r != nil && len(*r) > 0 {
+				//存在更新
+				ok_your = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"my_position_id":   yourPositionId,
+					"your_position_id": myPositionId,
+				}, map[string]interface{}{
+					"message_id": messageId,
+					"timestamp":  timestamp,
+					"unread":     gconv.Int((*r)[0]["unread"]) + 1,
+				})
+			} else {
+				//新增
+				ok_your = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+					"my_position_id":          yourPositionId,
+					"your_position_id":        myPositionId,
+					"message_id":              messageId,
+					"timestamp":               timestamp,
+					"unread":                  1,
+					"customer_service_access": isCustomerServiceAccess,
+				}) > 0
+			}
+			return ok_my && ok_your
 		}
 		}
-		return ok_my && ok_your
 	}
 	}
 	return true
 	return true
 }
 }