tencent cloud

Chat

News and Announcements
Release Notes
Announcements
Product Introduction
Overview
Basic Concepts
Scenarios
Features
Account System
User Profile and Relationship Chain
Message Management
Group Related
Official Account
Audio/Video Call
Use Limits
Purchase Guide
Billing Overview
Pricing
Purchase Instructions
Renewal Guide
Service Suspension Explanation
Refund Policy
Development Guidelines
Demo Zone
Activate Service
Free Demos
Quick Run
Download
SDK and Demo Source Code
Update Log
Chat Interaction (UI Included)
TUIKit Introduction
Getting Started
Full-feature Integration
Single-function Integration
Build with AI
Build Basic Interfaces
More Features
Customizing Appearance
Internationalization
Push Service
Overview
Noun explanation
Activate the Service
Quick Start
Manufacturer Channel
Statistics
Troubleshooting Tool
Client APIs
REST API
Push Callback
Advanced Features
Release Notes
Error Codes
FAQS
Desk
Overview
Quick Start
Integration Guide
Admin Operation Manual
Agent Manual
More Practices
Live Streaming Setup Guide
AI Chatbot
Super Large Entertainment and Collaboration Community
Discord Implementation Guide
How to Integrate Chat into Games
WhatsApp Channel-style Official Account Integration Solution
Send Red Packet
Firewall Restrictions
No UI Integration
Quick Start
SDK Integration
Initialization
Login and Logout
Message
Conversation
Group
Community Topic
User Profile and Relationship Chain
Offline Push
Cloud Search
Local Search
Official Channel Management
Client APIs
JavaScript
Android
iOS & macOS
Swift
Flutter
Electron
Unity
React Native
C APIs
C++
Server APIs
Secure authentication with UserSig
RESTful APIs
Webhooks
Console Guide
New Console Introduction
Creating and Upgrading an Application
Basic Configuration
Feature Configuration
Account Management
Group Management
Official Channel Management
Webhook Configuration
Usage
Viewing Guide for Resource Packages
Real-Time Monitor
Auxiliary Development Tools
Access Management
Advanced Features
FAQs
uni-app FAQs
Purchase
SDK
Account Authentication
User Profile and Relationship Chain
Message
Group
Audio-Video Group
Nickname and Profile Photo
Security Compliance Certification
Service Level Agreement
Security Compliance Certification
Chat Policies
Privacy Policy
Data Privacy and Security Agreement
Migration
Migration Solutions
Migration Solutions Lite
Error Codes
Contact Us

Flutter

PDF
Focus Mode
Font Size
Last updated: 2025-04-16 15:00:22

Overview

The Chat SDK supports friend management, and users can add and delete friends and set to send messages only to friends.

Getting the contacts

The Chat SDK supports the logic for the friend contacts. You can call the getFriendList API (details) to get contacts.
Sample code:
// Obtain the contacts
V2TimValueCallback<List<V2TimFriendInfo>> friendsList = await friendshipManager.getFriendList();

Adding friends

Call the addFriend API (details) to add a friend.
Sample code:
// Add a two-way friend
V2TimValueCallback<V2TimFriendOperationResult> addFriend = await friendshipManager.addFriend(userID: "userID",remark:"Friend request remarks",addWording:"Remarks",addType:FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH);
The process has the following variations depending on whether friend verification is required.

Friend request approval is not required

1. Users A and B call setFriendListener to set the contacts listener.
2. User B specifies that friend request approval is not required (V2TIM_FRIEND_ALLOW_ANY) through the allowType field (details) in the setSelfInfo function.
3. User A can add user B as a friend successfully by calling addFriend, after which the addType of the V2TIMFriendAddApplication request parameter can be set to either value as needed:
If it is set to V2TIM_FRIEND_TYPE_BOTH (two-way friend), both users A and B will receive the onFriendListAdded callback (details).
If it is set to V2TIM_FRIEND_TYPE_SINGLE (one-way friend), only user A will receive the onFriendListAdded callback.

Friend request approval is required

1. Users A and B call setFriendListener to set the contacts listener.
2. User B specifies that friend request approval is required (V2TIM_FRIEND_NEED_CONFIRM) through the allowType field in the setSelfInfo function.
3. User A calls addFriend to request to add user B as a friend. The resultCode parameter in the callback for successful API call returns 30539, indicating that the request needs to be approved by user B. In addition, both users A and B will receive the onFriendApplicationListAdded callback (details).
4. User B will receive the onFriendApplicationListAdded callback. If type in the V2TIMFriendApplication parameter is V2TIM_FRIEND_APPLICATION_COME_IN, user B can accept or reject the request.
User B calls acceptFriendApplication API (details) to accept the friend request. If the type is V2TIM_FRIEND_ACCEPT_AGREE (one-way friend):
User A will receive the onFriendListAdded callback, indicating that the one-way friend was added successfully.
User B will receive the onFriendApplicationListDeleted callback (details). At this point, user B has become a friend of user A, but not vice versa.
User B calls acceptFriendApplication to accept the friend request. If the type is V2TIM_FRIEND_ACCEPT_AGREE_AND_ADD (two-way friend), both users A and B will receive the onFriendListAdded callback, indicating that they added each other as a friend successfully.
User B calls refuseFriendApplication API (details) to reject the friend request, and both users will receive the onFriendApplicationListDeleted callback.

Deleting friends

Call the deleteFromFriendList API (details) to delete a friend.
Sample code:
// Two-way deletion
V2TimValueCallback<List<V2TimFriendOperationResult>> deleteres = await friendshipManager.deleteFromFriendList(deleteType: FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH,userIDList:['user1']);

Checking friend relationships

Call the checkFriend API (details) to check the friend relationship.
Sample code:
// Check whether the friend relationship is one-way or two-way
V2TimValueCallback<List<V2TimFriendCheckResult>> checkres = await friendshipManager.checkFriend(checkType:FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH,userIDList: [] );

Setting to send messages to friends only

By default, Chat SDK does not check the relationship when sending one-to-one messages. This default setting is generally applied in customer service scenarios, where having to friend a customer service agent before chatting is inefficient.
If you want to implement the interaction mode of "friending before chatting", go to Chat console -> Feature Configuration -> Login and Message -> Relationship Check and enable "Check Relationship for One-to-One Messages". With this feature enabled, users can only send messages to friends, and will receive the 20009 error code from SDK when sending a message to a non-friend user.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback