消息:取消消息屏蔽
authorCaisking <3449750381@qq.com>
Fri, 11 Oct 2024 11:33:55 +0000 (19:33 +0800)
committerCaisking <3449750381@qq.com>
Fri, 11 Oct 2024 11:33:55 +0000 (19:33 +0800)
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp

index 89281d1..22a0891 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * @Date: 2024-06-21 09:56:18
- * @LastEditors: SnickerSun snickersun@163.com
- * @LastEditTime: 2024-10-10 21:54:07
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-10-11 19:05:25
  * @FilePath:
  * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp
  */
@@ -120,38 +120,39 @@ static void Notify(void *args, const Topic topic, Request *request) {
   UNUSED(args);
   UNUSED(topic);
 
-  if (request == NULL) {  
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received NULL request");  
-    return;  
-  }  
+  if (request == NULL) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received NULL request");
+    return;
+  }
 
-  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Received request %d", request->msgId);  
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Received request %d", request->msgId);
 
-  if (request->msgId == TOPIC_EVENT_MESSAGE_UPDATA) {  
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,  
-                  "Processing TOPIC_EVENT_MESSAGE_UPDATA");  
+  if (request->msgId == TOPIC_EVENT_MESSAGE_UPDATA) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "Processing TOPIC_EVENT_MESSAGE_UPDATA");
 
-    // 创建新的消息信息  
-    ancs_data_info_t *messageInfo = new ancs_data_info_t();  
-    if (messageInfo == NULL) {  
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,  
-                    "Failed to allocate memory for ancs_data_info_t");  
-      return;  
-    }  
+    // 创建新的消息信息
+    ancs_data_info_t *messageInfo = new ancs_data_info_t();
+    if (messageInfo == NULL) {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "Failed to allocate memory for ancs_data_info_t");
+      return;
+    }
 
-    // 复制请求数据到新的消息信息  
-    int rets = memcpy_s(messageInfo, sizeof(ancs_data_info_t),  
-                        (ancs_data_info_t *)request->data, request->len);  
-    if (rets != EOK) {  
-      delete messageInfo;  
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,  
-                    "memcpy_s ancs_data_info_t failed, ret = %d", rets);  
-      return;  
-    }  
+    // 复制请求数据到新的消息信息
+    int rets = memcpy_s(messageInfo, sizeof(ancs_data_info_t),
+                        (ancs_data_info_t *)request->data, request->len);
+    if (rets != EOK) {
+      delete messageInfo;
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "memcpy_s ancs_data_info_t failed, ret = %d", rets);
+      return;
+    }
+
+    // 更新到模型里面的数组
+    MessageModel::GetInstance().AddMessageData(messageInfo);
 
-    // 更新到模型里面的数组  
-    MessageModel::GetInstance().AddMessageData(messageInfo);  
-    
+#if 0
     // 加锁以保护共享变量  
     {  
       std::lock_guard<std::mutex> lock(messageMutex);  
@@ -160,7 +161,6 @@ static void Notify(void *args, const Topic topic, Request *request) {
       // 设置最后更新时间  
       lastUpdateTime = std::chrono::steady_clock::now();  
     }  
-    
     // 直接尝试显示消息(用于单条消息的情况)  
     {  
       std::lock_guard<std::mutex> lock(messageMutex); // 加锁以保护共享变量  
@@ -172,26 +172,10 @@ static void Notify(void *args, const Topic topic, Request *request) {
           WEARABLE_LOG_MODULE_APP, "Time since last update: %lld milliseconds",  
           std::chrono::duration_cast<std::chrono::milliseconds>(timeDiff)  
               .count());  
-
-      if (timeDiff >= updateDelay) {  
+      if (timeDiff>=updateDelay) {  
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,  
                       "Displaying new message after time delay");  
-
-        // 发送信息进行弹窗  
-        if (uapi_dev_runtime_get_train_status() ||  
-            uapi_dev_runtime_get_saveele_status() ||  
-            uapi_dev_runtime_get_respiratory_training_status()) {  
-          // 增加训练模式下,不弹窗  
-          // 省电模式,不弹窗  
-          // 呼吸训练,不弹窗  
-          return;  
-        }  
-
-        // 发送弹窗通知 会自动查询到数组的最新一个  
-        CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0);  
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Message popup sent");  
-
-        // 发送完毕,重置标志  
+       // 发送完毕,重置标志  
         shouldDisplayMessage = false; // 重置状态  
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,  
                       "Reset shouldDisplayMessage to false");  
@@ -200,12 +184,23 @@ static void Notify(void *args, const Topic topic, Request *request) {
                        std::chrono::duration_cast<std::chrono::milliseconds>(timeDiff).count(),   
                        std::chrono::duration_cast<std::chrono::milliseconds>(updateDelay).count());  
       }  
-    }  
-  } else {  
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "No new message to display");  
-  }  
-}
+    }
+#endif
+    // 发送信息进行弹窗
+    if (uapi_dev_runtime_get_train_status() ||
+        uapi_dev_runtime_get_saveele_status() ||
+        uapi_dev_runtime_get_respiratory_training_status()) {
+      // 增加训练模式下,不弹窗
+      // 省电模式,不弹窗
+      // 呼吸训练,不弹窗
+      return;
+    }
 
+    // 发送弹窗通知 会自动查询到数组的最新一个
+    CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0);
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Message popup sent");
+  }
+}
 void saveancsdata() {
   printf("saveancs\r\n");
   OHOS::MessageModel::GetInstance().SaveMessagesToStorage();