2017-10-11 63 views
2

在Applozic /離子綜合應用,我需要聊天的最後消息,時間爲一個用戶或組Applozic離子得到最後消息的用戶

我已閱讀Applozic文檔 - 離子結合,但還沒有找到一個以上解決方案。僅提及了下面

//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){ 
 
    });

+0

什麼是'Api'網址是什麼? – Sampath

+0

@Sampath我使用這個鏈接,文檔:https://www.applozic.com/docs/ionic-chat-plugin.html#unread-count-for-user – Thakur

回答

5

目前,還沒有方法提供用於一個特定的用戶或組的最新消息。但是,您可以獲取用戶發起聊天的所有聯繫人和羣組的最新消息,或獲取特定聯繫人或羣組的所有消息。爲此,插件中有一個函數 - 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[]; 
} 
+0

上述功能不被AppLozic離子文檔中提到。感謝這些信息,它確實有幫助,並最終我想像這樣定製我的屏幕。我試圖獲取>>爲特定聯繫人/羣會話列表:通過提的ContactID:'[email protected]」,並保持channelKey:空 - 我得到錯誤‘一些錯誤,而獲取信息’。當我嘗試>>>獲取所有聯繫人/組的最新消息:使用var messageListModel,如上所述,應用程序退出。爲什麼會發生? – Thakur

+0

沒有任何鏈接,離子/ applozic的詳細資料,如你所知,這些功能都沒有在applozic.com/docs/ionic-chat-plugin.html – Thakur

+0

你能從日誌,當應用程序退出 –

相關問題