2011-11-22 09:34:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-17 19:42:38 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-22 09:34:21 +00:00
|
|
|
|
|
|
|
#include "SmsMessage.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
|
|
|
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
2012-01-15 08:13:07 +00:00
|
|
|
#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
|
2013-09-12 03:17:24 +00:00
|
|
|
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
2013-11-27 04:46:24 +00:00
|
|
|
#include "MessageUtils.h"
|
2011-11-22 09:34:21 +00:00
|
|
|
|
2013-03-01 08:38:47 +00:00
|
|
|
using namespace mozilla::dom::mobilemessage;
|
|
|
|
|
|
|
|
DOMCI_DATA(MozSmsMessage, mozilla::dom::SmsMessage)
|
2011-11-22 09:34:21 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(SmsMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsMessage)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(SmsMessage)
|
|
|
|
NS_IMPL_RELEASE(SmsMessage)
|
|
|
|
|
2012-10-30 10:53:24 +00:00
|
|
|
SmsMessage::SmsMessage(int32_t aId,
|
2013-11-02 10:17:16 +00:00
|
|
|
uint64_t aThreadId,
|
|
|
|
const nsString& aIccId,
|
2012-10-30 10:53:24 +00:00
|
|
|
DeliveryState aDelivery,
|
|
|
|
DeliveryStatus aDeliveryStatus,
|
|
|
|
const nsString& aSender,
|
|
|
|
const nsString& aReceiver,
|
|
|
|
const nsString& aBody,
|
2012-10-31 09:10:44 +00:00
|
|
|
MessageClass aMessageClass,
|
2012-10-30 10:53:24 +00:00
|
|
|
uint64_t aTimestamp,
|
2013-09-23 02:31:32 +00:00
|
|
|
uint64_t aSentTimestamp,
|
2013-11-01 12:00:55 +00:00
|
|
|
uint64_t aDeliveryTimestamp,
|
2012-10-30 10:53:24 +00:00
|
|
|
bool aRead)
|
2013-11-02 10:17:16 +00:00
|
|
|
: mData(aId, aThreadId, aIccId, aDelivery, aDeliveryStatus,
|
2013-09-23 02:31:32 +00:00
|
|
|
aSender, aReceiver, aBody, aMessageClass, aTimestamp, aSentTimestamp,
|
2013-11-02 10:17:16 +00:00
|
|
|
aDeliveryTimestamp, aRead)
|
2012-01-10 19:34:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-24 11:45:55 +00:00
|
|
|
SmsMessage::SmsMessage(const SmsMessageData& aData)
|
|
|
|
: mData(aData)
|
2011-11-22 09:34:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-24 05:02:52 +00:00
|
|
|
/* static */ nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
SmsMessage::Create(int32_t aId,
|
2013-11-02 10:17:16 +00:00
|
|
|
uint64_t aThreadId,
|
|
|
|
const nsAString& aIccId,
|
2011-12-24 05:02:52 +00:00
|
|
|
const nsAString& aDelivery,
|
2012-10-30 10:53:24 +00:00
|
|
|
const nsAString& aDeliveryStatus,
|
2011-12-24 05:02:52 +00:00
|
|
|
const nsAString& aSender,
|
|
|
|
const nsAString& aReceiver,
|
|
|
|
const nsAString& aBody,
|
2012-10-31 09:10:44 +00:00
|
|
|
const nsAString& aMessageClass,
|
2013-04-02 22:42:37 +00:00
|
|
|
const JS::Value& aTimestamp,
|
2013-09-23 02:31:32 +00:00
|
|
|
const JS::Value& aSentTimestamp,
|
2013-11-01 12:00:55 +00:00
|
|
|
const JS::Value& aDeliveryTimestamp,
|
2012-05-17 19:42:38 +00:00
|
|
|
const bool aRead,
|
2011-12-24 05:02:52 +00:00
|
|
|
JSContext* aCx,
|
|
|
|
nsIDOMMozSmsMessage** aMessage)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aMessage = nullptr;
|
2011-12-24 05:02:52 +00:00
|
|
|
|
|
|
|
// SmsMessageData exposes these as references, so we can simply assign
|
|
|
|
// to them.
|
|
|
|
SmsMessageData data;
|
|
|
|
data.id() = aId;
|
2013-04-05 12:15:52 +00:00
|
|
|
data.threadId() = aThreadId;
|
2013-11-02 10:17:16 +00:00
|
|
|
data.iccId() = nsString(aIccId);
|
2011-12-24 05:02:52 +00:00
|
|
|
data.sender() = nsString(aSender);
|
|
|
|
data.receiver() = nsString(aReceiver);
|
|
|
|
data.body() = nsString(aBody);
|
2012-05-17 19:42:38 +00:00
|
|
|
data.read() = aRead;
|
2011-12-24 05:02:52 +00:00
|
|
|
|
|
|
|
if (aDelivery.Equals(DELIVERY_RECEIVED)) {
|
|
|
|
data.delivery() = eDeliveryState_Received;
|
2012-12-11 09:09:42 +00:00
|
|
|
} else if (aDelivery.Equals(DELIVERY_SENDING)) {
|
|
|
|
data.delivery() = eDeliveryState_Sending;
|
2011-12-24 05:02:52 +00:00
|
|
|
} else if (aDelivery.Equals(DELIVERY_SENT)) {
|
|
|
|
data.delivery() = eDeliveryState_Sent;
|
2012-12-11 09:09:42 +00:00
|
|
|
} else if (aDelivery.Equals(DELIVERY_ERROR)) {
|
|
|
|
data.delivery() = eDeliveryState_Error;
|
2011-12-24 05:02:52 +00:00
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2012-10-30 10:53:24 +00:00
|
|
|
if (aDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
|
|
|
|
data.deliveryStatus() = eDeliveryStatus_NotApplicable;
|
|
|
|
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) {
|
|
|
|
data.deliveryStatus() = eDeliveryStatus_Success;
|
|
|
|
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
|
|
|
|
data.deliveryStatus() = eDeliveryStatus_Pending;
|
|
|
|
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
|
|
|
|
data.deliveryStatus() = eDeliveryStatus_Error;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:10:44 +00:00
|
|
|
if (aMessageClass.Equals(MESSAGE_CLASS_NORMAL)) {
|
|
|
|
data.messageClass() = eMessageClass_Normal;
|
|
|
|
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_0)) {
|
|
|
|
data.messageClass() = eMessageClass_Class0;
|
|
|
|
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_1)) {
|
|
|
|
data.messageClass() = eMessageClass_Class1;
|
|
|
|
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_2)) {
|
|
|
|
data.messageClass() = eMessageClass_Class2;
|
|
|
|
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_3)) {
|
|
|
|
data.messageClass() = eMessageClass_Class3;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-11-01 12:00:55 +00:00
|
|
|
// Set |timestamp|.
|
|
|
|
nsresult rv = convertTimeToInt(aCx, aTimestamp, data.timestamp());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-23 02:31:32 +00:00
|
|
|
// Set |sentTimestamp|.
|
|
|
|
rv = convertTimeToInt(aCx, aSentTimestamp, data.sentTimestamp());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-11-01 12:00:55 +00:00
|
|
|
// Set |deliveryTimestamp|.
|
|
|
|
rv = convertTimeToInt(aCx, aDeliveryTimestamp, data.deliveryTimestamp());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-12-24 05:02:52 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(data);
|
|
|
|
message.swap(*aMessage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-24 11:45:55 +00:00
|
|
|
const SmsMessageData&
|
|
|
|
SmsMessage::GetData() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
2013-03-08 03:46:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetType(nsAString& aType)
|
|
|
|
{
|
|
|
|
aType = NS_LITERAL_STRING("sms");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-22 09:34:21 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
SmsMessage::GetId(int32_t* aId)
|
2011-11-22 09:34:21 +00:00
|
|
|
{
|
2011-11-24 11:45:55 +00:00
|
|
|
*aId = mData.id();
|
2011-11-22 09:34:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:15:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetThreadId(uint64_t* aThreadId)
|
|
|
|
{
|
|
|
|
*aThreadId = mData.threadId();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-02 10:16:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetIccId(nsAString& aIccId)
|
|
|
|
{
|
2013-11-02 10:17:16 +00:00
|
|
|
aIccId = mData.iccId();
|
2013-11-02 10:16:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-22 09:34:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetDelivery(nsAString& aDelivery)
|
|
|
|
{
|
2011-11-24 11:45:55 +00:00
|
|
|
switch (mData.delivery()) {
|
2011-11-22 09:34:21 +00:00
|
|
|
case eDeliveryState_Received:
|
2012-01-17 18:48:58 +00:00
|
|
|
aDelivery = DELIVERY_RECEIVED;
|
2011-11-22 09:34:21 +00:00
|
|
|
break;
|
2012-12-11 09:09:42 +00:00
|
|
|
case eDeliveryState_Sending:
|
|
|
|
aDelivery = DELIVERY_SENDING;
|
|
|
|
break;
|
2011-11-24 11:45:55 +00:00
|
|
|
case eDeliveryState_Sent:
|
2012-01-17 18:48:58 +00:00
|
|
|
aDelivery = DELIVERY_SENT;
|
2011-11-24 11:45:55 +00:00
|
|
|
break;
|
2012-12-11 09:09:42 +00:00
|
|
|
case eDeliveryState_Error:
|
|
|
|
aDelivery = DELIVERY_ERROR;
|
|
|
|
break;
|
2011-11-24 11:45:55 +00:00
|
|
|
case eDeliveryState_Unknown:
|
2012-01-17 18:42:05 +00:00
|
|
|
case eDeliveryState_EndGuard:
|
2011-11-24 11:45:55 +00:00
|
|
|
default:
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("We shouldn't get any other delivery state!");
|
2012-10-30 10:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetDeliveryStatus(nsAString& aDeliveryStatus)
|
|
|
|
{
|
|
|
|
switch (mData.deliveryStatus()) {
|
|
|
|
case eDeliveryStatus_NotApplicable:
|
|
|
|
aDeliveryStatus = DELIVERY_STATUS_NOT_APPLICABLE;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Success:
|
|
|
|
aDeliveryStatus = DELIVERY_STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Pending:
|
|
|
|
aDeliveryStatus = DELIVERY_STATUS_PENDING;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Error:
|
|
|
|
aDeliveryStatus = DELIVERY_STATUS_ERROR;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_EndGuard:
|
|
|
|
default:
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("We shouldn't get any other delivery status!");
|
2011-11-22 09:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetSender(nsAString& aSender)
|
|
|
|
{
|
2011-11-24 11:45:55 +00:00
|
|
|
aSender = mData.sender();
|
2011-11-22 09:34:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetReceiver(nsAString& aReceiver)
|
|
|
|
{
|
2011-11-24 11:45:55 +00:00
|
|
|
aReceiver = mData.receiver();
|
2011-11-22 09:34:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetBody(nsAString& aBody)
|
|
|
|
{
|
2011-11-24 11:45:55 +00:00
|
|
|
aBody = mData.body();
|
2011-11-22 09:34:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:10:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetMessageClass(nsAString& aMessageClass)
|
|
|
|
{
|
|
|
|
switch (mData.messageClass()) {
|
|
|
|
case eMessageClass_Normal:
|
|
|
|
aMessageClass = MESSAGE_CLASS_NORMAL;
|
|
|
|
break;
|
|
|
|
case eMessageClass_Class0:
|
|
|
|
aMessageClass = MESSAGE_CLASS_CLASS_0;
|
|
|
|
break;
|
|
|
|
case eMessageClass_Class1:
|
|
|
|
aMessageClass = MESSAGE_CLASS_CLASS_1;
|
|
|
|
break;
|
|
|
|
case eMessageClass_Class2:
|
|
|
|
aMessageClass = MESSAGE_CLASS_CLASS_2;
|
|
|
|
break;
|
|
|
|
case eMessageClass_Class3:
|
|
|
|
aMessageClass = MESSAGE_CLASS_CLASS_3;
|
|
|
|
break;
|
|
|
|
default:
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("We shouldn't get any other message class!");
|
2012-10-31 09:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-22 09:34:21 +00:00
|
|
|
NS_IMETHODIMP
|
2013-09-23 02:31:12 +00:00
|
|
|
SmsMessage::GetTimestamp(DOMTimeStamp* aTimestamp)
|
2011-11-22 09:34:21 +00:00
|
|
|
{
|
2013-09-23 02:31:12 +00:00
|
|
|
*aTimestamp = mData.timestamp();
|
2011-11-22 09:34:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-23 02:31:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetSentTimestamp(DOMTimeStamp* aSentTimestamp)
|
|
|
|
{
|
2013-09-23 02:31:32 +00:00
|
|
|
*aSentTimestamp = mData.sentTimestamp();
|
|
|
|
return NS_OK;
|
2013-09-23 02:31:12 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 12:00:55 +00:00
|
|
|
NS_IMETHODIMP
|
2013-11-30 11:14:41 +00:00
|
|
|
SmsMessage::GetDeliveryTimestamp(DOMTimeStamp* aDate)
|
2013-11-01 12:00:55 +00:00
|
|
|
{
|
2013-11-30 11:14:41 +00:00
|
|
|
*aDate = mData.deliveryTimestamp();
|
2013-11-01 12:00:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-17 19:42:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SmsMessage::GetRead(bool* aRead)
|
|
|
|
{
|
|
|
|
*aRead = mData.read();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-22 09:34:21 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|