chat-util.js 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// 名前空間
var CHAT_UTIL = {};

CHAT_UTIL.isAndroid = function() {
	return PLATFORM == 'android';
};

CHAT_UTIL.isIOS = function() {
	return PLATFORM == 'ios';
};

CHAT_UTIL.isMobile = function() {
	return IS_MOBILE == 'true';
};

CHAT_UTIL.formatDate = function(date) {
	const REFERENCE = moment();
	const TODAY = REFERENCE.clone().startOf('day');
	let createdAt = moment(date);
	if (date.length == 14) {
	  createdAt = moment(date,'YYYYMMDDhhmmss');
	} else {
	  createdAt = moment(date);
	}

	// #36171
	const createdAtDay = createdAt.format('MMM Do');
	const createdAtTime = createdAt.format('HH:mm');
	if (createdAt.isSame(TODAY, 'd')) {
		createdAt = createdAtTime;
	} else {
		createdAt = createdAtDay;
	}
	let rntDate = new Object();
	rntDate.createdAtDay = createdAtDay;
	rntDate.createdAtTime = createdAtTime;
	rntDate.createdAt = createdAt;
	return rntDate;
}

CHAT_UTIL.htmlDecode = function(input) {
	var e = document.createElement('textarea');
	e.innerHTML = input;
	// handle case of empty input
	return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}

//generates a unique id, not obligator a UUID
CHAT_UTIL.generateUUID = function() {
	var d = new Date().getTime();
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		var r = (d + Math.random()*16)%16 | 0;
		d = Math.floor(d/16);
		return (c=='x' ? r : (r&0x3|0x8)).toString(16);
	});
	return uuid;
};
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

CHAT_UTIL.systemDay = function(date) {
    let createdAt = moment(date);
    createdAt = moment(date,'YYYYMMDDhhmmss');
    const createdAtDow = createdAt.format('YYYY-MM-DD');

    let systemDay = new Object();
    systemDay.year = createdAt.format('YYYY');
    systemDay.month = createdAt.format('MM');
    systemDay.day = createdAt.format('DD');
    systemDay.dow = moment(createdAtDow).day();

    return systemDay;
}

CHAT_UTIL.findDow = function(data) {
    let dow = "";
    if (data == 0) {
        dow = getLocalizedString('sunday');
    } else if (data == 1) {
        dow = getLocalizedString('monday');
    } else if (data == 2) {
        dow = getLocalizedString('thusday');
    } else if (data == 3) {
        dow = getLocalizedString('wednesday');
    } else if (data == 4) {
        dow = getLocalizedString('thursday');
    } else if (data == 5) {
        dow = getLocalizedString('friday');
    } else if (data == 6) {
        dow = getLocalizedString('sunday');
    }
    return dow;
}
Lee Munkyeong committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105

function msToTime(s) {
  var ms = s % 1000;
  s = (s - ms) / 1000;
  var secs = s % 60;
  s = (s - secs) / 60;
  var mins = s % 60;
  var hrs = (s - mins) / 60;

  return hrs + ':' + mins + ':' + secs;
}

function updateDuration() {
    var now = new Date();
106 107
    $('.collaboration_duration').each(function(index, item) {
        var insertDateString = $(item).data('insertdate');
Lee Munkyeong committed
108 109 110 111 112 113 114 115
        insertDateString = insertDateString.toString();
        var year = insertDateString.substring(0,4);
        var month = insertDateString.substring(4,6);
        var day = insertDateString.substring(6,8);
        var hour = insertDateString.substring(8,10);
        var min = insertDateString.substring(10,12);
        var sec = insertDateString.substring(12,14);
        var insertDate = new Date(year, month-1 , day, hour, min, sec);
116
        $(item).html(msToTime(now - insertDate));
Lee Munkyeong committed
117 118 119 120 121 122
    });
}

CHAT_UTIL.getCollaborationType = function(key) {
    switch(key) {
        case collaborationTypeKey.AUDIO:
123
            return COLLABORATION_TYPE.AUDIO;
Lee Munkyeong committed
124
        case collaborationTypeKey.CAMERA:
125
            return COLLABORATION_TYPE.CAMERA;
Lee Munkyeong committed
126
        case collaborationTypeKey.VIDEO:
127
            return COLLABORATION_TYPE.VIDEO;
Lee Munkyeong committed
128
        case collaborationTypeKey.DOCUMENT:
129
            return COLLABORATION_TYPE.DOCUMENT;
Lee Munkyeong committed
130 131 132
        default:
            return 0;
    }
133 134
}

135 136
CHAT_UTIL.getCoviewTypeFromCollaborationType = function(joinCollaborationType) {
    switch(joinCollaborationType) {
137
        case COLLABORATION_TYPE.AUDIO:
138
            console.log(collaborationTypeKey.AUDIO);
139
            return collaborationTypeKey.AUDIO;
140
        case COLLABORATION_TYPE.CAMERA:
141
            console.log(collaborationTypeKey.CAMERA);
142
            return collaborationTypeKey.CAMERA;
143
        case COLLABORATION_TYPE.VIDEO:
144
            return collaborationTypeKey.VIDEO;
145
        case COLLABORATION_TYPE.DOCUMENT:
146
            return collaborationTypeKey.DOCUMENT;
147
        case COLLABORATION_TYPE.BOARD:
148 149 150 151
            return collaborationTypeKey.BOARD;
        default:
            return 0;
    }
Lee Munkyeong committed
152
}