diff --git a/handler/im.go b/handler/im.go index 5938f8b..a16f941 100644 --- a/handler/im.go +++ b/handler/im.go @@ -61,10 +61,13 @@ func GetImKey(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"}) return } - if retrievedData["from_user_id"] == id1 { + if int(retrievedData["from_user_id"].(float64)) == id1 { + if int(retrievedData["is_read"].(float64)) == 1 { + worker.DelRedis(redis_key) + } c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"}) return - } else { + } else if int(retrievedData["to_user_id"].(float64)) == id1 { retrievedData["is_read"] = 1 str, _ := json.Marshal(retrievedData) res3 := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300) @@ -77,6 +80,9 @@ func GetImKey(c *gin.Context) { return c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"}) return + } else { + c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + return } } diff --git a/worker/redis.go b/worker/redis.go index cb011e0..f4e72e9 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -176,6 +176,14 @@ func PopRedisListLeft(key string) string { return val } +func DelRedis(key string) { + ctx := context.Background() + err := redisClient.Del(ctx, key).Err() + if err != nil { + fmt.Println("Error deleting key: %v", err) + } +} + // push redis list from right func PushRedisList(key string, value string) bool { ctx := context.Background()