Message replies
A message thread represents a group of messages, consisting of a parent message and message replies.
A message can have multiple replies in a thread. A message that has a thread of replies is a parent message. A parent message and the replies are called a message thread. Every message within a thread is a threaded message. A message that has no replies is an unthreaded message.
Replying to a message
java
InvocationFuture<Void> replyMessage(IMMessage msg, IMMessage replyMsg, boolean resend);
Parameter |
Description |
msg |
Message body to be sent, constituted by {@link MessageBuilder} |
replyMsg |
Replied message |
resend |
If a message is sent unsuccessfully and then sent again, it is marked as "true". Otherwise, as "false". |
javaNIMClient.getService(MsgService.class).replyMessage(message, replymessage.get(0), false).setCallback(new RequestCallback<Void>() {
@Override
public void onSuccess(Void param) {
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
})
Notes: a message is replied with superteamService
in a superteam.
Querying the threaded chat history on cloud
java
InvocationFuture<ThreadTalkHistory> queryThreadTalkHistory(IMMessage anchor, long fromTime, long toTime, int limit, QueryDirectionEnum direction, boolean persist);
Parameter |
Description |
anchor |
Find the anchor. Find object is the message in the corresponding thread |
fromTime |
Start time |
toTime |
End time |
limit |
Limit for the number of messages |
direction |
Direction |
persist |
Determine that it is persisted |
javaNIMClient.getService(MsgService.class).queryThreadTalkHistory(replymessage.get(0), aTime, tTime, msgCount, direction, true).setCallback(new RequestCallback<ThreadTalkHistory>() {
@Override
public void onSuccess(ThreadTalkHistory thread) {
if (thread == null) {
Toast.makeText(SessionExtension.this, R.string.msg_history_empty, Toast.LENGTH_SHORT).show();
return;
}
MsgHistoryActivity.startActivity(SessionExtension.this, thread.getReplyList());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable throwable) {
Log.e(TAG, "pull server message exception:" + throwable);
}
});
Getting the number of replies to a threaded message
Get the number of replies to a threaded message from a local database.
java
int queryReplyCountInThreadTalkBlock(IMMessage msg);
Parameter |
Description |
msg |
A certain message in a thread |
javaint count = NIMClient.getService(MsgService.class).queryReplyCountInThreadTalkBlock(replymessage.get(0));
You can add a quick comment to a message. The comment content is long type, instead of a message. The correlation between comment content and interface display is specified by the upper layer.
java
InvocationFuture<Long> addQuickComment(IMMessage msg, long replyType, String ext, boolean needPush, boolean needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayload);
Parameter |
Description |
msg |
Reply object |
replyType |
Reply type |
ext |
User-defined extension field, max. size 8 characters |
needPush |
Determine if a push is needed |
needBadge |
Determine that corner mark is needed |
pushTitle |
Push title |
pushContent |
Push content |
pushPayload |
The third-party defined push attribute, limited to json type |
javaNIMClient.getService(MsgService.class).addQuickComment(message, replytype, qcmsgExtEdit.getText().toString(), needpush, needbadge,
pushTitleEdit.getText().toString(), pushContentEdit.getText().toString(), null).setCallback(new RequestCallback<Long>() {
@Override
public void onSuccess(Long param) {
Toast.makeText(SessionExtension.this, "Add a quick comment successfully", Toast.LENGTH_SHORT).show();
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
java
InvocationFuture<Long> removeQuickComment(IMMessage msg, long replyType, String ext, boolean needPush, boolean needBadge, String pushTitle, String pushContent, Map<String, Object> pushPayload);
Parameter |
Description |
msg |
Reply object |
replyType |
Reply type |
ext |
User-defined extension field, max. size 8 characters |
needPush |
Determine if a push is needed |
needBadge |
Determine that corner mark is needed |
pushTitle |
Push title |
pushContent |
Push content |
pushPayload |
The third-party defined push attribute, limited to json type |
javaNIMClient.getService(MsgService.class).removeQuickComment(message, replytype, qcmsgExtEdit.getText().toString(), needpush, needbadge,
pushTitleEdit.getText().toString(), pushContentEdit.getText().toString(), null).setCallback(new RequestCallback<Long>() {
@Override
public void onSuccess(Long param) {
Toast.makeText(SessionExtension.this, "Delete a quick comment successfully", Toast.LENGTH_SHORT).show
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
java
InvocationFuture<List<QuickCommentOptionWrapper>> queryQuickComment(List<IMMessage> msgList);
Parameter |
Description |
msgList |
Each element is a message which is queried for a quick comment, of which the number cannot exceed 20. |
javaNIMClient.getService(MsgService.class).queryQuickComment(msglist).setCallback(new RequestCallback<List<QuickCommentOptionWrapper>>() {
@Override
public void onSuccess(List<QuickCommentOptionWrapper> param) {
showQuickComment(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
Favorites
Users can add a character string within 20 kb in size to Favorites.
java
InvocationFuture<CollectInfo> addCollect(int type, String date, String ext, String uniqueId);
Parameter |
Description |
type |
Type of favorite |
date |
Favorite content, max. size 20k |
ext |
Extension field, max. size 1k |
uniqueId |
A unique ID |
javaNIMClient.getService(MsgService.class).addCollect(1, logJson.toString(), extEdit.getText().toString(), UniqueIdEdit.getText().toString()).setCallback(
new RequestCallback<CollectInfo>() {
@Override
public void onSuccess(CollectInfo param) {
Toast.makeText(SessionExtension.this, "Add a collection successfully", Toast.LENGTH_SHORT).show();
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
}
);
Removing multiple messages from Favorites at a time
java
InvocationFuture<Integer> removeCollect(List<Pair<Long, Long>> collectInfo);
Parameter |
Description |
collectInfo |
List of key information to be removed from favorites. Each item is a Pair. The first item is the ID of favorite and the second item is the creation time of favorite. |
javaNIMClient.getService(MsgService.class).removeCollect(collectInfo).setCallback(
new RequestCallback<Integer>() {
@Override
public void onSuccess(Integer param) {
Toast.makeText(SessionExtension.this, "Remove collections at a time successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
}
);
Updating the extension field of Favorites
java
InvocationFuture<CollectInfo> updateCollect(long infoId, long createTime, String ext);
Parameter |
Description |
infoId |
ID of favorite to be updated |
createTime |
Creation time of favorite to be updated |
ext |
Updated extension field |
javaNIMClient.getService(MsgService.class).updateCollect(collectId,collectCreateTime,extEdit.getText().toString()).setCallback(new RequestCallback<CollectInfo>() {
@Override
public void onSuccess(CollectInfo param) {
Toast.makeText(SessionExtension.this, "Update extension field of a collection successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
Querying Favorites by page
java
InvocationFuture<CollectInfoPage> queryCollect(CollectInfo anchor, long toTime, int limit, QueryDirectionEnum direction);
Parameter |
Description |
anchor |
Final favorite of end query (not included in query results) |
toTime |
End time. Unit: millisecond |
limit |
Limit for the number of messages for query (max. 100) |
direction |
Query direction |
javaNIMClient.getService(MsgService.class).queryCollect(null, tTime, limit, direction).setCallback(
new RequestCallback<CollectInfoPage>() {
@Override
public void onSuccess(CollectInfoPage param) {
if (param == null) {
Toast.makeText(SessionExtension.this, "The list of collections queried by paging from the server is null",
Toast.LENGTH_SHORT).show();
return;
}
addCollects(param.getCollectList());
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
}
);
All users of a session can mark PIN for a message, cancel PIN, query PIN, and update the extension field. A message can be marked with one PIN only. If multiple users mark PIN for a message, the final PIN will cover the early PIN.
Adding a PIN tag to a message
java
InvocationFuture<Long> addMsgPin(IMMessage msg, String ext);
Parameter |
Description |
msg |
Message marked with PIN |
ext |
Extension field |
javaNIMClient.getService(MsgService.class).addMsgPin(message, pinmsgExtEdit.getText().toString()).setCallback(new RequestCallback<Long>() {
@Override
public void onSuccess(Long param) {
Toast.makeText(SessionExtension.this, "Mark PIN for a message successfully", Toast.LENGTH_SHORT).show();
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
Updating the PIN tag of a message
java
InvocationFuture<Long> updateMsgPin(IMMessage msg, String ext);
Parameter |
Description |
msg |
Message marked with PIN |
ext |
Extension field |
javaNIMClient.getService(MsgService.class).updateMsgPin(message, pinmsgExtEdit.getText().toString()).setCallback(new RequestCallback<Long>() {
@Override
public void onSuccess(Long param) {
Toast.makeText(SessionExtension.this, "Update PIN of a message successfully", Toast.LENGTH_SHORT).show();
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
Remove the PIN tag from a message
java
InvocationFuture<Long> removeMsgPin(IMMessage msg, String ext);
Parameter |
Description |
msg |
Message marked with PIN |
ext |
Extension field |
javaNIMClient.getService(MsgService.class).removeMsgPin(message, pinmsgExtEdit.getText().toString()).setCallback(new RequestCallback<Long>() {
@Override
public void onSuccess(Long param) {
Toast.makeText(SessionExtension.this, "Remove PIN of a message successfully", Toast.LENGTH_SHORT).show();
showOnLog(logText, logJson.toString());
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
});
java
InvocationFuture<MsgPinSyncResponseOptionWrapper> syncMsgPin(SessionTypeEnum sessionType, String sessionId, long timestamp);
Parameter |
Description |
sessionType |
Session type |
sessionId |
Session ID |
timestamp |
timestamp, PIN after synchronizing timestamp |
javaNIMClient.getService(MsgService.class).syncMsgPin(getSessionType(), recipientEdit.getText().toString(), 0).setCallback(new RequestCallback<MsgPinSyncResponseOptionWrapper>() {
@Override
public void onSuccess(MsgPinSyncResponseOptionWrapper msgPinSync) {
if (msgPinSync == null) {
Toast.makeText(SessionExtension.this, "PIN information about a session queried in server is null",
Toast.LENGTH_SHORT).show();
return;
}
if (!msgPinSync.isChanged()) {
Toast.makeText(SessionExtension.this, "No change", Toast.LENGTH_SHORT).show();
return;
}
ArrayList<IMMessage> msgList = new ArrayList<>();
for (MsgPinSyncResponseOption infoList : msgPinSync.getMsgPinInfoList()) {
String uuid = infoList.getKey().getUuid();
IMMessage msg = MsgDBHelper.queryMessageByUuid(uuid);
if (msg == null) {
continue;
}
msgList.add(msg);
}
MsgHistoryActivity.startActivity(SessionExtension.this, msgList);
}
@Overridetong
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
java
List<MsgPinDbOption> queryMsgPinBlock(String sessionId, SessionTypeEnum sessionType);
Parameter |
Description |
sessionId |
Session ID |
sessionType |
Session type |
javaList<MsgPinDbOption> msgPinDbOptions = NIMClient.getService(MsgService.class).queryMsgPinBlock(recipientEdit.getText().toString(), getSessionType());
Pinning sessions
Pinning a session
java
InvocationFuture<StickTopSessionInfo> addStickTopSession(String sessionId, SessionTypeEnum sessionType, String ext);
Parameter |
Description |
sessionId |
Session ID |
sessionType |
Session type |
ext |
Extension field, can contain up to 512 characters |
javaNIMClient.getService(MsgService.class).addStickTopSession(recipientEdit.getText().toString(), getSessionType(), extEdit.getText().toString()).setCallback(
new RequestCallback<StickTopSessionInfo>() {
@Override
public void onSuccess(StickTopSessionInfo param) {
Toast.makeText(SessionExtension.this, "Add a pinned session successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
}
);
Deleting a pinned session
java
InvocationFuture<Void> removeStickTopSession(String sessionId, SessionTypeEnum sessionType, String ext);
Parameter |
Description |
sessionId |
Session ID |
sessionType |
Session type |
ext |
Extension field, can contain up to 512 characters |
javaNIMClient.getService(MsgService.class).removeStickTopSession(recipientEdit.getText().toString(), getSessionType(), extEdit.getText().toString()).setCallback(
new RequestCallback<Void>() {
@Override
public void onSuccess(Void param) {
Toast.makeText(SessionExtension.this, "Delete a stick top session successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
}
);
Updating an extension field
java
InvocationFuture<StickTopSessionInfo> updateStickTopSession(String sessionId, SessionTypeEnum sessionType, String ext);
Parameter |
Description |
sessionId |
Session ID |
sessionType |
Session type |
ext |
Extension field, can contain up to 512 characters |
javaNIMClient.getService(MsgService.class).updateStickTopSession(recipientEdit.getText().toString(), getSessionType(), extEdit.getText().toString()).setCallback(
new RequestCallback<StickTopSessionInfo>() {
@Override
public void onSuccess(StickTopSessionInfo param) {
Toast.makeText(SessionExtension.this, "Update extension field of a stick top session successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int code) {
Toast.makeText(SessionExtension.this, "Failed:" + code, Toast.LENGTH_SHORT).show();
}
@Override
public void onException(Throwable exception) {
Log.e(TAG, "pull server message exception:" + exception);
}
}
);
Getting the list of pinned sessions
Notes: You must set "notifyStickTopSession" of initialization parameter "SDKOptions" as "true" and then enable the feature of synchronizing top session list to query detailed top session list using the following interface. Otherwise, the queried list does not include offline alteration.
java
List<StickTopSessionInfo> queryStickTopSessionBlock();
javaList<StickTopSessionInfo> sticktopsession = NIMClient.getService(MsgService.class).queryStickTopSessionBlock();