目前,还没有方法提供用于一个特定的用户或组的最新消息。但是,您可以获取用户发起聊天的所有联系人和群组的最新消息,或获取特定联系人或群组的所有消息。为此,插件中有一个函数 - getConversationList()。
>>获取用于特定联系人/群会话列表:
按照下面的步骤获得了particualar联系人/群消息:
1)创建一个messageListModel对象:
var messageListModel = {
'startTime' : null, //start time
'endTime' : null, //end time
'contactId' : <your-contact-id>, //(this is string) pass contact id to get the message list for that contact
'searchString' : null, // pass the search string to get the latest messages that match the search string
'channelKey' : <your-group-id>, //(this is number) pass the channel key to get the message list for that channel
'conversationId' : null,
'isScroll' : false, //is scroll will be false if you want to get all list of chats
'isSkipRead' : false,
};
2)将此对象传递给getConversationList()函数:
applozic.getConversationList(messageListModel, (conversationList)=> {
console.log(JSON.stringify(conversationList))
},()=>{});
您将在onSuccess回调函数中收到conversationList。
3)该会话对象有三个对象:
一个)消息 - 消息的特定联系人/组
B)联系 - 如果消息是从组
C也会空)通道 - 如果消息是针对联系人的,则将为空
因此,在您的情况下,您将收到具有与您在messageListModel对象中传递的相同联系人/通道的对话列表。列表中的最后一个对话是您正在寻找的内容。
>>>获取最新消息的所有联系人/组:
你也可以得到最新的消息所有联系人/群用户已inititated与聊天。就像whatsapp主屏幕一样。
1)创建一个messageListModel对象:
var messageListModel = {
'startTime' : null, //start time
'endTime' : null, //end time
'contactId' : null, //pass contact id to get the message list for that contact
'searchString' : null, // pass the search string to get the latest messages that match the search string
'channelKey' : null, // pass the channel key to get the message list for that channel
'conversationId' : null,
'isScroll' : false, //is scroll will be false if you want to get all list of chats
'isSkipRead' : false,
};
2)将此对象传递给getConversationList()函数:
applozic.getConversationList(messageListModel, (conversationList)=> {
console.log(JSON.stringify(conversationList))
},()=>{});
你会在的onSuccess回调函数接收conversationList。
3)该会话对象有三个对象:
一个)消息 - 对接触/组
B)联系最新消息 - 如果该消息是从组
C也会空)通道 - 如果消息联系人
你可以找到在这个列表中的联系人/通道,并得到消息,这将是空。 对话列表按消息创建时间的降序排列。就像你在whatsapp主屏幕上看到的一样。最新的消息是最重要的。因此,如果您的联系人脱离了前60个会话,您需要再次拨打电话,但是这次在下面的消息列表模型对象中传递最新消息的createdAtTime,这会为您提供下一批60个会话:
var messageListModel = {
'startTime' : null, //start time
'endTime' : null, //end time
'contactId' : null, //pass contact id to get the message list for that contact
'searchString' : null, // pass the search string to get the latest messages that match the search string
'channelKey' : null, // pass the channel key to get the message list for that channel
'conversationId' : null,
'isScroll' : false, //is scroll will be false if you want to get all list of chats
'isSkipRead' : false,
'createdAtTime' : conversationList[conversationList.length - 1].message.createdAtTime;
};
如何获得消息的时间:
得到消息的时候,你可以这样做:
conversationList[index].message.createdAtTime;
以下是为您提供方便上述使用的对象的所有属性。对话对象的
属性:消息对象的
interface Conversation{
message : Message;
contact : Contact;
channel : Channel;
}
属性:接触物体的
interface Message{
createdAtTime : number;
to : string;
message : string;
key : string;
deviceKey : string;
userKey : string;
emailIds : string;
shared : boolean;
sent : boolean;
delivered : boolean;
type : number;
storeOnDevice : boolean;
contactIds : string;
groupId : number;
scheduledAt : number;
source : number;
timeToLive : number;
sentToServer : boolean;
fileMetaKey : string;
filePaths : string[];
pairedMessageKey : string;
sentMessageTimeAtServer : number;
canceled : boolean;
clientGroupId : string;
messageId : number;
read : boolean;
attDownloadInProgress : boolean;
applicationId : string;
conversationId : number;
topicId : string;
connected : boolean;
contentType : number;
status : number;
hidden : boolean;
replyMessage : number;
fileMeta : FileMeta;
metadata : Map<string,string>;
}
interface FileMeta{
key : string;
userKey : string;
blobKey : string;
name : string;
url : string;
size : number;
contentType : string;
thumbnailUrl : string;
createdAtTime : number;
}
属性:信道对象的
interface Contact{
firstName : string;
middleName : string;
lastName : string;
emailIdLists : string[];
contactNumberLists : string[];
phoneNumbers : Map<string, string>;
contactNumber : string;
formattedContactNumber : string;
contactId : number;
fullName : string;
userId : string;
imageURL : string;
localImageUrl : string;
emailId : string;
applicationId : string;
connected : boolean;
lastSeenAtTime : number;
checked : boolean;
unreadCount : number;
blocked : boolean;
blockedBy : boolean;
status : string;
userTypeId : number;
contactType : number;
deletedAtTime : number;
latestMessageAtTime : number;
}
性质:
interface Channel{
key : number;
parentKey : number;
clientGroupId : string;
name : string;
adminKey : string;
type : number;
unreadCount : number;
userCount : number;
subGroupCount : number;
imageUrl : string;
notificationAfterTime : number;
localImageUri : string;
contacts : Contact[];
}
什么是'Api'网址是什么? – Sampath
@Sampath我使用这个链接,文档:https://www.applozic.com/docs/ionic-chat-plugin.html#unread-count-for-user – Thakur