Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.telephony.ims; |
| 18 | |
| 19 | import static android.provider.Telephony.RcsColumns.RcsUnifiedMessageColumns.MESSAGE_TYPE_INCOMING; |
| 20 | |
| 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 23 | |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 24 | import java.util.List; |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 25 | import java.util.stream.Collectors; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
Sahin Caliskan | 2f932d7 | 2019-02-06 10:11:39 -0800 | [diff] [blame] | 28 | * The result of a {@link RcsMessageStore#getRcsMessages(RcsMessageQueryParams)} |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 29 | * call. This class allows getting the token for querying the next batch of messages in order to |
| 30 | * prevent handling large amounts of data at once. |
Sahin Caliskan | 9a7e40e | 2019-02-21 15:35:44 -0800 | [diff] [blame] | 31 | * |
| 32 | * @hide |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 33 | */ |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 34 | public final class RcsMessageQueryResult { |
Leland Miller | a3d9f76 | 2019-02-01 09:44:00 -0800 | [diff] [blame] | 35 | private final RcsControllerCall mRcsControllerCall; |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 36 | private final RcsMessageQueryResultParcelable mRcsMessageQueryResultParcelable; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 37 | |
Leland Miller | a3d9f76 | 2019-02-01 09:44:00 -0800 | [diff] [blame] | 38 | RcsMessageQueryResult(RcsControllerCall rcsControllerCall, |
| 39 | RcsMessageQueryResultParcelable rcsMessageQueryResultParcelable) { |
| 40 | mRcsControllerCall = rcsControllerCall; |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 41 | mRcsMessageQueryResultParcelable = rcsMessageQueryResultParcelable; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns a token to call |
| 46 | * {@link RcsMessageStore#getRcsMessages(RcsQueryContinuationToken)} |
| 47 | * to get the next batch of {@link RcsMessage}s. |
| 48 | */ |
| 49 | @Nullable |
| 50 | public RcsQueryContinuationToken getContinuationToken() { |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 51 | return mRcsMessageQueryResultParcelable.mContinuationToken; |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns all the {@link RcsMessage}s in the current query result. Call {@link |
| 56 | * RcsMessageStore#getRcsMessages(RcsQueryContinuationToken)} to get the next batch |
| 57 | * of {@link RcsMessage}s. |
| 58 | */ |
| 59 | @NonNull |
| 60 | public List<RcsMessage> getMessages() { |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 61 | return mRcsMessageQueryResultParcelable.mMessageTypeIdPairs.stream() |
| 62 | .map(typeIdPair -> typeIdPair.getType() == MESSAGE_TYPE_INCOMING |
Leland Miller | a3d9f76 | 2019-02-01 09:44:00 -0800 | [diff] [blame] | 63 | ? new RcsIncomingMessage(mRcsControllerCall, typeIdPair.getId()) |
| 64 | : new RcsOutgoingMessage(mRcsControllerCall, typeIdPair.getId())) |
Leland Miller | 35d2933 | 2019-03-22 14:19:25 -0700 | [diff] [blame] | 65 | .collect(Collectors.toList()); |
Sahin Caliskan | f00a876 | 2019-01-24 14:32:12 -0800 | [diff] [blame] | 66 | } |
| 67 | } |