From f5a4168ee16b24f5fcafc99c781ab1ef4c7659b1 Mon Sep 17 00:00:00 2001 From: yj <1095778225@qq.com> Date: Mon, 20 Feb 2023 21:33:27 +0800 Subject: [PATCH] feat: update api in Contact class --- src/api/index.ts | 3 ++- src/contact/index.ts | 45 +++++++++++++++++++++++++++++--------------- src/types.ts | 4 ++++ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index d17133a..0f262c2 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -6,6 +6,7 @@ import { GetMessageListParams, BaseParams, NewBaseParams, + GetFollowAndContactListApiParams, GetGroupMemberListParams, InviteGroupMemberParams, JoinGroupParams, @@ -218,7 +219,7 @@ export const searchContactRequest = async (payload: SearchParams) => { }); }; -export const getContactListRequest = async (payload: NewCommonGetListParams) => { +export const getFollowAndContactListRequest = async (payload: GetFollowAndContactListApiParams) => { return await request.get('/api/user_follow_contacts/', { params: payload, }); diff --git a/src/contact/index.ts b/src/contact/index.ts index 52b39b5..a17054f 100644 --- a/src/contact/index.ts +++ b/src/contact/index.ts @@ -12,7 +12,7 @@ import { import { getDataSignature, newDateFormat, transformAddress } from '../utils'; import { followOperationRequest, - getContactListRequest, + getFollowAndContactListRequest, getFollowerListRequest, getFollowingListRequest, getMyFriendListRequset, @@ -59,6 +59,20 @@ export class Contact { }); return data; } + + async getFollowerAndFollowingList(option: PageParams) { + const { userid, PrivateKey } = this._keys; + const timestamp = Date.now(); + const signContent = userid + timestamp; + const web3mq_user_signature = await getDataSignature(PrivateKey, signContent); + const { data } = await getFollowAndContactListRequest({ + userid, + web3mq_user_signature, + timestamp, + ...option, + }); + return data.user_list; + } async getContactList(option: PageParams): Promise { const { emit } = this._client; @@ -68,20 +82,22 @@ export class Contact { const signContent = userid + timestamp; const web3mq_user_signature = await getDataSignature(PrivateKey, signContent); - const { data } = await getContactListRequest({ + const { data } = await getFollowAndContactListRequest({ userid, web3mq_user_signature, timestamp, + follow_status: 'follow_each', ...option, }); - const newContacts = data.user_list.filter((item: ContactListItemType) => item.follow_status === 'follow_each'); if (this.contactList && option.page !== 1) { - this.contactList = [...this.contactList, ...newContacts]; + this.contactList = [...this.contactList, ...data.user_list]; } else { - this.contactList = newContacts; + this.contactList = data.user_list; + } + if (this._client.listeners.events['contact.getContactList']) { + emit('contact.getContactList', { type: 'contact.getContactList' }); } - emit('contact.getContactList', { type: 'contact.getContactList' }); - return newContacts; + return data.user_list; } async getFollowerList(option: PageParams): Promise { @@ -151,14 +167,13 @@ export class Contact { const did_pubkey = didType === 'starknet' ? PublicKey : undefined; const timestamp = Date.now(); let nonce = sha3_224(userid + action + targetUserid + timestamp); - const sign_content = ` - Web3MQ wants you to sign in with your ${didType} account: - ${address} - - For follow signature - - Nonce: ${nonce} - Issued At: ${newDateFormat(timestamp, 'Y/m/d h:i')}`; + const sign_content = `Web3MQ wants you to sign in with your ${didType} account: +${address} + +For follow signature + +Nonce: ${nonce} +Issued At: ${newDateFormat(timestamp, 'Y/m/d h:i')}`; const { sign: did_signature } = await Client.register.sign(sign_content, address, didType); const data = await followOperationRequest({ did_pubkey, diff --git a/src/types.ts b/src/types.ts index 0aa49b2..6b7c703 100644 --- a/src/types.ts +++ b/src/types.ts @@ -361,6 +361,10 @@ export interface ProfileParams extends BaseParams { avatar_url: string; } +export interface GetFollowAndContactListApiParams extends NewCommonGetListParams { + follow_status?: 'follow_each'; +} + export interface SendFriendParams extends BaseParams { content: string; target_userid: string;