Skip to content

Commit

Permalink
Bug 733320 - [WebSMS][B2G SMS] Add 'read' attribute to nsIDOMMozSmsMe…
Browse files Browse the repository at this point in the history
…ssage. Part 2 - WebSMS; r=mounir
  • Loading branch information
ferjm committed May 17, 2012
1 parent d554490 commit 9a16cf6
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 215 deletions.
68 changes: 33 additions & 35 deletions dom/sms/src/SmsFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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/. */

#include "SmsFilter.h"
#include "nsIDOMClassInfo.h"
Expand Down Expand Up @@ -66,6 +34,7 @@ SmsFilter::SmsFilter()
mData.startDate() = 0;
mData.endDate() = 0;
mData.delivery() = eDeliveryState_Unknown;
mData.read() = eReadState_Unknown;
}

SmsFilter::SmsFilter(const SmsFilterData& aData)
Expand Down Expand Up @@ -259,6 +228,35 @@ SmsFilter::SetDelivery(const nsAString& aDelivery)
return NS_ERROR_INVALID_ARG;
}

NS_IMETHODIMP
SmsFilter::GetRead(JSContext* aCx, jsval* aRead)
{
if (mData.read() == eReadState_Unknown) {
*aRead = JSVAL_VOID;
return NS_OK;
}

aRead->setBoolean(mData.read());

return NS_OK;
}

NS_IMETHODIMP
SmsFilter::SetRead(JSContext* aCx, const jsval& aRead)
{
if (aRead == JSVAL_VOID) {
mData.read() = eReadState_Unknown;
return NS_OK;
}

if (!aRead.isBoolean()) {
return NS_ERROR_INVALID_ARG;
}

mData.read() = aRead.toBoolean() ? eReadState_Read : eReadState_Unread;
return NS_OK;
}

} // namespace sms
} // namespace dom
} // namespace mozilla
61 changes: 26 additions & 35 deletions dom/sms/src/SmsManager.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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/. */

#include "SmsFilter.h"
#include "SmsManager.h"
Expand Down Expand Up @@ -316,6 +284,29 @@ SmsManager::GetMessages(nsIDOMMozSmsFilter* aFilter, bool aReverse,
return NS_OK;
}

NS_IMETHODIMP
SmsManager::MarkMessageRead(PRInt32 aId, bool aValue,
nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsISmsRequestManager> requestManager =
do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);

PRInt32 requestId;
nsresult rv = requestManager->CreateRequest(this, aRequest, &requestId);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create the request!");
return rv;
}

nsCOMPtr<nsISmsDatabaseService> smsDBService =
do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);

smsDBService->MarkMessageRead(aId, aValue, requestId, 0);

return NS_OK;
}

NS_IMPL_EVENT_HANDLER(SmsManager, received)
NS_IMPL_EVENT_HANDLER(SmsManager, sent)
NS_IMPL_EVENT_HANDLER(SmsManager, delivered)
Expand Down
52 changes: 14 additions & 38 deletions dom/sms/src/SmsMessage.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
* Philipp von Weitershausen <philipp@weitershausen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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/. */

#include "SmsMessage.h"
#include "nsIDOMClassInfo.h"
Expand All @@ -59,8 +26,8 @@ NS_IMPL_RELEASE(SmsMessage)

SmsMessage::SmsMessage(PRInt32 aId, DeliveryState aDelivery,
const nsString& aSender, const nsString& aReceiver,
const nsString& aBody, PRUint64 aTimestamp)
: mData(aId, aDelivery, aSender, aReceiver, aBody, aTimestamp)
const nsString& aBody, PRUint64 aTimestamp, bool aRead)
: mData(aId, aDelivery, aSender, aReceiver, aBody, aTimestamp, aRead)
{
}

Expand All @@ -76,6 +43,7 @@ SmsMessage::Create(PRInt32 aId,
const nsAString& aReceiver,
const nsAString& aBody,
const jsval& aTimestamp,
const bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage)
{
Expand All @@ -88,6 +56,7 @@ SmsMessage::Create(PRInt32 aId,
data.sender() = nsString(aSender);
data.receiver() = nsString(aReceiver);
data.body() = nsString(aBody);
data.read() = aRead;

if (aDelivery.Equals(DELIVERY_RECEIVED)) {
data.delivery() = eDeliveryState_Received;
Expand Down Expand Up @@ -181,6 +150,13 @@ SmsMessage::GetTimestamp(JSContext* cx, jsval* aDate)
return NS_OK;
}

NS_IMETHODIMP
SmsMessage::GetRead(bool* aRead)
{
*aRead = mData.read();
return NS_OK;
}

} // namespace sms
} // namespace dom
} // namespace mozilla
41 changes: 5 additions & 36 deletions dom/sms/src/SmsMessage.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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/. */

#ifndef mozilla_dom_sms_SmsMessage_h
#define mozilla_dom_sms_SmsMessage_h
Expand All @@ -56,7 +24,7 @@ class SmsMessage : public nsIDOMMozSmsMessage

SmsMessage(PRInt32 aId, DeliveryState aDelivery, const nsString& aSender,
const nsString& aReceiver, const nsString& aBody,
PRUint64 aTimestamp);
PRUint64 aTimestamp, bool aRead);
SmsMessage(const SmsMessageData& aData);

static nsresult Create(PRInt32 aId,
Expand All @@ -65,6 +33,7 @@ class SmsMessage : public nsIDOMMozSmsMessage
const nsAString& aReceiver,
const nsAString& aBody,
const JS::Value& aTimestamp,
const bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage);
const SmsMessageData& GetData() const;
Expand Down
50 changes: 15 additions & 35 deletions dom/sms/src/SmsRequestManager.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* 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/. */

#include "SmsRequestManager.h"
#include "nsIDOMSmsMessage.h"
Expand Down Expand Up @@ -245,6 +213,18 @@ SmsRequestManager::NotifyReadMessageListFailed(PRInt32 aRequestId, PRInt32 aErro
return NotifyError(aRequestId, aError);
}

NS_IMETHODIMP
SmsRequestManager::NotifyMarkedMessageRead(PRInt32 aRequestId, bool aRead)
{
return NotifySuccess<bool>(aRequestId, aRead);
}

NS_IMETHODIMP
SmsRequestManager::NotifyMarkMessageReadFailed(PRInt32 aRequestId, PRInt32 aError)
{
return NotifyError(aRequestId, aError);
}

} // namespace sms
} // namespace dom
} // namespace mozilla
Loading

0 comments on commit 9a16cf6

Please sign in to comment.