SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/chat/chat-history-item-vo.js

129 lines
3.7 KiB
JavaScript

"use strict";
/**
* Value object for asset item.
*
* @constructor
*/
function ChatHistoryItemVO() {
this.id = '';
this.mucJid = '';
// database fields
this.messagesCount = 0;
this.connection = null;
this.startDate = null;
this.lastActivity = null;
this.participants = [];
this.roster = {};
//this.messages = [];
}
// inherit BaseVO
ChatHistoryItemVO.prototype = new BaseVO();
// correct the constructor pointer
ChatHistoryItemVO.prototype.constructor = ChatHistoryItemVO;
/**
* @override
* @return {Array}
*/
ChatHistoryItemVO.prototype.getProps = function () {
return ['id', 'mucJid', 'messagesCount', 'lastActivity', 'startDate', 'lastActivity', 'participants', 'connection'];
};
/**
* @override
*/
ChatHistoryItemVO.prototype.postBuild = function () {
};
ChatHistoryItemVO.prototype.listParticipants = function () {
var namesList = [];
_.each(this.roster, function (userProfile, userId) {
if (userProfile) {
namesList.push(userProfile.fullName || userProfile.displayName);
}
else {
namesList.push(userId.split('_')[0]);
}
});
return namesList.join(', ');
};
ChatHistoryItemVO.prototype.getStartDate = function () {
return moment(this.startDate).calendar({ sameElse: 'lll' });
};
ChatHistoryItemVO.prototype.getEndDate = function () {
return moment(this.lastActivity).calendar({ sameElse: 'lll' });
};
ChatHistoryItemVO.prototype.fillRoster = function (cachedProfiles) {
var self = this;
_.each(this.participants, function (userId) {
self.roster[userId] = cachedProfiles[userId];
if (self.roster[userId] && self.roster[userId].thumbnail) {
self.selectedUser = self.roster[userId];
}
});
if (!this.selectedUser) {
var selectedId = this.participants[0];
this.selectedUser = this.roster[selectedId];
}
};
ChatHistoryItemVO.prototype.generateRelatedItemTitle = function () {
var relatedItemTitle = '', summary, displayId;
if (this.parent) {
if (this.parent.ticketType && this.parent.ticketType === EntityVO.TYPE_ASSET) {
summary = this.parent.name;
displayId = EntityVO.TYPE_ASSET.toUpperCase();
}
else {
summary = this.parent.summary;
displayId = this.parent.displayId;
}
relatedItemTitle = _.compact([displayId, summary]).join(': ');
}
return relatedItemTitle;
};
/*ChatHistoryItemVO.prototype.generateChatTopic = function() {
if(this.parent){
var topicParts = []
if(this.parent.ticketType && this.parent.ticketType == EntityVO.TYPE_ASSET){
topicParts = [EntityVO.TYPE_ASSET.toUpperCase(),this.parent.name];
}
else{
topicParts = [this.parent.displayId,this.parent.summary];
}
return topicParts.join(": ");
}
}
ChatHistoryItemVO.prototype.getParticipantJIDsArray = function() {
var JIDsList = [];
_.each(this.participants, function(user){
var jid = Strophe.getNodeFromJid(user.jid);
JIDsList.push(jid);
});
return JIDsList;
}
ChatHistoryItemVO.prototype.generateRosterSummary = function() {
var self = this;
if(this.participants){
var participantNamesList = [],
participantsCount = _.size(this.participants);
_.each(this.participants, function(user, nick) {
if(nick == self.room.nick) return;
var userJID = user.jid.split("@")[0],
userProfile = self.roster[userJID] || {};
if(participantsCount <= 3){
var userName = userProfile.firstName ? (userProfile.fullName || userProfile.displayName) : nick.replace("_"," ");
}
else{
var userName = userProfile.firstName ? userProfile.firstName : nick.split("_")[0];
};
participantNamesList.push(userName);
})
if(participantNamesList.length){
return participantNamesList.join(", ");
}
}
return "";
}*/