notice-log.component.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { CommonModule, DatePipe } from '@angular/common';
  2. import { Component, OnInit } from '@angular/core';
  3. import { NavComponent } from '../../../app/components/nav/nav.component';
  4. import { AiChatService } from '../../../services/aichart.service';
  5. import {
  6. ionicStandaloneModules,
  7. LoadingController,
  8. ToastController,
  9. } from '../../ionic-standalone.modules';
  10. import * as Parse from 'parse';
  11. import { InfiniteScrollCustomEvent } from '@ionic/core';
  12. import { Router } from '@angular/router';
  13. import { MessageService } from '../../../services/message.service';
  14. @Component({
  15. selector: 'app-notice-log',
  16. templateUrl: './notice-log.component.html',
  17. styleUrls: ['./notice-log.component.scss'],
  18. standalone: true,
  19. imports: [...ionicStandaloneModules, NavComponent, CommonModule],
  20. providers: [DatePipe],
  21. })
  22. export class NoticeLogComponent implements OnInit {
  23. list: Array<any> = [];
  24. user: Parse.Object = Parse.User.current()!;
  25. constructor(
  26. public toastController: ToastController,
  27. private loadingCtrl: LoadingController,
  28. private router: Router,
  29. private msgSer: MessageService,
  30. private aiSer: AiChatService
  31. ) {}
  32. ngOnInit() {
  33. this.getLog();
  34. }
  35. async getLog() {
  36. let uid: any = Parse.User.current()?.id;
  37. let r = await this.aiSer.getSysNotice(uid, 20, this.list.length);
  38. this.list.push(...r?.data);
  39. return r?.data;
  40. }
  41. async onIonInfinite(ev: any) {
  42. let uid: any = Parse.User.current()?.id;
  43. let result = await this.aiSer.getSysNotice(uid, 20, this.list.length);
  44. if (result.data.length == 0) {
  45. (ev as InfiniteScrollCustomEvent).target.disabled = true;
  46. }
  47. setTimeout(() => {
  48. (ev as InfiniteScrollCustomEvent).target.complete();
  49. }, 500);
  50. }
  51. toUrl(url: string) {
  52. this.router.navigate([url]);
  53. }
  54. async onApply(id: string, index: number, pass: boolean) {
  55. let isAnthor = this.aiSer.identity
  56. const loading = await this.loadingCtrl.create({
  57. message: '加载中',
  58. });
  59. loading.present();
  60. this.list[index].status = pass ? '200' : '101';
  61. let query = new Parse.Query('Friends');
  62. let res = await query.get(id);
  63. res.set('isPass', pass);
  64. if(pass){
  65. let channel = isAnthor ? `${this.user.id}-${this.list[index].tuid}` : `${this.list[index].tuid}-${this.user.id}`
  66. res.set('channel', channel)
  67. this.msgSer.subscribeMessage(channel); //同意好友邀请并且订阅频道
  68. }
  69. await res.save();
  70. loading.dismiss();
  71. const toast = await this.toastController.create({
  72. message: `已${pass ? '通过' : '拒绝'}申请`,
  73. color: 'success',
  74. duration: 1000,
  75. });
  76. toast.present();
  77. }
  78. }