소스 검색

新增消息红点

warrior 3 주 전
부모
커밋
884e144eaa

+ 0 - 6
projects/live-app/src/modules/live/chat/chat.component.html

@@ -63,13 +63,7 @@
       @if ($index == 0 || item.timestamp -
       msgServe.messageMapList[channel][$index-1].timestamp > 600000) {
       <div class="time-box">
-        @if (item.istoday) {
         <div class="time">{{ item.timestamp | showDate }}</div>
-        }@else {
-        <div class="time">
-          {{ item.timestamp | showDate }}
-        </div>
-        }
       </div>
       }
 

+ 2 - 0
projects/live-app/src/modules/live/chat/chat.component.scss

@@ -7,6 +7,7 @@
   .avatar {
     width: 10.2564vw;
     height: 10.2564vw;
+    border-radius: 50%;
   }
   .message-box {
     margin-bottom: 7.6923vw;
@@ -36,6 +37,7 @@
     }
     .msg-bloak {
       display: flex;
+      padding: 0 4px;
       .text-item_left {
         background: #f1f1f1;
       }

+ 11 - 2
projects/live-app/src/modules/live/chat/chat.component.ts

@@ -37,7 +37,7 @@ import { DeviceService } from '../../../services/device.service';
     CommonModule,
     SharedModule,
     CallModalComponent,
-    AppraiseComponent
+    AppraiseComponent,
   ],
   // providers: [DatePipe],
 })
@@ -90,6 +90,7 @@ export class ChatComponent implements OnInit {
         history.back();
         return;
       }
+      this.msgServe.newNoticeMap.delete(this.channel);
       this.refresh();
     });
   }
@@ -110,6 +111,10 @@ export class ChatComponent implements OnInit {
       message: '加载中',
     });
     loading.present();
+    let noticeMap: any = localStorage.getItem('noticeMap') || '{}';
+    noticeMap = JSON.parse(noticeMap);
+    noticeMap[this.channel] = new Date().getTime();
+    localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
     await this.getProfile();
     await this.getFriend();
     await this.msgServe.initRTM();
@@ -276,7 +281,11 @@ export class ChatComponent implements OnInit {
     const alert = await this.alertController.create({
       cssClass: 'my-custom-class',
       header: '',
-      message: `你确定${this.isRet?.get('isAward') ? '移除对方为黑名单列表' : '加入对方为黑名单列表'}吗?`,
+      message: `你确定${
+        this.isRet?.get('isAward')
+          ? '移除对方为黑名单列表'
+          : '加入对方为黑名单列表'
+      }吗?`,
       buttons: [
         {
           text: '取消',

+ 6 - 1
projects/live-app/src/modules/tabs/notice/notice.component.html

@@ -150,7 +150,12 @@
             (touchstart)="startPress(item)"
             (mousemove)="stopPress()"
           >
-            <img [src]="item.avatar" class="avatar" slot="start" alt="avatar" />
+            <div class="user-avatar">
+              <img [src]="item.avatar" class="avatar" slot="start" alt="avatar" />
+              @if (msgServe.newNoticeMap.has(item.channel)) {
+                <div class="tips"></div>
+              }
+            </div>
             <div class="li-right">
               <div class="name">
                 {{ item.nickname || item.name || "用户" + item.uid }}

+ 15 - 0
projects/live-app/src/modules/tabs/notice/notice.component.scss

@@ -53,6 +53,21 @@
     .li {
       display: flex;
       margin-bottom: 2.5641vw;
+      .user-avatar{
+        position: relative;
+        .tips{
+          position: absolute;
+          right: 5px;
+          width: 6px;
+          height: 6px;
+          top: -4px;
+          background: #dd0000;
+          border-radius: 50%;
+          color: white;
+          text-align: center;
+          line-height: 16px;
+        }
+      }
       .avatar{
         margin-right: 2.5641vw;
         flex-shrink: 0;

+ 2 - 2
projects/live-app/src/modules/tabs/tabs/tabs.component.html

@@ -17,8 +17,8 @@
     <ion-label [style.color]="active == $index ? '#FD7884' : '#808080'">{{
       item.name
     }}</ion-label>
-    @if ($index == 1) {
-    <div class="tips">1</div>
+    @if ($index == 1 && msgServe.newNoticeMap.size > 0) {
+    <div class="tips"></div>
     }
   </div>
   }

+ 2 - 2
projects/live-app/src/modules/tabs/tabs/tabs.component.scss

@@ -29,8 +29,8 @@
     .tips{
       position: absolute;
       right: -8px;
-      width: 4px;
-      height: 4px;
+      width: 6px;
+      height: 6px;
       top: 4px;
       background: #dd0000;
       // width: 16px;

+ 4 - 4
projects/live-app/src/modules/tabs/tabs/tabs.component.ts

@@ -8,7 +8,7 @@ import { IonicModule } from '@ionic/angular';
 import { OnInit } from '@angular/core';
 // import { AlertController } from '@ionic/angular';
 import { FlutterCompComponent } from '../../../app/components/flutter-comp/flutter-comp.component';
-// import { MessageService } from '../../../services/message.service';
+import { MessageService } from '../../../services/message.service';
 // import { ConnectTaskService } from '../../../services/connectTask.service';
 
 import { Camera } from '@capacitor/camera';
@@ -32,12 +32,12 @@ export class TabsComponent implements OnInit {
     // private alertController: AlertController,
     private activateRoute: ActivatedRoute,
     public deviceSer: DeviceService,
-    private http: HttpService
-  ) // private connectTask: ConnectTaskService
+    private http: HttpService,
+    public msgServe: MessageService,
+  )
   {
     this.activateRoute.paramMap.subscribe(async (params) => {
       await this.presentAlert();
-      // this.connectTask.init();
       this.active = this.option.findIndex((item: any) => {
         return item.url == location.pathname.slice(1)
       }) ?? 0

+ 0 - 6
projects/live-app/src/modules/user/online-service/online-service.component.html

@@ -14,13 +14,7 @@
       @if ($index == 0 || item.timestamp -
       msgServe.messageMapList[channel][$index-1].timestamp > 600000) {
       <div class="time-box">
-        @if (item.istoday) {
         <div class="time">{{ item.timestamp | showDate }}</div>
-        }@else {
-        <div class="time">
-          {{ item.timestamp | showDate }}
-        </div>
-        }
       </div>
       }
 

+ 2 - 0
projects/live-app/src/modules/user/online-service/online-service.component.scss

@@ -7,6 +7,7 @@
   .avatar {
     width: 10.2564vw;
     height: 10.2564vw;
+    border-radius: 50%;
   }
   .message-box {
     margin-bottom: 7.6923vw;
@@ -36,6 +37,7 @@
     }
     .msg-bloak {
       display: flex;
+      padding: 0 4px;
       .text-item_left {
         background: #f1f1f1;
       }

+ 55 - 24
projects/live-app/src/services/message.service.ts

@@ -7,8 +7,7 @@ import { Subject } from 'rxjs';
 import { Router } from '@angular/router';
 import { AiChatService } from './aichart.service';
 declare const AgoraRTM: any;
-import { VapInit } from '../lib/vap-player/index'
-
+import { VapInit } from '../lib/vap-player/index';
 
 @Injectable({
   providedIn: 'root',
@@ -37,9 +36,9 @@ export class MessageService {
   giftList: Array<any> = []; //礼物列表
   timeg: any;
   isPlayer: boolean = false;
-
+  newNoticeMap = new Set(); //新消息提示
   private audioPlayer: HTMLAudioElement | null = null;
-  private loopPlayAudio(audioUrl: string, rep?:boolean) {
+  private loopPlayAudio(audioUrl: string, rep?: boolean) {
     if (this.audioPlayer) {
       this.audioPlayer.pause();
       this.audioPlayer.currentTime = 0;
@@ -47,7 +46,7 @@ export class MessageService {
 
     this.audioPlayer = new Audio(audioUrl);
     this.audioPlayer.loop = rep; // 设置循环播放
-    this.audioPlayer.play().catch(error => {
+    this.audioPlayer.play().catch((error) => {
       console.error('播放音频失败:', error);
     });
   }
@@ -56,6 +55,7 @@ export class MessageService {
     this.rtmClient = null;
     this.channelNameList = {};
     this.messageMapList = {};
+    this.newNoticeMap = new Set();
   }
   constructor(
     private alertController: AlertController,
@@ -132,7 +132,7 @@ export class MessageService {
         }
         //呼出播放声音
         if (message.text == 'USERCALLINVITATION') {
-          this.loopPlayAudio('mp3/call.mp3',true);
+          this.loopPlayAudio('mp3/call.mp3', true);
         } else if (message.text == 'CLOASEINVITATION') {
           if (this.audioPlayer) {
             this.audioPlayer.pause();
@@ -189,18 +189,19 @@ export class MessageService {
         count: arr?.[2],
         user: userData,
       });
-      !this.isPlayer && setTimeout(() => {
-        // this.playGift(this.giftLogMap.slice(-1)[0]);
-        let obj = this.giftLogMap.slice(-1)[0]
-        this.eventplay.next({
-          video: obj.gift.video,
-          config: obj.gift.config,
-        });
-      }, 0);
+      !this.isPlayer &&
+        setTimeout(() => {
+          // this.playGift(this.giftLogMap.slice(-1)[0]);
+          let obj = this.giftLogMap.slice(-1)[0];
+          this.eventplay.next({
+            video: obj.gift.video,
+            config: obj.gift.config,
+          });
+        }, 0);
       return;
     }
     if (message.indexOf('USERGREETING_') > -1) {
-      this.loopPlayAudio('mp3/message.mp3')
+      this.loopPlayAudio('mp3/message.mp3');
       let arr = message.split('_');
       this.alert = await this.alertController.create({
         cssClass: 'my-custom-class',
@@ -211,8 +212,7 @@ export class MessageService {
           {
             text: '关闭',
             role: 'cancel',
-            handler: async (blah) => {
-            },
+            handler: async (blah) => {},
           },
           {
             text: '查看主页',
@@ -228,7 +228,7 @@ export class MessageService {
     }
     switch (message) {
       case 'USERCALLINVITATION':
-        this.loopPlayAudio('mp3/call.mp3',true);
+        this.loopPlayAudio('mp3/call.mp3', true);
         await this.setConnectState(this.userId, 'CONNECTING');
         // console.log(`收到${userData?.nickname?.value ?? '未知用户'}通话邀请`);
         this.alert = await this.alertController.create({
@@ -328,7 +328,7 @@ export class MessageService {
 
   playGift(giftModule: any) {
     console.log(giftModule);
-    this.isPlayer = true
+    this.isPlayer = true;
     let dom = document.getElementById('vap-gift');
     console.log(dom);
     let vapPlayer = VapInit({
@@ -355,10 +355,12 @@ export class MessageService {
       if (this.giftLogMap.length > 0) {
         this.playGift(this.giftLogMap.slice(-1)[0]);
       } else {
-        this.isPlayer = false
+        this.isPlayer = false;
       }
     });
-    vapPlayer.on('playering', function () { console.log('playering'); })
+    vapPlayer.on('playering', function () {
+      console.log('playering');
+    });
   }
 
   async getRoom(uid: string): Promise<string | undefined> {
@@ -432,7 +434,9 @@ export class MessageService {
   }
   /* 订阅消息 */
   subscribeMessage(channelName: string, param?: any, deadline?: number): any {
-    if (this.channelNameList[channelName]) { return };
+    if (this.channelNameList[channelName]) {
+      return;
+    }
 
     return new Promise((resolve, reject) => {
       const options = {
@@ -451,6 +455,10 @@ export class MessageService {
           if (!this.messageMapList[channelName]) {
             this.messageMapList[channelName] = [];
             if (channelName.indexOf('-') > -1 || channelName == 'global_room') {
+              let noticeMap = localStorage.getItem('noticeMap') || '{}';
+              noticeMap = JSON.parse(noticeMap);
+              noticeMap[channelName] = 0;
+              localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
               this.getHistoryMessage(channelName, deadline);
             }
           }
@@ -478,10 +486,22 @@ export class MessageService {
       let is_self = item?.get('from_id') == this.userId;
       let data: any = item?.get('content');
       data['is_self'] = is_self;
-      data['istoday'] = true;
       data['timestamp'] = new Date(data.timestamp);
       this.messageMapList[channelName].unshift(data);
     });
+    //处理未读信息红点
+    let noticeMap = localStorage.getItem('noticeMap') || '{}';
+    noticeMap = JSON.parse(noticeMap);
+    if (this.router.url.indexOf('/live/chat/' + channelName) == 0) {
+      noticeMap[channelName] = new Date().getTime();
+      localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
+      this.newNoticeMap.delete(channelName);
+    } else if (msgList.length > 0 && !this.newNoticeMap.has(channelName)) {
+      let lastMsg = this.messageMapList[channelName]?.at(-1);
+      if (!lastMsg.is_self && lastMsg.timestamp > noticeMap[channelName]) {
+        this.newNoticeMap.add(channelName);
+      }
+    }
     // this.messageMapList[channelName].unshift(...msgList);
   }
   /* 取消订阅 */
@@ -523,6 +543,18 @@ export class MessageService {
           timestamp: param.timestamp,
         },
       });
+    } else if (param.channelName.indexOf('-') > -1) {
+      let noticeMap: any = localStorage.getItem('noticeMap') || '{}';
+      noticeMap = JSON.parse(noticeMap);
+      if (
+        this.router.url.indexOf('/live/chat/' + param.channelName) == 0
+      ) {
+        noticeMap[param.channelName] = new Date().getTime();
+        localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
+        this.newNoticeMap.delete(param.channelName);
+      } else if (param.timestamp > noticeMap[param.channelName]) {
+        this.newNoticeMap.add(param.channelName);
+      }
     }
     let data: any = {
       is_self: is_self,
@@ -534,7 +566,6 @@ export class MessageService {
       content: message?.text ?? '',
       publisher: param.publisher,
       timestamp: new Date(param.timestamp),
-      istoday: true,
     };
     this.messageMapList[param.channelName].push(data);
     this.pageFun?.();