Applozic Ionic为用户获取最后一条消息

Tha*_*kur 2 chat applozic ionic2 ionic3

在Applozic/Ionic集成应用程序中,我需要为用户或组获取最后的消息和聊天时间

我已经阅读了Applozic - Ionic集成的文档,但还没有找到上面的解决方案.它只在下面提到

//Get Total Unread Count
applozic.getUnreadCount(function(response){
     var count = response;
    },
    function(error){alert(error)
   });
   
//Get Unread count per user
   var userId = 'USER_ID'; //pass UserId with which unread count 
   applozic.getUnreadCountForUser(userId,function(response){
     var count = response;
    },
    function(error){alert(error)
   });
   
 //Get unread count per group
   var groupId = 'GROUP_ID'; // pass groupId in which unreadcount required

  applozic.getUnreadCountForGroup(groupId,function(response){
       var count = response;
    },
     function(error){
    });
Run Code Online (Sandbox Code Playgroud)

Ash*_*wal 5

目前,没有方法为特定用户或组提供最新消息.但是,您可以获取用户已启动与OR聊天的所有联系人和组的最新消息,或者获取特定联系人或组的所有消息.为此,插件中有一个函数 - getConversationList().

>>获取特定联系人/小组的对话列表:

按照以下步骤获取特定联系人/组的消息:

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,
  };
Run Code Online (Sandbox Code Playgroud)

2)将此对象传递给getConversationList()函数:

applozic.getConversationList(messageListModel, (conversationList)=> {
console.log(JSON.stringify(conversationList))
}, ()=>{});
Run Code Online (Sandbox Code Playgroud)

您将在onSuccess回调函数中收到conversationList.

3)会话对象有三个对象:

a)消息 - 特定联系人/组的消息

b)联系 - 如果消息来自组,则为null

c)频道 - 如果消息是针对联系人,则为空

因此,在您的情况下,您将收到一个对话列表,其中包含您在messageListModel对象中传递的相同联系人/频道.列表中的最后一次对话就是您要找的内容.

>>>获取所有联系人/组的最新消息:

您还可以获取用户已启动聊天的所有联系人/组的最新消息.就像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,
  };
Run Code Online (Sandbox Code Playgroud)

2)将此对象传递给getConversationList()函数:

applozic.getConversationList(messageListModel, (conversationList)=> {
console.log(JSON.stringify(conversationList))
}, ()=>{});
Run Code Online (Sandbox Code Playgroud)

您将在onSuccess回调函数中收到conversationList.

3)会话对象有三个对象:

a)消息 - 联系人/组的最新消息

b)联系 - 如果消息来自组,则为null

c)频道 - 如果消息是针对联系人,则为空

您可以在此列表中找到联系人/频道,并获取相关消息."对话"列表按照创建消息的时间降序排序.就像你在whatsapp主屏幕上看到的那样.最新消息在最前面.因此,如果您的联系人不在前六次会话中,您需要再次拨打电话,但这次在消息列表模型对象中传递最新消息的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;
      };
Run Code Online (Sandbox Code Playgroud)

如何获取消息的时间:

要获取消息的时间,您可以执行以下操作:

conversationList[index].message.createdAtTime;
Run Code Online (Sandbox Code Playgroud)

以下是上述使用对象的所有属性,以方便您使用.

会话对象的属性:

interface Conversation{
  message : Message;
  contact : Contact;
  channel : Channel;
}
Run Code Online (Sandbox Code Playgroud)

Message对象的属性:

    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;
}
Run Code Online (Sandbox Code Playgroud)

联系对象的属性:

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;
}
Run Code Online (Sandbox Code Playgroud)

Channel对象的属性:

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[];
}
Run Code Online (Sandbox Code Playgroud)