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 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: jsxc.lib.Message.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: jsxc.lib.Message.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* Load message object with given uid.
*
* @class Message
* @memberOf jsxc
* @param {string} uid Unified identifier from message object
*/
/**
* Create new message object.
*
* @class Message
* @memberOf jsxc
* @param {object} args New message properties
* @param {string} args.bid
* @param {direction} args.direction
* @param {string} args.msg
* @param {boolean} args.encrypted
* @param {boolean} args.forwarded
* @param {boolean} args.sender
* @param {integer} args.stamp
* @param {object} args.attachment Attached data
* @param {string} args.attachment.name File name
* @param {string} args.attachment.size File size
* @param {string} args.attachment.type File type
* @param {string} args.attachment.data File data
*/
jsxc.Message = function() {
/** @member {string} */
this._uid = null;
/** @member {boolean} */
this._received = false;
/** @member {boolean} */
this.encrypted = false;
/** @member {boolean} */
this.forwarded = false;
/** @member {integer} */
this.stamp = new Date().getTime();
if (typeof arguments[0] === 'string' && arguments[0].length > 0 && arguments.length === 1) {
this._uid = arguments[0];
this.load(this._uid);
} else if (typeof arguments[0] === 'object' && arguments[0] !== null) {
$.extend(this, arguments[0]);
}
if (!this._uid) {
this._uid = new Date().getTime() + ':msg';
}
};
/**
* Load message properties.
*
* @memberof jsxc.Message
* @param {string} uid
*/
jsxc.Message.prototype.load = function(uid) {
var data = jsxc.storage.getUserItem('msg', uid);
if (!data) {
jsxc.debug('Could not load message with uid ' + uid);
}
$.extend(this, data);
};
/**
* Save message properties and create thumbnail.
*
* @memberOf jsxc.Message
* @return {Message} this object
*/
jsxc.Message.prototype.save = function() {
var history;
if (this.bid) {
history = jsxc.storage.getUserItem('history', this.bid) || [];
if (history.indexOf(this._uid) < 0) {
if (history.length > jsxc.options.get('numberOfMsg')) {
jsxc.Message.delete(history.pop());
}
} else {
history = null;
}
}
if (Image && this.attachment && this.attachment.type.match(/^image\//i) && this.attachment.data) {
var sHeight, sWidth, sx, sy;
var dHeight = 100,
dWidth = 100;
var canvas = $("<canvas>").get(0);
canvas.width = dWidth;
canvas.height = dHeight;
var ctx = canvas.getContext("2d");
var img = new Image();
img.src = this.attachment.data;
if (img.height > img.width) {
sHeight = img.width;
sWidth = img.width;
sx = 0;
sy = (img.height - img.width) / 2;
} else {
sHeight = img.height;
sWidth = img.height;
sx = (img.width - img.height) / 2;
sy = 0;
}
ctx.drawImage(img, sx, sy, sWidth, sHeight, 0, 0, dWidth, dHeight);
this.attachment.thumbnail = canvas.toDataURL();
if (this.direction === 'out') {
// save storage
this.attachment.data = null;
}
}
var data;
if (this.attachment && this.attachment.size > jsxc.options.maxStorableSize && this.direction === 'in') {
jsxc.debug('Attachment to large to store');
data = this.attachment.data;
this.attachment.data = null;
this.attachment.persistent = false;
//@TODO inform user
}
jsxc.storage.setUserItem('msg', this._uid, this);
if (history) {
history.unshift(this._uid);
jsxc.storage.setUserItem('history', this.bid, history);
}
if (data && this.attachment) {
this.attachment.data = data;
}
return this;
};
/**
* Remove object from storage.
*
* @memberOf jsxc.Message
*/
jsxc.Message.prototype.delete = function() {
jsxc.Message.delete(this._uid);
};
/**
* Returns object as jquery object.
*
* @memberOf jsxc.Message
* @return {jQuery} Representation in DOM
*/
jsxc.Message.prototype.getDOM = function() {
return jsxc.Message.getDOM(this._uid);
};
/**
* Mark message as received.
*
* @memberOf jsxc.Message
*/
jsxc.Message.prototype.received = function() {
this._received = true;
this.save();
this.getDOM().addClass('jsxc_received');
};
/**
* Returns true if the message was already received.
*
* @memberOf jsxc.Message
* @return {boolean} true means received
*/
jsxc.Message.prototype.isReceived = function() {
return this._received;
};
/**
* Remove message with uid.
*
* @memberOf jsxc.Message
* @static
* @param {string} uid message uid
*/
jsxc.Message.delete = function(uid) {
var data = jsxc.storage.getUserItem('msg', uid);
if (data) {
jsxc.storage.removeUserItem('msg', uid);
if (data.bid) {
var history = jsxc.storage.getUserItem('history', data.bid) || [];
history = $.grep(history, function(el) {
return el !== uid;
});
jsxc.storage.setUserItem('history', data.bid);
}
}
};
/**
* Returns message object as jquery object.
*
* @memberOf jsxc.Message
* @static
* @param {string} uid message uid
* @return {jQuery} jQuery representation in DOM
*/
jsxc.Message.getDOM = function(uid) {
return $('#' + uid.replace(/:/g, '-'));
};
/**
* Message direction can be incoming, outgoing or system.
*
* @typedef {(jsxc.Message.IN|jsxc.Message.OUT|jsxc.Message.SYS)} direction
*/
/**
* @constant
* @type {string}
* @default
*/
jsxc.Message.IN = 'in';
/**
* @constant
* @type {string}
* @default
*/
jsxc.Message.OUT = 'out';
/**
* @constant
* @type {string}
* @default
*/
jsxc.Message.SYS = 'sys';
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="jsxc.Message.html">Message</a></li></ul><h3>Namespaces</h3><ul><li><a href="jsxc.html">jsxc</a></li><li><a href="jsxc.gui.html">gui</a></li><li><a href="jsxc.gui.dialog.html">dialog</a></li><li><a href="jsxc.gui.queryActions.html">queryActions</a></li><li><a href="jsxc.gui.roster.html">roster</a></li><li><a href="jsxc.gui.window.html">window</a></li><li><a href="jsxc.muc.html">muc</a></li><li><a href="jsxc.notification.html">notification</a></li><li><a href="jsxc.options.html">options</a></li><li><a href="jsxc.otr.html">otr</a></li><li><a href="jsxc.storage.html">storage</a></li><li><a href="jsxc.webrtc.html">webrtc</a></li><li><a href="jsxc.xmpp.html">xmpp</a></li><li><a href="jsxc.xmpp.bookmarks.html">bookmarks</a></li><li><a href="jsxc.xmpp.carbons.html">carbons</a></li></ul><h3>Global</h3><ul><li>{boolean}</li><li>{integer}</li><li>{string}</li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Fri Mar 11 2016 17:32:12 GMT+0100 (CET)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
|