qiscus / qiscus-sdk-android

Qiscus provide everything you need to power up your app with chats. And it's now made simple.
https://www.qiscus.com
Apache License 2.0
201 stars 84 forks source link

add extras in comment #23

Closed andhikayuana closed 7 years ago

andhikayuana commented 7 years ago

you can intercept comment before send to server like this :

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.qiscus.sdk.Qiscus;

/** intercept **/
Qiscus.getChatConfig()
                .setCommentSendingInterceptor(qiscusComment -> {
                    qiscusComment.setExtras(extras());
                    return qiscusComment;
                });

/** some extras method **/
private JsonObject extras() {
        return new Gson().fromJson("{\"id\":123, \"name\": \"yuana\"}", JsonObject.class);
    }
codecov[bot] commented 7 years ago

Codecov Report

Merging #23 into develop will not change coverage. The diff coverage is 0%.

Impacted file tree graph

@@          Coverage Diff           @@
##           develop    #23   +/-   ##
======================================
  Coverage        0%     0%           
======================================
  Files          119    119           
  Lines         9425   9454   +29     
  Branches       972    978    +6     
======================================
- Misses        9425   9454   +29
Impacted Files Coverage Δ
...ain/java/com/qiscus/sdk/data/remote/QiscusApi.java 0% <0%> (ø) :arrow_up:
...va/com/qiscus/sdk/data/remote/QiscusApiParser.java 0% <0%> (ø) :arrow_up:
...om/qiscus/sdk/data/local/QiscusDataBaseHelper.java 0% <0%> (ø) :arrow_up:
...va/com/qiscus/sdk/data/remote/QiscusPusherApi.java 0% <0%> (ø) :arrow_up:
...va/com/qiscus/sdk/data/model/QiscusChatConfig.java 0% <0%> (ø) :arrow_up:
.../java/com/qiscus/sdk/data/model/QiscusComment.java 0% <0%> (ø) :arrow_up:
.../main/java/com/qiscus/sdk/data/local/QiscusDb.java 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fbd7632...c67ac21. Read the comment docs.

andhikayuana commented 7 years ago

using extras :

import com.qiscus.sdk.Qiscus;

import org.json.JSONException;
import org.json.JSONObject;

/** intercept **/
Qiscus.getChatConfig()
                .setCommentSendingInterceptor(qiscusComment -> {
                    qiscusComment.setExtras(extras());
                    return qiscusComment;
                });

/** generate extras **/
private JSONObject extras() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("id", 123);
            jsonObject.put("name", "yuana");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }