# like count

It's easy to implement a request to get the like count for a chat room and increase the count.

# How to use the library

The library does not require a separate API KEY or preset settings to be set in the CMS. Please read and proceed below.


  1. Send like count

This is an example of sending a like count. This API is supposed to only aggregate counts, so if you want to send only once per user, you need to manage the state internally.

VChatCloudApi.getInstance().sendLike(room_id, new ApiCallback() {
    @Override
    public void onFailure(VChatCloudException e) {

    }

    @Override
    public void onSuccess(JSONObject jsonObject) {
        getLike(); // Call the method to get the like count (item 2)
    }
});
1
2
3
4
5
6
7
8
9
10
11
  1. Get like count

Because the like count does not dynamically send a message even if the other person presses it, Implementation is required to make periodic requests to the chat server or to call it back with a custom message. Below is an example of getting the count from the chat server.

String room_id = options.channelKey; //chat room id
VChatCloudApi.getInstance().getLikeCount(room_id, new ApiCallback() {

  @Override
  public void onFailure(VChatCloudException e) {
      Log.e("getLikeCount", "" + e);
  }

  @Override
  public void onSuccess(JSONObject jsonObject) {
      Log.e("getLikeCount", "" + jsonObject);
      android.os.Message msg = likeHandler.obtainMessage();
      msg.obj = jsonObject;
      likeHandler.sendMessage(msg);
  }
});

Handler likeHandler = new Handler(Looper.getMainLooper()) {
    public void handleMessage(android.os.Message msg) {
        JSONObject object = (JSONObject) msg.obj;
        if ((long) object.get("like_cnt") == 0) {
            $titleLikeCount.setText("0");
        } else {
          // Util.valueConversion is a method from the Vchatcloud library.
          // Number This is a utility that cuts the number in the requested unit (1000) and expresses the number and data (unit character) provided.
            $titleLikeCount.setText(Util.valueConversion(new String[] {"", "K", "M", "G", "T", "P", "E", "Z", "Y"}, (long) object.get("like_cnt"), 1000));
        }
    }
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
JSONObject 리턴 데이터
식별자 설명
result_cd int 성공 (1), 실패(0)
like_cnt long 좋아요 카운트
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.