blob: 36bb78a0594b8c95b104a6772af379654322e4ac [file] [log] [blame]
Sahin Caliskanf00a8762019-01-24 14:32:12 -08001/*
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
17package android.telephony.ims;
18
19import static android.provider.Telephony.RcsColumns.RcsUnifiedMessageColumns.MESSAGE_TYPE_INCOMING;
20
21import android.annotation.NonNull;
22import android.annotation.Nullable;
Sahin Caliskanf00a8762019-01-24 14:32:12 -080023
Sahin Caliskanf00a8762019-01-24 14:32:12 -080024import java.util.List;
Leland Miller35d29332019-03-22 14:19:25 -070025import java.util.stream.Collectors;
Sahin Caliskanf00a8762019-01-24 14:32:12 -080026
27/**
Sahin Caliskan2f932d72019-02-06 10:11:39 -080028 * The result of a {@link RcsMessageStore#getRcsMessages(RcsMessageQueryParams)}
Sahin Caliskanf00a8762019-01-24 14:32:12 -080029 * 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 Caliskan9a7e40e2019-02-21 15:35:44 -080031 *
32 * @hide
Sahin Caliskanf00a8762019-01-24 14:32:12 -080033 */
Leland Miller35d29332019-03-22 14:19:25 -070034public final class RcsMessageQueryResult {
Leland Millera3d9f762019-02-01 09:44:00 -080035 private final RcsControllerCall mRcsControllerCall;
Leland Miller35d29332019-03-22 14:19:25 -070036 private final RcsMessageQueryResultParcelable mRcsMessageQueryResultParcelable;
Sahin Caliskanf00a8762019-01-24 14:32:12 -080037
Leland Millera3d9f762019-02-01 09:44:00 -080038 RcsMessageQueryResult(RcsControllerCall rcsControllerCall,
39 RcsMessageQueryResultParcelable rcsMessageQueryResultParcelable) {
40 mRcsControllerCall = rcsControllerCall;
Leland Miller35d29332019-03-22 14:19:25 -070041 mRcsMessageQueryResultParcelable = rcsMessageQueryResultParcelable;
Sahin Caliskanf00a8762019-01-24 14:32:12 -080042 }
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 Miller35d29332019-03-22 14:19:25 -070051 return mRcsMessageQueryResultParcelable.mContinuationToken;
Sahin Caliskanf00a8762019-01-24 14:32:12 -080052 }
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 Miller35d29332019-03-22 14:19:25 -070061 return mRcsMessageQueryResultParcelable.mMessageTypeIdPairs.stream()
62 .map(typeIdPair -> typeIdPair.getType() == MESSAGE_TYPE_INCOMING
Leland Millera3d9f762019-02-01 09:44:00 -080063 ? new RcsIncomingMessage(mRcsControllerCall, typeIdPair.getId())
64 : new RcsOutgoingMessage(mRcsControllerCall, typeIdPair.getId()))
Leland Miller35d29332019-03-22 14:19:25 -070065 .collect(Collectors.toList());
Sahin Caliskanf00a8762019-01-24 14:32:12 -080066 }
67}