Group counters provide each group with the capability to store data of integer type. You can use it to store additional information on a group level, such as the cumulative viewer count, viewing count, number of likes, and the total number of gifts in an audio-video group.
If the key of the group counter to be set already exists, the value of key is updated directly. Otherwise, a key-value pair will be added.
If multiple users set the same counter at the same time, the final value of the counter will be used. It's recommended that the group owner performs counter setting operations.
Sample: Call the setGroupCounters API to set the values of counters key1 and key2 to 0
Android
iOS and macOS
Windows
HashMap<String, Long> counters =newHashMap<>();
counters.put("key1",0);
counters.put("key2",0);
V2TIMManager.getGroupManager().setGroupCounters("your group id", counters,newV2TIMValueCallback<Map<String, Long>>(){
Call the increaseGroupCounter (Android / iOS & macOS / Windows) API to increment the value of a group counter. After the value of the group counter is incremented, the onGroupCounterChanged (Android / iOS & Mac / Windows) callback will be triggered. For the usage of the onGroupCounterChanged callback, see Group Counter Change Notification.
Note
The API parameter value is the change value. Each time when the API is called, the current value is incremented by the value passed in.
If the key of the group counter to be set already exists, the current value is directly incremented by the value passed in. Otherwise, a key will be added, and the default value (0) is incremented by the value passed in.
Sample: Assume that the current value of counter key1 is 8. After you call the increaseGroupCounter API to pass in an increment value 2, the final value of key1 becomes 10.
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().increaseGroupCounter("your group id","key1",2,newV2TIMValueCallback<Map<String, Long>>(){
Call the decreaseGroupCounter (Android / iOS & macOS / Windows) API to decrement the value of a group counter. After the value of the group counter is decremented, the onGroupCounterChanged (Android / iOS & macOS / Windows) callback will be triggered. For the usage of the onGroupCounterChanged callback, see Group Counter Change Notification.
Note
The API parameter value is the change value. Each time when the API is called, the current value is decremented by the value passed in.
If the key of the group counter to be set already exists, the current value is directly decremented by the value passed in. Otherwise, a key will be added, and the default value (0) is decremented by the value passed in.
Sample: Assume that the current value of counter key1 is 8. After you call the decreaseGroupCounter API to pass in a decrement value 2, the final value of key1 becomes 6.
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().decreaseGroupCounter("your group id","key1",2,newV2TIMValueCallback<Map<String, Long>>(){
Call the getGroupCounters (Android / iOS & macOS / Windows) API to pass in a set of keys to get the information of the corresponding group counters. The API will return all key-value pairs matching the keys passed in.
Note
If the key list passed in is empty, all group counters are returned.
Sample: Call the getGroupCounters API to get the values of group counters key1 and key2
When you call the setGroupCounters, increaseGroupCounter, or decreaseGroupCounter API to modify group counters, the SDK will trigger the onGroupCounterChanged callback and return the updated values.
Note
Before you can use the above-mentioned callback, you need to call the addGroupListener (Android / iOS & macOS / Windows) API to add a group listener.
1. A single group supports up to 20 group counters, that is, up to 20 keys per group.
2. For a single group counter, the key can contain up to 128 bytes, and the value must be of integer type (signed integer of up to 64 bits).
3. The setGroupCounters, increaseGroupCounter, and decreaseGroupCounter APIs together can be called by a logged-in user up to 20 times every 5 seconds in the SDK, and the 8516 error code will be called back if the limit is exceeded.
4. The getGroupCounters API can be called by a logged-in user up to 20 times every 5 seconds in the SDK, and the 8516 error code will be called back if the limit is exceeded.