Răsfoiți Sursa

消息多端读取

luoyangwei 1 an în urmă
părinte
comite
057e7ee1eb
2 a modificat fișierele cu 10 adăugiri și 11 ștergeri
  1. 4 3
      models/session.go
  2. 6 8
      server/client.go

+ 4 - 3
models/session.go

@@ -40,9 +40,10 @@ type SessionMessage struct {
 
 	Receiver    string
 	Sender      string
-	Type        int8
-	ContentType uint8
-	Content     json.RawMessage `gorm:"type:json"`
+	SessionId   string
+	PayloadType uint8
+	Payload     json.RawMessage `gorm:"type:json"`
+	IsRead      int
 	SentAt      time.Time
 }
 

+ 6 - 8
server/client.go

@@ -74,7 +74,7 @@ func (c *Client) Reader() {
 	}
 }
 
-// writer is event listening for servers sending messages to clients
+// Writer is event listening for servers sending messages to clients
 func (c *Client) Writer() {
 	ticker := time.NewTicker(c.pingpongWait)
 	defer func() {
@@ -219,11 +219,8 @@ func (c *Client) persistenceMessage(ctx context.Context, message *Message) error
 		ID:          message.MessageId,
 		Receiver:    message.Receiver,
 		Sender:      message.sender,
-		Type:        message.Type,
-		ContentType: 1,
+		PayloadType: 1,
 		SentAt:      time.Now().UTC(),
-		// IsRead:      false,
-		// Received:    false,
 	}
 
 	zap.L().Info("[persistence] save database begin",
@@ -241,9 +238,10 @@ func (c *Client) persistenceMessage(ctx context.Context, message *Message) error
 	case MessageTypeUpChating:
 		// Chat dialogue messages
 		chatingContent := message.Content.(ChatingContent)
-		chatingContent.MessageId = message.MessageId        // Important, not having this line may result in the inability to receive messages
-		mod.ContentType = uint8(chatingContent.PayloadType) // Important, not having this line may result in the inability to receive messages
+		chatingContent.MessageId = message.MessageId // Important, not having this line may result in the inability to receive messages
+		mod.PayloadType = chatingContent.PayloadType // Important, not having this line may result in the inability to receive messages
 		mod.Receiver = chatingContent.Receiver
+		mod.SessionId = chatingContent.SessionId
 
 		// Format the structure. Sometimes,
 		// the data passed in may contain fields that contaminate the structure.
@@ -266,7 +264,7 @@ func (c *Client) persistenceMessage(ctx context.Context, message *Message) error
 		}
 		payload, _ := json.Marshal(chatingContent.Payload)
 
-		mod.Content = payload
+		mod.Payload = payload
 		mod.SentAt = time.UnixMilli(chatingContent.SendTime)
 		message.Content = chatingContent
 		// case MessageTypeNotification: