|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Defination of class CCalendarInterface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 function __device_messaging_descriptor(provider){ |
|
21 this.interfaceName = provider.interfaceName; |
|
22 this.version = provider.version; |
|
23 } |
|
24 |
|
25 |
|
26 |
|
27 function __device_messaging_startEditor(message){ |
|
28 |
|
29 return this.provider.startEditor(message); |
|
30 } |
|
31 |
|
32 function __device_messaging_getList(callback, match, sortkey, sortorder, ErrorCallback){ |
|
33 return this.provider.getList(callback, match, sortkey, sortorder, ErrorCallback); |
|
34 } |
|
35 |
|
36 function __device_messaging_send(callback, message, id, ErrorCallback){ |
|
37 return this.provider.send(callback, message, id, ErrorCallback); |
|
38 } |
|
39 |
|
40 |
|
41 function __device_messaging_setNotifier(callback, ErrorCallback){ |
|
42 return this.provider.setNotifier(callback, ErrorCallback ); |
|
43 } |
|
44 |
|
45 function __device_messaging_cancelNotifier(){ |
|
46 return this.provider.cancelNotifier(); |
|
47 } |
|
48 |
|
49 function __device_messaging_getMessage(id){ |
|
50 return this.provider.getMessage(id); |
|
51 } |
|
52 |
|
53 function __device_messaging_delete(id){ |
|
54 return this.provider.deleteMessage(id); |
|
55 } |
|
56 |
|
57 function __device_messaging_setStatus(id, status){ |
|
58 return this.provider.setStatus(id, status); |
|
59 } |
|
60 function __device_messaging_cancel(transactionId){ |
|
61 |
|
62 return this.provider.cancel(transactionId); |
|
63 } |
|
64 |
|
65 function __device_messaging(provider){ |
|
66 //Private properties |
|
67 this.provider = provider; |
|
68 //Read-only properties |
|
69 this.interfaceName = provider.descriptor.interfaceName; |
|
70 this.version = provider.descriptor.version; |
|
71 //constants |
|
72 this.SORT_ASCENDING = 0; |
|
73 this.SORT_DESCENDING = 1; |
|
74 this.SORT_BY_DATE = 0; |
|
75 this.SORT_BY_SENDER = 1; |
|
76 this.STATUS_READ = 0; |
|
77 this.STATUS_UNREAD = 1; |
|
78 |
|
79 //Core methods |
|
80 this.startEditor = __device_messaging_startEditor; |
|
81 //Extended methods |
|
82 this.getList = __device_messaging_getList; |
|
83 this.send = __device_messaging_send; |
|
84 this.setNotifier = __device_messaging_setNotifier; |
|
85 this.cancelNotifier = __device_messaging_cancelNotifier; |
|
86 this.getMessage = __device_messaging_getMessage; |
|
87 this.deleteMessage = __device_messaging_delete; |
|
88 this.setStatus = __device_messaging_setStatus; |
|
89 this.cancel = __device_messaging_cancel; |
|
90 } |
|
91 |
|
92 // Namepace: com.nokia.device.service |
|
93 |
|
94 |
|
95 var __device_messaging_service_entry = { |
|
96 "name": null, |
|
97 "version": null, |
|
98 "proto": __device_messaging, |
|
99 "descriptor": __device_messaging_descriptor, |
|
100 "providers": [{ |
|
101 "descriptor": __sp_messaging_descriptor, |
|
102 "instance": __sp_messaging_instance |
|
103 }] |
|
104 }; |
|
105 |
|
106 |
|
107 |
|
108 /* |
|
109 Copyright © 2009 Nokia. All rights reserved. |
|
110 Code licensed under the BSD License: |
|
111 Software License Agreement (BSD License) Copyright © 2009 Nokia. |
|
112 All rights reserved. |
|
113 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
114 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
115 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
116 Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. |
|
117 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
118 version: 1.0 |
|
119 */ |
|
120 // S60 sp-based messaging provider |
|
121 var FILE_SCHEME = 'file://'; |
|
122 //Constant values as per the CJSE Spec |
|
123 //var INVALID_URI_ERR = 108; |
|
124 |
|
125 /* |
|
126 * Global object for Async utility functions: |
|
127 * 1)addToGlobalArray |
|
128 * 2)getFromArray |
|
129 * 3)removeFromArray |
|
130 */ |
|
131 |
|
132 //var error = new DeviceError(0, 'dummy'); |
|
133 /* |
|
134 if(undefined == com.nokia.device.messaging) |
|
135 { |
|
136 com.nokia.device.messaging={}; |
|
137 } |
|
138 nokia.device.messaging.SORT_ASCENDING = 0; |
|
139 nokia.device.messaging.SORT_DESCENDING = 1; |
|
140 nokia.device.messaging.SORT_BY_DATE = 0; |
|
141 nokia.device.messaging.SORT_BY_SENDER = 1; |
|
142 nokia.device.messaging.STATUS_READ = 0; |
|
143 nokia.device.messaging.STATUS_UNREAD = 1;*/ |
|
144 function __sp_messaging_descriptor(){ |
|
145 //Read-only properties |
|
146 this.interfaceName = "messaging"; |
|
147 if (window.__Service_Interface_Ver) |
|
148 this.version = __Service_Interface_Ver; |
|
149 else |
|
150 this.version = 1.0; |
|
151 //Class-static properties |
|
152 } |
|
153 |
|
154 function __sp_messaging_instance(){ |
|
155 |
|
156 |
|
157 //Descriptor |
|
158 this.descriptor = new __sp_messaging_descriptor(); |
|
159 //Core methods |
|
160 this.startEditor = __sp_messaging_startEditor; |
|
161 //Extended methods |
|
162 this.getList = __sp_messaging_getList; |
|
163 this.getListcB = __sp_message_getListcB; |
|
164 |
|
165 this.send = __sp_messaging_send; |
|
166 this.sendcb = __sp_message_sendcb; |
|
167 |
|
168 this.setNotifier = __sp_messaging_setNotifier; |
|
169 this.setNotifierCb = __sp_messaging_setNotifier_cb; |
|
170 |
|
171 this.cancelNotifier = __sp_messaging_cancelNotifier; |
|
172 this.getMessage = __sp_messaging_getMessage; |
|
173 this.deleteMessage = __sp_messaging_delete; |
|
174 this.setStatus = __sp_messaging_setStatus; |
|
175 this.cancel = __sp_messaging_cancel; |
|
176 // Private data |
|
177 this.sendCommon = __sp_messaging_send_common; |
|
178 //Constant values as per the CJSE Spec |
|
179 this.SORT_ASCENDING = 0; |
|
180 this.SORT_DESCENDING = 1; |
|
181 this.SORT_BY_DATE = 0; |
|
182 this.SORT_BY_SENDER = 1; |
|
183 this.STATUS_READ = 0; |
|
184 this.STATUS_UNREAD = 1; |
|
185 this.error = new DeviceException(0, "Dummy"); |
|
186 |
|
187 try { |
|
188 //__device_debug("Trying messaging service"); |
|
189 this.so = device.getServiceObject("Service.Messaging", "IMessaging"); |
|
190 //__device_debug("Got messaging service object"); |
|
191 } |
|
192 catch (e) { |
|
193 this.so = null; |
|
194 __device_handle_exception(e, "Messaging service not available"); |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 function __sp_attachment_build(attachment){ |
|
201 if (!attachment) { |
|
202 return null; |
|
203 } |
|
204 var sp_attachment = {}; |
|
205 modifyObjectBaseProp(sp_attachment); |
|
206 if (attachment.uri) { |
|
207 if (typeof attachment.uri != "string") { |
|
208 throw new DeviceException(this.error.INVALID_ARG_ERR, "uri is invalid"); |
|
209 } |
|
210 //device1.0: added this statement.. with out this the script will crib..also checking for proper URI |
|
211 if (attachment.uri.slice(0, 7) == FILE_SCHEME) { |
|
212 if (attachment.uri.charAt(7) == "/") { |
|
213 if (attachment.uri.charAt(9) != ":") { |
|
214 throw new DeviceException(this.error.URI_NOT_FOUND_ERR, "specified uri not found"); |
|
215 } |
|
216 sp_attachment.FileName = attachment.uri.slice(8).replace(/\057/g, "\\"); |
|
217 if (sp_attachment.FileName.length > 256) { |
|
218 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "uri is out of range");//map the errorcode to data_out_of_range |
|
219 } |
|
220 } |
|
221 |
|
222 else { |
|
223 if (attachment.uri.charAt(8) != ":") { |
|
224 throw new DeviceException(this.error.URI_NOT_FOUND_ERR, "specified uri not found"); |
|
225 } |
|
226 sp_attachment.FileName = attachment.uri.slice(7).replace(/\057/g, "\\"); |
|
227 if (sp_attachment.FileName.length > 256) { |
|
228 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "uri is out of range");//map the errorcode to data_out_of_range |
|
229 } |
|
230 } |
|
231 } |
|
232 else { |
|
233 throw new DeviceException(this.error.INVALID_URI_ERR, "uri is invalid") |
|
234 } |
|
235 |
|
236 } |
|
237 //alert("attachment" + sp_attachment.FileName); |
|
238 return sp_attachment; |
|
239 } |
|
240 |
|
241 function __sp_message_build(message, id){ |
|
242 //a(id) |
|
243 //__device_debug("sp_message_build"); |
|
244 if (!message) { |
|
245 return null; |
|
246 } |
|
247 var sp_message = {}; |
|
248 modifyObjectBaseProp(sp_message); |
|
249 var attachFlag = 0; |
|
250 sp_message.MessageParam = {}; |
|
251 modifyObjectBaseProp(sp_message.MessageParam); |
|
252 sp_message.MessageParam.LaunchEditor = false; //Defaults to no editor |
|
253 sp_message.MessageType = (message.type == undefined || message.type == null) ? "SMS" : message.type; |
|
254 //alert(message.to[0]+" "+message.type) |
|
255 if (message.to) { |
|
256 if (typeof(message.to) == "string") { |
|
257 sp_message.To = message.to; |
|
258 } |
|
259 else |
|
260 if (__device_typeof(message.to) == "Array" && message.to.length > 0) { |
|
261 if (message.to[0]) { |
|
262 sp_message.To = message.to[0]; |
|
263 } |
|
264 |
|
265 |
|
266 if (message.to.length > 1) { |
|
267 if (message.to.slice(1)) { |
|
268 sp_message.MessageParam.To = message.to.slice(1); |
|
269 |
|
270 } |
|
271 } |
|
272 } |
|
273 else { |
|
274 sp_message.To = message.to; |
|
275 } |
|
276 } |
|
277 |
|
278 if (message.cc) { |
|
279 sp_message.MessageParam.Cc = message.cc; |
|
280 } |
|
281 |
|
282 if (id) { |
|
283 if ((typeof(id) == "string") && !(isNaN(id))) { |
|
284 id = Number(id); |
|
285 } |
|
286 sp_message.MessageParam.TemplateId = id; |
|
287 } |
|
288 if (sp_message.MessageType == "SMS") { |
|
289 if (message.body) { |
|
290 sp_message.BodyText = message.body; |
|
291 } |
|
292 } |
|
293 |
|
294 if (sp_message.MessageType == "MMS") { |
|
295 if (message.body) { |
|
296 //device1.0: Added body to MMS as it is a valid input to MMS type of message also |
|
297 sp_message.BodyText = message.body; |
|
298 } |
|
299 if (message.subject) { |
|
300 if (typeof message.subject == "string" && message.subject.length > 256) { |
|
301 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "subject length is greater than 256 characters"); |
|
302 } |
|
303 sp_message.Subject = message.subject; |
|
304 } |
|
305 if (message.attachments) { |
|
306 sp_message.MessageParam.AttachmentList = []; |
|
307 for (var a in message.attachments) { |
|
308 //if (message.attachments.hasOwnProperty('a')) { |
|
309 if (typeof message.attachments[a] == "object" && __device_typeof(message.attachments[a]) != "Array") { |
|
310 sp_message.MessageParam.AttachmentList.push(__sp_attachment_build(message.attachments[a])); |
|
311 attachFlag = 1; |
|
312 } |
|
313 |
|
314 |
|
315 |
|
316 //} |
|
317 } |
|
318 if (attachFlag == 0) { |
|
319 throw new DeviceException(this.error.INVALID_ARG_ERR, "uri is invalid"); |
|
320 } |
|
321 } |
|
322 } |
|
323 // //alert("returning message____"); |
|
324 return sp_message; |
|
325 } |
|
326 |
|
327 function __sp_device_attachment_build(sp_attachment){ |
|
328 if (!sp_attachment) { |
|
329 return null; |
|
330 } |
|
331 var attachment = {}; |
|
332 attachment.uri = FILE_SCHEME + sp_attachment.FileName; |
|
333 return attachment; |
|
334 } |
|
335 |
|
336 function __sp_device_message_build(sp_message){ |
|
337 if (!sp_message) { |
|
338 return null; |
|
339 } |
|
340 // //alert("am in message build"); |
|
341 var message = {}; |
|
342 message.body = null; |
|
343 message.subject = null; |
|
344 message.attachments = null; |
|
345 message.to = null; |
|
346 message.cc = null; |
|
347 |
|
348 message.type = sp_message.MessageType; |
|
349 if (sp_message.BodyText) { |
|
350 message.body = sp_message.BodyText; |
|
351 } |
|
352 if (sp_message.to) { |
|
353 message.to = sp_message.To; |
|
354 |
|
355 } |
|
356 if (sp_message.Subject) //device1.0: moved to here from MMS,for sms also subject is valid it will return the first 64 characters of the body as subject |
|
357 { |
|
358 message.subject = sp_message.Subject; |
|
359 } |
|
360 message.attachment = false; |
|
361 |
|
362 |
|
363 if (message.type == "MMS") { |
|
364 if (sp_message.Cc) { |
|
365 message.cc = sp_message.Cc; |
|
366 } |
|
367 if (sp_message.AttachmentList) { |
|
368 message.attachment = true; |
|
369 message.attachments = []; |
|
370 for (var a in sp_message.AttachmentList) { |
|
371 if (sp_message.AttachmentList.hasOwnProperty('a')) { |
|
372 message.attachments.push(__sp_device_attachment_build(sp_message.AttachmentList[a])); |
|
373 } |
|
374 } |
|
375 } |
|
376 } |
|
377 // //alert("returning message"); |
|
378 return message; |
|
379 } |
|
380 |
|
381 function __sp_device_message_info_build_notifier(sp_message){ |
|
382 if (!sp_message) { |
|
383 return null; |
|
384 } |
|
385 var message_info = {}; |
|
386 message_info.message = {}; |
|
387 message_info.message.type = sp_message.MessageType; |
|
388 message_info.sender = sp_message.Sender; |
|
389 message_info.message.subject = sp_message.Subject; |
|
390 message_info.time = sp_message.Time; |
|
391 message_info.attachments = (sp_message.Attachments == undefined || sp_message.Attachments == null) ? (!(sp_message.AttachmentList == undefined || sp_message.AttachmentList == null)) : sp_message.Attachments; |
|
392 message_info.unread = sp_message.Unread; //TBD: check existence |
|
393 message_info.id = (sp_message.MessageId).toString(); // TBD: check name of sp field |
|
394 return message_info; |
|
395 } |
|
396 |
|
397 |
|
398 function __sp_device_message_info_build(sp_message){ |
|
399 //__device_debug("sp_device_message_info_build"); |
|
400 if (!sp_message) { |
|
401 return null; |
|
402 } |
|
403 // //alert("*******"); |
|
404 var message_info = {}; |
|
405 message_info.message = __sp_device_message_build(sp_message); |
|
406 message_info.sender = sp_message.Sender; |
|
407 message_info.time = sp_message.Time; |
|
408 message_info.unread = sp_message.Unread; //TBD: check existence |
|
409 message_info.id = (sp_message.MessageId).toString(); // TBD: check name of sp field |
|
410 return message_info; |
|
411 } |
|
412 |
|
413 // ------ Wrap sp iterator ------- |
|
414 |
|
415 |
|
416 |
|
417 function __sp_message_iterator_get_next(){ |
|
418 //__device_debug("sp_message_iterator_get_next"); |
|
419 // //alert("in get_next"); |
|
420 var sp_message = this.iter.getNext(); |
|
421 if (typeof sp_message == "undefined") { |
|
422 // //alert("returning null"); |
|
423 return null; |
|
424 } |
|
425 // //alert("iterator"); |
|
426 var message = __sp_device_message_info_build(sp_message); |
|
427 sp_message.close(); |
|
428 return message; |
|
429 } |
|
430 |
|
431 function __sp_message_iterator(js_iterator){ |
|
432 this.iter = js_iterator; |
|
433 this.next = __sp_message_iterator_get_next; |
|
434 this.close = function(){ |
|
435 this.iter.close(); |
|
436 } |
|
437 |
|
438 } |
|
439 |
|
440 |
|
441 function __sp_message_getListcB(arg1, arg2, arg3){ |
|
442 |
|
443 var success_cb; |
|
444 var error_cb; |
|
445 var CbObj; |
|
446 |
|
447 |
|
448 CbObj = glob_obj.getFromArray(arg1); |
|
449 |
|
450 |
|
451 |
|
452 if (CbObj) { |
|
453 success_cb = CbObj.success_cb; |
|
454 error_cb = CbObj.error_cb; |
|
455 } |
|
456 |
|
457 else { |
|
458 alert("Messaging: __sp_message_getListcB: Callback not found "); |
|
459 return; |
|
460 } |
|
461 |
|
462 |
|
463 var iter = null; |
|
464 |
|
465 if (arg3.ErrorCode != 0) { |
|
466 //alert('error '+error_cb); |
|
467 if (arg3.ErrorMessage) { |
|
468 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
469 } |
|
470 else { |
|
471 err_msg = "Operation Failed"; |
|
472 } |
|
473 |
|
474 if (error_cb) { |
|
475 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "Messaging: getList: " + err_msg)); |
|
476 return; |
|
477 } |
|
478 } |
|
479 else |
|
480 if (arg3.ReturnValue) { |
|
481 |
|
482 iter = new __sp_message_iterator(arg3.ReturnValue); |
|
483 } |
|
484 |
|
485 if (arg2 != event_cancelled) // 3 signifies eventcancelled //device1.0: currently this check is not required here but might be in future if sp provides Async getlist |
|
486 { |
|
487 success_cb(iter);//device1.0: arg1 is the errorcode, arg2 is the transactionId and iter is the return value |
|
488 } |
|
489 glob_obj.removeFromArray(arg1); |
|
490 } |
|
491 |
|
492 function __sp_messaging_getList(msg_cb, match, sortkey, sortorder, ErrorCallback){ |
|
493 |
|
494 //alert("in getlist"); |
|
495 |
|
496 if (!msg_cb) { |
|
497 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:getList:callback is missing"); |
|
498 } |
|
499 else |
|
500 if (typeof msg_cb != "function") { |
|
501 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:callback is not a function"); //BadArgumentType error |
|
502 } |
|
503 if (match != null && match != undefined && typeof match != "object") { |
|
504 // a("match not object") |
|
505 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:match is invalid"); //BadArgumentType error |
|
506 } |
|
507 |
|
508 if (sortkey != null && sortkey != undefined && typeof sortkey != "number") { |
|
509 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortkey is invalid"); //BadArgumentType error |
|
510 } |
|
511 |
|
512 if (sortorder != null && sortorder != undefined && typeof sortorder != "number") { |
|
513 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortorder is invalid"); //BadArgumentType error |
|
514 } |
|
515 |
|
516 if (sortkey != null && sortkey != undefined && typeof sortkey == "number") { |
|
517 if ((sortkey != 0) && (sortkey != 1)) |
|
518 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortkey is invalid"); //BadArgumentType error |
|
519 } |
|
520 |
|
521 if (sortorder != null && sortorder != undefined && typeof sortorder == "number") { |
|
522 // a(sortorder+" "+typeof sortorder) |
|
523 if ((sortorder != 0) && (sortorder != 1)) |
|
524 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortorder is invalid"); //BadArgumentType error |
|
525 } |
|
526 |
|
527 if (ErrorCallback) { |
|
528 if (typeof(ErrorCallback) != 'function') { |
|
529 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging: startEditor: ErrorCallback is invalid"); |
|
530 } |
|
531 } |
|
532 |
|
533 |
|
534 var criteria = {}; |
|
535 modifyObjectBaseProp(criteria); |
|
536 criteria.Type = "Inbox"; |
|
537 criteria.Filter = {}; |
|
538 modifyObjectBaseProp(criteria.Filter); |
|
539 |
|
540 |
|
541 if (match) { |
|
542 // a("in match"); |
|
543 if (match.type != null && match.type != undefined) { |
|
544 // a("match.type" + match.type); |
|
545 criteria.Filter.MessageTypeList = match.type; |
|
546 } |
|
547 if (match.senders != null && match.senders != undefined) { |
|
548 criteria.Filter.SenderList = match.senders; |
|
549 } |
|
550 if (match.subject != null && match.subject != undefined) { |
|
551 if (match.subject.length > 256) { |
|
552 if (ErrorCallback) { |
|
553 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:getList:subject is out of range")); |
|
554 return; |
|
555 } |
|
556 else { |
|
557 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:getList:subject is out of range"); |
|
558 } |
|
559 } |
|
560 else { |
|
561 criteria.Filter.Subject = match.subject; |
|
562 } |
|
563 } |
|
564 if (match.start != null && match.start != undefined) { |
|
565 criteria.Filter.StartDate = match.start; |
|
566 } |
|
567 if (match.end != null && match.end != undefined) { |
|
568 criteria.Filter.EndDate = match.end; |
|
569 } |
|
570 } |
|
571 |
|
572 if (sortkey || sortorder) { |
|
573 // a("in sortkey"); |
|
574 criteria.SortOrder = {}; |
|
575 modifyObjectBaseProp(criteria.SortOrder); |
|
576 if (sortkey) { |
|
577 if ((sortkey == this.SORT_BY_DATE)) { |
|
578 criteria.SortOrder.Key = "Date"; |
|
579 } |
|
580 else |
|
581 if ((sortkey == this.SORT_BY_SENDER)) { |
|
582 criteria.SortOrder.Key = "Sender"; |
|
583 } |
|
584 } |
|
585 else { |
|
586 criteria.SortOrder.Key = "Date"; |
|
587 } |
|
588 if (sortorder) { |
|
589 |
|
590 if ((sortorder == this.SORT_ASCENDING)) { |
|
591 criteria.SortOrder.Order = "Ascending"; |
|
592 } |
|
593 else |
|
594 if ((sortorder == this.SORT_DESCENDING)) { |
|
595 criteria.SortOrder.Order = "Descending"; |
|
596 } |
|
597 } |
|
598 else { |
|
599 criteria.SortOrder.Order = "Ascending"; |
|
600 } |
|
601 } |
|
602 |
|
603 try { |
|
604 //__device_debug("Getting message list"); |
|
605 temp_scb = msg_cb; |
|
606 temp_ecb = ErrorCallback; |
|
607 var result = this.so.IMessaging.GetList(criteria, this.getListcB); |
|
608 if (result.TransactionID) { |
|
609 glob_obj.addToGlobalArray(result.TransactionID, msg_cb, ErrorCallback); |
|
610 } |
|
611 |
|
612 if (criteria) { |
|
613 delete criteria.Filter; |
|
614 delete criteria.SortOrder; |
|
615 delete criteria.Type; |
|
616 } |
|
617 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
618 { |
|
619 |
|
620 var err_msg = "operation failed"; |
|
621 if (result.ErrorMessage) { |
|
622 err_msg = splitErrorMessage(result.ErrorMessage); |
|
623 } |
|
624 switch (MapErrorCode[result.ErrorCode]) { |
|
625 case this.error.INVALID_ARG_ERR: |
|
626 case this.error.MISSING_ARG_ERR: |
|
627 case this.error.NOT_SUPPORTED_ERR: |
|
628 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:getList:" + err_msg); |
|
629 break; |
|
630 |
|
631 default: |
|
632 if (ErrorCallback) { |
|
633 setTimeout(function(){ |
|
634 ErrorCallback(new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:getList:" + err_msg)); |
|
635 }, 500); |
|
636 } |
|
637 else { |
|
638 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:getList:" + err_msg); |
|
639 } |
|
640 |
|
641 } |
|
642 } |
|
643 |
|
644 return result.TransactionID; |
|
645 } |
|
646 catch (e) { |
|
647 __device_handle_exception(e, '__sp_messaging_getList: ' + e); |
|
648 } |
|
649 } |
|
650 |
|
651 function __sp_message_sendcb(arg1, arg2, arg3){ |
|
652 var send_cb; |
|
653 var eCB; |
|
654 var CbObj = glob_obj.getFromArray(arg1); |
|
655 |
|
656 if (CbObj) { |
|
657 send_cb = CbObj.success_cb; |
|
658 eCB = CbObj.error_cb; |
|
659 } |
|
660 |
|
661 else |
|
662 { |
|
663 alert('Messaging : __sp_message_sendcb : Callback not found'); |
|
664 return; |
|
665 } |
|
666 if (send_cb) { |
|
667 var err_msg = "operation failed"; |
|
668 |
|
669 if (arg3.ErrorCode != 0) { |
|
670 |
|
671 if (arg3.ErrorMessage) { |
|
672 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
673 } |
|
674 if (eCB) { |
|
675 //alert("am in ecb"); |
|
676 setTimeout(function(){ |
|
677 eCB(new DeviceException(MapErrorCode[arg3.ErrorCode], "Messaging: send: " + err_msg)); |
|
678 }, 500); |
|
679 return; |
|
680 } |
|
681 } |
|
682 if (arg2 != event_cancelled) // 3 signifies eventcancelled |
|
683 { |
|
684 send_cb();//device1.0: arg1 is the transaction id, arg3 is the return value which holds the errorcode |
|
685 } |
|
686 } |
|
687 glob_obj.removeFromArray(arg1); |
|
688 } |
|
689 |
|
690 function __sp_messaging_send_common(message, editor, send_cb, id, eCB){ |
|
691 |
|
692 //__device_debug("sp_messaging_send_common"); |
|
693 var criteria = __sp_message_build(message, id); |
|
694 criteria.MessageParam.LaunchEditor = editor; |
|
695 |
|
696 var result; |
|
697 // //alert("before editor"); |
|
698 if (editor == false) //device1.0:making it async only in case of send api, as it doesnot invoke editor, returning the output accordingly |
|
699 { |
|
700 temp_scb = send_cb; |
|
701 temp_ecb = eCB; |
|
702 result = this.so.IMessaging.Send(criteria, this.sendcb); |
|
703 if (result.TransactionID) { |
|
704 glob_obj.addToGlobalArray(result.TransactionID, send_cb, eCB); |
|
705 } |
|
706 |
|
707 //alert("ErrorCode" + (result.ErrorCode)); |
|
708 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
709 { |
|
710 var err_msg = "operation failed"; |
|
711 if (result.ErrorMessage) { |
|
712 err_msg = splitErrorMessage(result.ErrorMessage); |
|
713 } |
|
714 //alert("before switch"); |
|
715 switch (MapErrorCode[result.ErrorCode]) { |
|
716 case this.error.INVALID_ARG_ERR: |
|
717 case this.error.MISSING_ARG_ERR: |
|
718 case this.error.NOT_SUPPORTED_ERR: |
|
719 //alert("INVALID"); |
|
720 throw new DeviceException(MapErrorCode[result.ErrorCode], err_msg); |
|
721 break; |
|
722 |
|
723 default: |
|
724 // a("in default"); |
|
725 if (eCB) { |
|
726 // a("calling eCB"); |
|
727 setTimeout(function(){ |
|
728 eCB(new DeviceException(MapErrorCode[result.ErrorCode], err_msg)); |
|
729 }, 500); |
|
730 // a("after eCB" + result.TransactionID); |
|
731 return; |
|
732 } |
|
733 else { |
|
734 // a("else"); |
|
735 throw new DeviceException(MapErrorCode[result.ErrorCode], err_msg); |
|
736 } |
|
737 |
|
738 } |
|
739 } |
|
740 |
|
741 var transactionID = result.TransactionID; |
|
742 // a("transactionID" + transactionID); |
|
743 return transactionID; |
|
744 } |
|
745 else { |
|
746 // a("am coming here"); |
|
747 result = this.so.IMessaging.Send(criteria); |
|
748 // a("result.ErrorCode" + result.ErrorCode); |
|
749 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
750 { |
|
751 if (result.ErrorMessage) { |
|
752 var err_msg1 = splitErrorMessage(result.ErrorMessage); |
|
753 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:startEditor" + err_msg1); |
|
754 } |
|
755 else { |
|
756 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:startEditor:operation failed"); |
|
757 } |
|
758 } |
|
759 } |
|
760 if (criteria) { |
|
761 delete criteria.MessageParam; |
|
762 } |
|
763 |
|
764 } |
|
765 |
|
766 |
|
767 function __sp_messaging_startEditor(message){ |
|
768 //a("starteditor"); |
|
769 if (!message) { |
|
770 // a("starteditor1"); |
|
771 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:startEditor:message is missing");//SErrMissingArgument = 1003 |
|
772 } |
|
773 else |
|
774 if (typeof message != "object") { |
|
775 // a("starteditor2"); |
|
776 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:startEditor:message is invalid"); //BadArgumentType error |
|
777 } |
|
778 //__device_debug("sp_messaging_startEditor"); |
|
779 if ((message.subject)) { |
|
780 if ((message.subject).length > 256) { |
|
781 // a("starteditor3"); |
|
782 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:startEditor:subject is too lengthy");//SErrMissingArgument = 1003 |
|
783 } |
|
784 } |
|
785 if (message.to == undefined || message.to == null) { |
|
786 // a("starteditor4"); |
|
787 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:startEditor:to field is missing");//SErrMissingArgument = 1003 |
|
788 } |
|
789 |
|
790 if (message.attachments != undefined && message.attachments != null && typeof message.attachments != "object") { |
|
791 // a("INVALID_ARG_ERR"); |
|
792 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:startEditor:attachment is invalid");//SErrMissingArgument = 1003 |
|
793 } |
|
794 if (message) { |
|
795 if (message.body) { |
|
796 if (typeof(message.body) != "string") { |
|
797 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:startEditor:body is invalid"); |
|
798 } |
|
799 } |
|
800 } |
|
801 try { |
|
802 // a("before sendcommon"); |
|
803 this.sendCommon(message, true, null); |
|
804 } |
|
805 catch (e) { |
|
806 // a("starteditor catch"); |
|
807 var error = null; |
|
808 if (e.message) { |
|
809 |
|
810 error = new DeviceException(e.code, "Messaging:startEditor:" + e.message); |
|
811 } |
|
812 else { |
|
813 error = new DeviceException(e.code, "Messaging:startEditor:operation failed"); |
|
814 } |
|
815 __device_handle_exception(error, '__sp_messaging_startEditor: ' + error); |
|
816 } |
|
817 } |
|
818 |
|
819 function __sp_messaging_send(msg_cb, message, id, ErrorCallback){ |
|
820 |
|
821 // a("send!!!!!!!" + ErrorCallback); |
|
822 if (!message) { |
|
823 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:send:message is missing");//SErrMissingArgument = 1003 |
|
824 } |
|
825 else |
|
826 if (typeof message != "object") { |
|
827 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:send:message is invalid"); //BadArgumentType error |
|
828 } |
|
829 if (!msg_cb) { |
|
830 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:send:callback is missing");//SErrMissingArgument = 1003 |
|
831 } |
|
832 else |
|
833 if (typeof msg_cb != "function") { |
|
834 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:send:callback is invalid"); //BadArgumentType error |
|
835 } |
|
836 |
|
837 |
|
838 if (message.to == undefined || message.to == null) { |
|
839 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:send:to field is missing");//SErrMissingArgument = 1003 |
|
840 } |
|
841 |
|
842 |
|
843 if (message.attachments != undefined && message.attachments != null && typeof message.attachments != "object") { |
|
844 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:send:attachment is invalid");//SErrMissingArgument = 1003 |
|
845 } |
|
846 |
|
847 if (!id) { |
|
848 id = ""; |
|
849 } |
|
850 /* if (id) { |
|
851 if (((typeof id) != "function") && ((typeof id) != "string") && ((typeof id) != "number")) { |
|
852 throw new DeviceException(INVALID_ARG_ERR, 'Messaging:send:id is not a string'); |
|
853 }*/ |
|
854 if ((typeof id) == "function") { |
|
855 var errorCbk = id; |
|
856 id = ""; |
|
857 ErrorCallback = errorCbk; |
|
858 } |
|
859 |
|
860 if ((typeof ErrorCallback) == "undefined" || ErrorCallback == null) { |
|
861 ErrorCallback = null; |
|
862 } |
|
863 else |
|
864 if ((typeof ErrorCallback) != "function") { |
|
865 throw new DeviceException(this.error.INVALID_ARG_ERR, 'Messaging:send:errorCallback is not a function'); |
|
866 } |
|
867 |
|
868 var invoker = function(arg1, arg2, arg3){ |
|
869 var success_cb = msg_cb; |
|
870 var error_cb = ErrorCallback; |
|
871 var iter = null; |
|
872 if (arg3.ErrorCode != 0) { |
|
873 var err_msg; |
|
874 if (arg3.ErrorMessage) |
|
875 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
876 else |
|
877 err_msg = "Operation Failed"; |
|
878 |
|
879 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "Messaging:startEditor: " + err_msg)); |
|
880 return; |
|
881 } |
|
882 else |
|
883 if (arg3.ReturnValue) { |
|
884 iter = new __sp_message_iterator(arg3.ReturnValue); |
|
885 success_cb(iter); |
|
886 } |
|
887 if (arg2 != event_cancelled) // 3 signifies eventcancelled //device1.0: currently this check is not required here but might be in future if sp provides Async getlist |
|
888 { |
|
889 success_cb(iter);//device1.0: arg1 is the errorcode, arg2 is the transactionId and iter is the return value |
|
890 } |
|
891 }; |
|
892 |
|
893 try { |
|
894 // //alert("before sendCommon"); |
|
895 // a("ErrorCallback" + ErrorCallback); |
|
896 var transactionID = this.sendCommon(message, false, msg_cb, id, ErrorCallback); |
|
897 // a("transactionID" + transactionID); |
|
898 return transactionID; |
|
899 } |
|
900 catch (e) { |
|
901 //a("e.message" + e.message); |
|
902 var error = null; |
|
903 switch (e.code) { |
|
904 case this.error.INVALID_ARG_ERR: |
|
905 case this.error.MISSING_ARG_ERR: |
|
906 case this.error.NOT_SUPPORTED_ERR: |
|
907 throw new DeviceException(e.code, "Messaging:send:" + e.message); |
|
908 break; |
|
909 |
|
910 default: |
|
911 if (ErrorCallback) { |
|
912 setTimeout(function(){ |
|
913 ErrorCallback(new DeviceException(e.code, "Messaging:send:" + e.message)); |
|
914 }, 1000); |
|
915 } |
|
916 else { |
|
917 throw new DeviceException(e.code, "Messaging:send:" + e.message); |
|
918 } |
|
919 |
|
920 } |
|
921 } |
|
922 } |
|
923 |
|
924 function __sp_messaging_setNotifier_cb(arg1, arg2, arg3){ |
|
925 var success_cb; |
|
926 var error_cb; |
|
927 var msginfo = null; |
|
928 var err_msg = null; |
|
929 |
|
930 var CbObj; |
|
931 |
|
932 |
|
933 CbObj = glob_obj.getFromArray(arg1); |
|
934 |
|
935 |
|
936 if (CbObj) { |
|
937 success_cb = CbObj.success_cb; |
|
938 error_cb = CbObj.error_cb; |
|
939 } |
|
940 |
|
941 else { |
|
942 alert("Messaging: __sp_messaging_setNotifier_cb : Callback not found "); |
|
943 return; |
|
944 } |
|
945 |
|
946 |
|
947 if (arg3.ErrorCode != 0) { |
|
948 if (arg3.ErrorMessage) { |
|
949 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
950 } |
|
951 else { |
|
952 err_msg = "operation failed"; |
|
953 } |
|
954 if (error_cb) { |
|
955 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "Messaging:setNotifier: " + err_msg)); |
|
956 return; |
|
957 } |
|
958 } |
|
959 else |
|
960 if (arg3.ReturnValue) { |
|
961 msginfo = new __sp_device_message_info_build_notifier(arg3.ReturnValue);//LAT BUG |
|
962 arg3.ReturnValue.close(); |
|
963 } |
|
964 if (arg2 != event_cancelled) // 3 signifies eventcancelled |
|
965 { |
|
966 success_cb(msginfo.id);//msginfo.id)//device1.0: returning the errorcode, |
|
967 } |
|
968 glob_obj.removeFromArray(arg1); |
|
969 } |
|
970 |
|
971 function __sp_messaging_setNotifier(msg_cb, ErrorCallback){ |
|
972 |
|
973 if (!msg_cb) { |
|
974 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:setNotifier:callback is missing");//SErrMissingArgument = 1003 |
|
975 } |
|
976 else |
|
977 if (typeof msg_cb != "function") { |
|
978 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setNotifier:callback is invalid"); //BadArgumentType error |
|
979 } |
|
980 |
|
981 |
|
982 |
|
983 if (ErrorCallback) { |
|
984 if (typeof(ErrorCallback) != 'function') { |
|
985 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setNotifier: ErrorCallback is invalid"); |
|
986 } |
|
987 } |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 var criteria = {}; |
|
993 modifyObjectBaseProp(criteria); |
|
994 criteria.Type = 'NewMessage'; |
|
995 |
|
996 try { |
|
997 temp_scb = msg_cb; |
|
998 temp_ecb = ErrorCallback; |
|
999 var result = this.so.IMessaging.RegisterNotification(criteria, this.setNotifierCb); |
|
1000 |
|
1001 if (result.TransactionID) { |
|
1002 glob_obj.addToGlobalArray(result.TransactionID, msg_cb, ErrorCallback); |
|
1003 } |
|
1004 |
|
1005 if (criteria) { |
|
1006 delete criteria.Type; |
|
1007 } |
|
1008 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1009 { |
|
1010 |
|
1011 var err_msg = "operation failed"; |
|
1012 if (result.ErrorMessage) { |
|
1013 err_msg = splitErrorMessage(result.ErrorMessage); |
|
1014 } |
|
1015 switch (MapErrorCode[result.ErrorCode]) { |
|
1016 case this.error.INVALID_ARG_ERR: |
|
1017 case this.error.MISSING_ARG_ERR: |
|
1018 case this.error.NOT_SUPPORTED_ERR: |
|
1019 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:setNotifier:" + err_msg); |
|
1020 break; |
|
1021 |
|
1022 default: |
|
1023 if (ErrorCallback) { |
|
1024 setTimeout(function(){ |
|
1025 ErrorCallback(new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:setNotifier:" + err_msg)); |
|
1026 }, 1000); |
|
1027 } |
|
1028 else { |
|
1029 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:setNotifier:" + err_msg); |
|
1030 } |
|
1031 |
|
1032 } |
|
1033 } |
|
1034 var transactionID = result.TransactionID; |
|
1035 return transactionID; |
|
1036 } |
|
1037 catch (e) { |
|
1038 __device_handle_exception(e, '__sp_messaging_setNotifier: ' + e.toString()); |
|
1039 } |
|
1040 } |
|
1041 |
|
1042 function __sp_messaging_cancelNotifier(){ |
|
1043 var criteria = {}; |
|
1044 modifyObjectBaseProp(criteria); |
|
1045 criteria.Type = "NewMessage"; |
|
1046 |
|
1047 try { |
|
1048 var result = this.so.IMessaging.CancelNotification(criteria); |
|
1049 if (criteria) { |
|
1050 delete criteria.Type; |
|
1051 } |
|
1052 //alert("result.ErrorCode" + result.ErrorCode); |
|
1053 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1054 { |
|
1055 if (result.ErrorMessage) { |
|
1056 var err_msg = splitErrorMessage(result.ErrorMessage); |
|
1057 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:cancelNotifier" + err_msg); |
|
1058 } |
|
1059 else { |
|
1060 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:cancelNotifier:operation failed"); |
|
1061 } |
|
1062 } |
|
1063 } |
|
1064 catch (e) { |
|
1065 __device_handle_exception(e, '__sp_messaging_cancelNotifier: ' + e); |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 function __sp_messaging_getMessage(id){ |
|
1070 |
|
1071 if (!id) { |
|
1072 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:getMessage:id is missing");//SErrMissingArgument = 1003 |
|
1073 } |
|
1074 else |
|
1075 if ((typeof id) != "string") |
|
1076 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getMessage:MessageId should be a string"); |
|
1077 if ((typeof id == "string") && !(isNaN(id))) { |
|
1078 id = Number(id); |
|
1079 if (id == 0) { |
|
1080 throw new DeviceException(this.error.DATA_NOT_FOUND_ERR, "Messaging:getMessage:id not found"); |
|
1081 } |
|
1082 if (id < 0) { |
|
1083 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:getMessage:id is out of range"); |
|
1084 } |
|
1085 } |
|
1086 |
|
1087 var criteria = {}; |
|
1088 modifyObjectBaseProp(criteria); |
|
1089 criteria.Type = "Inbox"; |
|
1090 criteria.Filter = {}; |
|
1091 modifyObjectBaseProp(criteria.Filter); |
|
1092 criteria.Filter.MessageId = id; |
|
1093 |
|
1094 try { |
|
1095 var result = this.so.IMessaging.GetList(criteria); |
|
1096 |
|
1097 if (criteria) { |
|
1098 delete criteria.Filter; |
|
1099 delete criteria.Type; |
|
1100 } |
|
1101 // a("result.ErrorCode" + result.ErrorCode); |
|
1102 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1103 { |
|
1104 // a("result.ErrorCode" + result.ErrorCode); |
|
1105 if (result.ErrorMessage) { |
|
1106 // a("result.ErrorMessage"); |
|
1107 var err_msg = splitErrorMessage(result.ErrorMessage); |
|
1108 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:getMessage" + err_msg); |
|
1109 } |
|
1110 else { |
|
1111 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:getMessage:operation failed"); |
|
1112 } |
|
1113 } |
|
1114 if (result.ReturnValue) { |
|
1115 // a("result.ReturnValue" + result.ReturnValue); |
|
1116 var iter = new __sp_message_iterator(result.ReturnValue);//LAT BUG |
|
1117 var result1 = iter.next(); |
|
1118 if (result1) { |
|
1119 // a("result1"); |
|
1120 return result1; |
|
1121 } |
|
1122 else { |
|
1123 // a("DATA_NOT_FOUND_ERR"); |
|
1124 throw new DeviceException(this.error.DATA_NOT_FOUND_ERR, "Messaging:getMessage:id not found");//sapi doesnot return errorcode for non-existent id |
|
1125 } |
|
1126 |
|
1127 } |
|
1128 } |
|
1129 catch (e) { |
|
1130 __device_handle_exception(e, '__sp_messaging_getMessage: ' + e); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 function __sp_messaging_delete(id){ |
|
1135 a("messageId" + typeof id); |
|
1136 if (!id) { |
|
1137 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:delete:id is missing");//SErrMissingArgument = 1003 |
|
1138 } |
|
1139 else |
|
1140 if ((typeof id) != "string") |
|
1141 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:deleteMessage:MessageId should be a string"); |
|
1142 |
|
1143 if ((typeof id == "string") && !(isNaN(id))) { |
|
1144 id = Number(id); |
|
1145 if (id == 0) { |
|
1146 throw new DeviceException(this.error.DATA_NOT_FOUND_ERR, "Messaging:delete:id not found"); |
|
1147 } |
|
1148 if (id < 0) { |
|
1149 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:delete:id is out of range"); |
|
1150 } |
|
1151 } |
|
1152 |
|
1153 var criteria = {}; |
|
1154 modifyObjectBaseProp(criteria); |
|
1155 criteria.MessageId = id; |
|
1156 |
|
1157 try { |
|
1158 // a("criteria.MessageId" + criteria.MessageId); |
|
1159 var result = this.so.IMessaging.Delete(criteria); |
|
1160 a("MapErrorCode[ result.ErrorCode ]" + MapErrorCode[result.ErrorCode]); |
|
1161 if (criteria) { |
|
1162 delete criteria.MessageId; |
|
1163 } |
|
1164 // a("result.ErrorCode" + result.ErrorCode); |
|
1165 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1166 { |
|
1167 if (result.ErrorMessage) { |
|
1168 // a("result.ErrorMessage"); |
|
1169 var err_msg = splitErrorMessage(result.ErrorMessage); |
|
1170 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:delete" + err_msg); |
|
1171 } |
|
1172 else { |
|
1173 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:delete:operation failed"); |
|
1174 } |
|
1175 } |
|
1176 } |
|
1177 catch (e) { |
|
1178 __device_handle_exception(e, '__sp_messaging_delete: ' + e); |
|
1179 } |
|
1180 } |
|
1181 |
|
1182 function __sp_messaging_setStatus(id, status){ |
|
1183 |
|
1184 if (id == null || id == undefined || (id.length) <= 0) { |
|
1185 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:setStatus:id is missing");//SErrMissingArgument = 1003 |
|
1186 } |
|
1187 //a("id.length" + id.length); |
|
1188 if ((typeof id) != "string") { |
|
1189 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:id should be string");//SErrMissingArgument = 1003 |
|
1190 } |
|
1191 |
|
1192 if (status == null || status == undefined) { |
|
1193 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:setStatus:status is missing");//SErrMissingArgument = 1003 |
|
1194 } |
|
1195 |
|
1196 if (typeof status != "number") { |
|
1197 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:status is invalid"); //BadArgumentType error |
|
1198 } |
|
1199 |
|
1200 if (typeof status == "number" && status != 0 && status != 1) { |
|
1201 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:status is invalid"); //BadArgumentType error |
|
1202 } |
|
1203 |
|
1204 if ((typeof id == "string") && !(isNaN(id))) { |
|
1205 id = Number(id); |
|
1206 if (id == 0) { |
|
1207 throw new DeviceException(this.error.DATA_NOT_FOUND_ERR, "Messaging:setStatus:id not found"); |
|
1208 } |
|
1209 if (id < 0) { |
|
1210 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:setStatus:id is out of range"); |
|
1211 } |
|
1212 } |
|
1213 |
|
1214 var criteria = {}; |
|
1215 modifyObjectBaseProp(criteria); |
|
1216 criteria.MessageId = id; |
|
1217 if ((status == this.STATUS_UNREAD)) { |
|
1218 criteria.Status = "Unread"; |
|
1219 } |
|
1220 else |
|
1221 if ((status == this.STATUS_READ)) { |
|
1222 a("in read") |
|
1223 criteria.Status = "Read"; |
|
1224 } |
|
1225 try { |
|
1226 var result = this.so.IMessaging.ChangeStatus(criteria); |
|
1227 if (criteria) { |
|
1228 delete criteria.MessageId; |
|
1229 delete criteria.Status; |
|
1230 } |
|
1231 // a("result.ErrorCode" + result.ErrorCode); |
|
1232 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1233 { |
|
1234 //a("error code is non-zero") |
|
1235 if (result.ErrorMessage) { |
|
1236 var err_msg = splitErrorMessage(result.ErrorMessage); |
|
1237 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:setStatus" + err_msg); |
|
1238 } |
|
1239 else { |
|
1240 throw new DeviceException(MapErrorCode[result.ErrorCode], "Messaging:setStatus:operation failed"); |
|
1241 } |
|
1242 } |
|
1243 } |
|
1244 catch (e) { |
|
1245 __device_handle_exception(e, '__sp_messaging_setStatus: ' + e); |
|
1246 } |
|
1247 } |
|
1248 |
|
1249 function __sp_messaging_cancel(transactionId){ |
|
1250 |
|
1251 if (transactionId == null || transactionId == undefined) { |
|
1252 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:setStatus:id is missing");//SErrMissingArgument = 1003 |
|
1253 } |
|
1254 |
|
1255 if (typeof transactionId != "number") { |
|
1256 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:cancel:id is invalid");//SErrMissingArgument = 1003 |
|
1257 } |
|
1258 var criteria = {}; |
|
1259 modifyObjectBaseProp(criteria); |
|
1260 criteria.TransactionID = transactionId; |
|
1261 // a("in cancel"); |
|
1262 try { |
|
1263 var result = this.so.IMessaging.Cancel(criteria); |
|
1264 if (criteria) { |
|
1265 delete criteria.TransactionID; |
|
1266 } |
|
1267 //alert("result.ErrorCode" + result.ErrorCode); |
|
1268 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
|
1269 { |
|
1270 var err; |
|
1271 if (result.ErrorCode == 1000) { |
|
1272 err = this.error.DATA_NOT_FOUND_ERR; |
|
1273 } |
|
1274 else { |
|
1275 err = MapErrorCode[result.ErrorCode]; |
|
1276 } |
|
1277 if (result.ErrorMessage) { |
|
1278 var err_msg = splitErrorMessage(result.ErrorMessage); |
|
1279 throw new DeviceException(err, "Messaging:cancel" + err_msg); |
|
1280 } |
|
1281 else { |
|
1282 throw new DeviceException(err, "Messaging:cancel:operation failed"); |
|
1283 } |
|
1284 } |
|
1285 } |
|
1286 catch (e) { |
|
1287 __device_handle_exception(e, '__sp_messaging_setStatus: ' + e); |
|
1288 } |
|
1289 } |