Răsfoiți Sursa

消息字段删除

luoyangwei 1 an în urmă
părinte
comite
03f7296f2b

+ 0 - 2
models/session.go

@@ -43,8 +43,6 @@ type SessionMessage struct {
 	Type        int8
 	ContentType uint8
 	Content     json.RawMessage `gorm:"type:json"`
-	IsRead      BitBool
-	Received    BitBool
 	SentAt      time.Time
 }
 

+ 0 - 1
repositories/repositories.go

@@ -16,7 +16,6 @@ type Repositories struct {
 	SessionRepository         SessionRepository
 	OnlineRepository          OnlineRepository
 	FirebaseMessageRepository FirebaseMessageRepository
-	UnreadCounterRepository   UnreadCounterRepository
 	MessageReadLogRepository  MessageReadLogRepository
 }
 

+ 0 - 70
repositories/unread_counter_repository.go

@@ -1,70 +0,0 @@
-package repositories
-
-import (
-	"context"
-	"fmt"
-	"strconv"
-
-	"github.com/redis/go-redis/v9"
-	"github.com/rotisserie/eris"
-)
-
-// UnreadCounterKey is a key for unread counter.
-// param 1 is account id
-// param 2 is session id
-const UnreadCounterKey = "clients.unread_counter.%s.%s"
-
-// UnreadCounterRepository is a repository for unread counter.
-type UnreadCounterRepository interface {
-
-	// AddUnreadCount adds unread count.
-	GetUnreadCount(ctx context.Context, uid, sid string) (int64, error)
-
-	// GetUnreadCount gets unread count.
-	AddUnreadCount(ctx context.Context, uid, sid string, factor int64) (int64, error)
-
-	// SubtractUnreadCount subtracts unread count.
-	SubtractUnreadCount(ctx context.Context, uid, sid string, factor int64) (int64, error)
-}
-
-type unreadCounterRepository struct {
-	rdb *redis.Client
-}
-
-// AddUnreadCount implements UnreadCounterRepository.
-func (repo *unreadCounterRepository) AddUnreadCount(ctx context.Context, uid, sid string, factor int64) (int64, error) {
-	i64, err := repo.rdb.IncrBy(ctx, fmt.Sprintf(UnreadCounterKey, uid, sid), factor).Result()
-	if err != nil {
-		return 0, eris.Wrap(err, "failed to increment unread count")
-	}
-	return i64, nil
-}
-
-// GetUnreadCount implements UnreadCounterRepository.
-func (repo *unreadCounterRepository) GetUnreadCount(ctx context.Context, uid, sid string) (int64, error) {
-	count, err := repo.rdb.Get(ctx, fmt.Sprintf(UnreadCounterKey, uid, sid)).Result()
-	if err != nil {
-		if eris.Is(err, redis.Nil) {
-			return 0, nil
-		}
-		return 0, eris.Wrap(err, "failed to get unread count")
-	}
-	i64, err := strconv.ParseInt(count, 10, 64)
-	if err != nil {
-		return 0, eris.Wrap(err, "failed to parse unread count")
-	}
-	return i64, nil
-}
-
-// SubtractUnreadCount implements UnreadCounterRepository.
-func (repo *unreadCounterRepository) SubtractUnreadCount(ctx context.Context, uid, sid string, factor int64) (int64, error) {
-	i64, err := repo.rdb.DecrBy(ctx, fmt.Sprintf(UnreadCounterKey, uid, sid), factor).Result()
-	if err != nil {
-		return 0, eris.Wrap(err, "failed to decrement unread count")
-	}
-	return i64, nil
-}
-
-func NewUnreadCounterRepository(rdb *redis.Client) UnreadCounterRepository {
-	return &unreadCounterRepository{rdb: rdb}
-}

+ 0 - 41
repositories/unread_counter_repository_test.go

@@ -1,41 +0,0 @@
-package repositories_test
-
-import (
-	"context"
-	"fmt"
-	"testing"
-
-	"sikey.com/websocket/repositories"
-	"x.sikey.com.cn/serverx/confx"
-	"x.sikey.com.cn/serverx/rdbx"
-)
-
-func TestUnreadCounterRepository_AddUnreadCount(t *testing.T) {
-	confx.LoadConfig("../etc/websocket.debug.yaml")
-	repo := repositories.NewUnreadCounterRepository(rdbx.GetConnect())
-	count, err := repo.AddUnreadCount(context.Background(), "1", "1", 2)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(count)
-}
-
-func TestUnreadCounterRepository_GetUnreadCount(t *testing.T) {
-	confx.LoadConfig("../etc/websocket.debug.yaml")
-	repo := repositories.NewUnreadCounterRepository(rdbx.GetConnect())
-	count, err := repo.GetUnreadCount(context.Background(), "1", "1")
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(count)
-}
-
-func TestUnreadCounterRepository_SubtractUnreadCount(t *testing.T) {
-	confx.LoadConfig("../etc/websocket.debug.yaml")
-	repo := repositories.NewUnreadCounterRepository(rdbx.GetConnect())
-	count, err := repo.SubtractUnreadCount(context.Background(), "1", "1", 2)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(count)
-}

+ 31 - 32
server/client.go

@@ -106,36 +106,35 @@ func (c *Client) Writer() {
 			switch message.Type {
 			case MessageTypeUpChating:
 				// Chat dialogue messages
-				if chatingContent, ok := message.Content.(ChatingContent); ok {
-					msg, err := c.repos.SessionRepository.FindMessageById(c.ctx, chatingContent.MessageId)
-					if err == nil {
-						msg.Received = true
-						if err := c.repos.SessionRepository.UpdateMessage(c.ctx, msg); err != nil {
-							zap.L().Error("[client] [writer] unable to update message status received",
-								zap.Error(err),
-								zap.String("message_id", message.MessageId),
-								zap.String("request_id", message.RequestId))
-						}
-					} else {
-						if eris.Is(err, models.ErrRecordNotFound) {
-							break
-						}
-						zap.L().Error("[client] [writer] unable to find message", zap.Error(err),
-							zap.String("message_id", message.MessageId),
-							zap.String("request_id", message.RequestId))
-					}
-
-					// Add Unread message count
-					_, err = c.repos.UnreadCounterRepository.AddUnreadCount(c.ctx, message.Receiver, chatingContent.SessionId, 1)
-					if err != nil {
-						zap.L().Error("[client] [writer] unable to add unread count",
-							zap.Error(err),
-							zap.String("message_id", message.MessageId),
-							zap.String("request_id", message.RequestId))
-						return
-					}
-				}
-
+				// if chatingContent, ok := message.Content.(ChatingContent); ok {
+				// 	msg, err := c.repos.SessionRepository.FindMessageById(c.ctx, chatingContent.MessageId)
+				// 	if err == nil {
+				// 		// msg.Received = true
+				// 		// if err := c.repos.SessionRepository.UpdateMessage(c.ctx, msg); err != nil {
+				// 		// 	zap.L().Error("[client] [writer] unable to update message status received",
+				// 		// 		zap.Error(err),
+				// 		// 		zap.String("message_id", message.MessageId),
+				// 		// 		zap.String("request_id", message.RequestId))
+				// 		// }
+				// 	} else {
+				// 		if eris.Is(err, models.ErrRecordNotFound) {
+				// 			break
+				// 		}
+				// 		zap.L().Error("[client] [writer] unable to find message", zap.Error(err),
+				// 			zap.String("message_id", message.MessageId),
+				// 			zap.String("request_id", message.RequestId))
+				// 	}
+
+				// 	// Add Unread message count
+				// 	_, err = c.repos.UnreadCounterRepository.AddUnreadCount(c.ctx, message.Receiver, chatingContent.SessionId, 1)
+				// 	if err != nil {
+				// 		zap.L().Error("[client] [writer] unable to add unread count",
+				// 			zap.Error(err),
+				// 			zap.String("message_id", message.MessageId),
+				// 			zap.String("request_id", message.RequestId))
+				// 		return
+				// 	}
+				// }
 				message.Type = MessageTypeDownChating
 
 			case MessageTypeError:
@@ -223,8 +222,8 @@ func (c *Client) persistenceMessage(ctx context.Context, message *Message) error
 		Type:        message.Type,
 		ContentType: 1,
 		SentAt:      time.Now().UTC(),
-		IsRead:      false,
-		Received:    false,
+		// IsRead:      false,
+		// Received:    false,
 	}
 
 	zap.L().Info("[persistence] save database begin",