-
{
- WKApp.routeLeft.pop()
- }} action={
-
-
}>
-
+ render(): ReactNode {
+ return (
+
{
+ return new NewFriendVM();
+ }}
+ render={(vm: NewFriendVM) => {
+ return (
+
+
{
+ WKApp.routeLeft.pop();
+ }}
+ action={
+
+
+
+ }
+ >
+
- }}>
-
-
- }
-}
\ No newline at end of file
+ );
+ }}
+ >
+ );
+ }
+}
diff --git a/packages/tsdaodaocontacts/src/NewFriend/vm.tsx b/packages/tsdaodaocontacts/src/NewFriend/vm.tsx
index 76f0354..06b2503 100644
--- a/packages/tsdaodaocontacts/src/NewFriend/vm.tsx
+++ b/packages/tsdaodaocontacts/src/NewFriend/vm.tsx
@@ -1,33 +1,83 @@
+import { WKSDK, Message, CMDContent } from "wukongimjssdk";
import { FriendApplyState, WKApp, ProviderListener } from "@tsdaodao/base";
import { FriendApply } from "@tsdaodao/base";
-
export class NewFriendVM extends ProviderListener {
- friendApplys: FriendApply[] = []
- sureLoading:boolean = false
- currentFriendApply?:FriendApply
+ friendApplys: FriendApply[] = [];
+ sureLoading: boolean = false;
+ currentFriendApply?: FriendApply;
- didMount(): void {
+ async didMount(): Promise
{
+ WKApp.shared.friendApplyMarkAllReaded();
- WKApp.shared.friendApplyMarkAllReaded()
-
- this.friendApplys = WKApp.shared.getFriendApplys()
- this.notifyListener()
+ this.friendApplys = await this.getFriendApply();
+ if (this.friendApplys.length === 0) {
+ this.clearFriendApply();
}
+ this.notifyListener();
+ // 监听好友申请
+ WKSDK.shared().chatManager.addCMDListener(this.friendRequestCMDListener);
+ }
- friendSure(apply: FriendApply) {
- this.sureLoading = true
- this.currentFriendApply = apply
- this.notifyListener()
+ didUnMount(): void {
+ // 监听好友申请
+ WKSDK.shared().chatManager.removeCMDListener(this.friendRequestCMDListener);
+ }
- WKApp.dataSource.commonDataSource.friendSure(apply.token || "").then(() => {
- apply.state = FriendApplyState.accepted
- WKApp.shared.updateFriendApply(apply)
- this.sureLoading = false
- this.notifyListener()
- }).catch(() => {
- this.sureLoading = false
- this.notifyListener()
- })
+ friendSure(apply: FriendApply) {
+ this.sureLoading = true;
+ this.currentFriendApply = apply;
+ this.notifyListener();
+
+ WKApp.dataSource.commonDataSource
+ .friendSure(apply.token || "")
+ .then(() => {
+ apply.status = FriendApplyState.accepted;
+ WKApp.shared.updateFriendApply(apply);
+ this.sureLoading = false;
+ this.notifyListener();
+ })
+ .catch(() => {
+ this.sureLoading = false;
+ this.notifyListener();
+ });
+ }
+
+ async getFriendApply(): Promise {
+ const fromData = {
+ page_index: 1,
+ page_size: 999,
+ };
+ const res = await WKApp.apiClient.get("/friend/apply", {
+ param: fromData,
+ });
+
+ return res;
+ }
+
+ async delFriendApply(apply: FriendApply): Promise {
+ WKApp.apiClient
+ .delete(`/friend/apply/${apply.to_uid}`)
+ .then(async () => {
+ this.friendApplys = await this.getFriendApply();
+ this.sureLoading = false;
+ this.notifyListener();
+ })
+ .catch(() => {
+ this.sureLoading = false;
+ this.notifyListener();
+ });
+ }
+
+ async clearFriendApply(): Promise {
+ await WKApp.apiClient.delete(`/user/reddot/friendApply`);
+ }
+
+ public async friendRequestCMDListener(message: Message) {
+ console.log("收到CMD->", message);
+ const cmdContent = message.content as CMDContent;
+ if (cmdContent.cmd === "friendRequest") {
+ this.friendApplys = await this.getFriendApply();
}
-}
\ No newline at end of file
+ }
+}
diff --git a/packages/tsdaodaocontacts/src/module.tsx b/packages/tsdaodaocontacts/src/module.tsx
index a047af0..38944c2 100644
--- a/packages/tsdaodaocontacts/src/module.tsx
+++ b/packages/tsdaodaocontacts/src/module.tsx
@@ -1,57 +1,105 @@
-import { EndpointCategory, IconListItem, IModule, WKApp, ThemeMode } from "@tsdaodao/base"
-import React from "react"
-import Blacklist from "./Blacklist"
-import { FriendAdd } from "./FriendAdd"
-import GroupSave from "./GroupSave"
-import { NewFriend } from "./NewFriend"
-import { ContactsListManager } from "./Service/ContactsListManager"
-
+import {
+ EndpointCategory,
+ IconListItem,
+ IModule,
+ WKApp,
+ ThemeMode,
+} from "@tsdaodao/base";
+import React from "react";
+import Blacklist from "./Blacklist";
+import { FriendAdd } from "./FriendAdd";
+import GroupSave from "./GroupSave";
+import { NewFriend } from "./NewFriend";
+import { ContactsListManager } from "./Service/ContactsListManager";
export default class ContactsModule implements IModule {
+ id(): string {
+ return "ContactsModule";
+ }
+ init(): void {
+ console.log("【ContactsModule】初始化");
- id(): string {
- return "ContactsModule"
+ WKApp.endpointManager.setMethod(
+ "contacts.friendapply.change",
+ () => {
+ ContactsListManager.shared.refreshList();
+ },
+ {
+ category: EndpointCategory.friendApplyDataChange,
+ }
+ );
+
+ // 获取好友未申请添加数量
+ let unreadCount = 0;
+ if (WKApp.loginInfo.isLogined()) {
+ WKApp.apiClient.get(`/user/reddot/friendApply`).then((res) => {
+ unreadCount = res.count;
+ WKApp.menus.refresh();
+ });
}
- init(): void {
- console.log("【ContactsModule】初始化")
+ WKApp.endpoints.registerContactsHeader("friends.new", (param: any) => {
+ return (
+ {
+ WKApp.routeLeft.push();
+ }}
+ >
+ );
+ });
- WKApp.endpointManager.setMethod("contacts.friendapply.change", () => {
- ContactsListManager.shared.refreshList()
- }, {
- category: EndpointCategory.friendApplyDataChange,
- })
+ WKApp.endpoints.registerContactsHeader("groups.save", (param: any) => {
+ return (
+ {
+ WKApp.routeLeft.push();
+ }}
+ >
+ );
+ });
- WKApp.endpoints.registerContactsHeader("friends.new", (param: any) => {
- return {
- WKApp.routeLeft.push()
- }} >
- })
+ WKApp.endpoints.registerContactsHeader(
+ "contacts.blacklist",
+ (param: any) => {
+ return (
+ {
+ WKApp.routeLeft.push();
+ }}
+ >
+ );
+ }
+ );
- WKApp.endpoints.registerContactsHeader("groups.save", (param: any) => {
- return {
- WKApp.routeLeft.push()
- }}>
- })
-
- WKApp.endpoints.registerContactsHeader("contacts.blacklist", (param: any) => {
- return {
- WKApp.routeLeft.push()
- }}>
- })
-
- WKApp.shared.chatMenusRegister("chatmenus.addfriend",(param)=>{
- const isDark = WKApp.config.themeMode === ThemeMode.dark
- return {
- title: "添加朋友",
- icon: require(`${isDark?"./assets/popmenus_friendadd_dark.png":"./assets/popmenus_friendadd.png"}`),
- onClick:()=>{
- WKApp.routeLeft.push({
- WKApp.routeLeft.pop()
- }}>)
- }
- }
- })
-
- }
-}
\ No newline at end of file
+ WKApp.shared.chatMenusRegister("chatmenus.addfriend", (param) => {
+ const isDark = WKApp.config.themeMode === ThemeMode.dark;
+ return {
+ title: "添加朋友",
+ icon: require(`${
+ isDark
+ ? "./assets/popmenus_friendadd_dark.png"
+ : "./assets/popmenus_friendadd.png"
+ }`),
+ onClick: () => {
+ WKApp.routeLeft.push(
+ {
+ WKApp.routeLeft.pop();
+ }}
+ >
+ );
+ },
+ };
+ });
+ }
+}