Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | ab53ada | 2019-01-02 17:23:00 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2019 Savoir-faire Linux Inc. |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com> |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 5 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | package cx.ring.conversation; |
| 22 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 23 | import java.io.File; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 24 | |
| 25 | import javax.inject.Inject; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 26 | import javax.inject.Named; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 27 | |
| 28 | import cx.ring.daemon.Blob; |
| 29 | import cx.ring.facades.ConversationFacade; |
Adrien Béraud | 20d4221 | 2018-03-02 14:40:38 -0500 | [diff] [blame] | 30 | import cx.ring.model.Account; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 31 | import cx.ring.model.CallContact; |
| 32 | import cx.ring.model.Conference; |
| 33 | import cx.ring.model.Conversation; |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 34 | import cx.ring.model.DataTransfer; |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 35 | import cx.ring.model.Interaction; |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 36 | import cx.ring.model.Error; |
Aline Bonnet | 15fdf0a | 2017-04-26 17:02:58 -0400 | [diff] [blame] | 37 | import cx.ring.model.SipCall; |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 38 | import cx.ring.model.TrustRequest; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 39 | import cx.ring.model.Uri; |
| 40 | import cx.ring.mvp.RootPresenter; |
| 41 | import cx.ring.services.AccountService; |
| 42 | import cx.ring.services.ContactService; |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 43 | import cx.ring.services.DeviceRuntimeService; |
Hadrien De Sousa | 45fb21b | 2017-12-14 11:06:48 -0500 | [diff] [blame] | 44 | import cx.ring.services.HardwareService; |
Hadrien De Sousa | 6cd2bd2 | 2018-01-02 16:11:32 -0500 | [diff] [blame] | 45 | import cx.ring.services.VCardService; |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 46 | import cx.ring.utils.Log; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 47 | import cx.ring.utils.StringUtils; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 48 | import cx.ring.utils.Tuple; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 49 | import cx.ring.utils.VCardUtils; |
Amirhossein | 5ee9d41 | 2020-04-04 13:44:52 -0400 | [diff] [blame^] | 50 | import io.reactivex.Observable; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 51 | import io.reactivex.Scheduler; |
| 52 | import io.reactivex.disposables.CompositeDisposable; |
| 53 | import io.reactivex.schedulers.Schedulers; |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 54 | import io.reactivex.subjects.BehaviorSubject; |
| 55 | import io.reactivex.subjects.Subject; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 56 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 57 | public class ConversationPresenter extends RootPresenter<ConversationView> { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 58 | |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 59 | private static final String TAG = ConversationPresenter.class.getSimpleName(); |
Adrien Béraud | 68f1adb | 2018-07-18 18:35:21 -0400 | [diff] [blame] | 60 | private final ContactService mContactService; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 61 | private final AccountService mAccountService; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 62 | private final HardwareService mHardwareService; |
| 63 | private final ConversationFacade mConversationFacade; |
| 64 | private final VCardService mVCardService; |
| 65 | private final DeviceRuntimeService mDeviceRuntimeService; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 66 | |
| 67 | private Conversation mConversation; |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 68 | private Uri mContactUri; |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 69 | private String mAccountId; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 70 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 71 | private CompositeDisposable mConversationDisposable; |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 72 | private final CompositeDisposable mVisibilityDisposable = new CompositeDisposable(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 73 | |
| 74 | @Inject |
| 75 | @Named("UiScheduler") |
| 76 | protected Scheduler mUiScheduler; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 77 | |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 78 | private final Subject<Conversation> mConversationSubject = BehaviorSubject.create(); |
| 79 | |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 80 | @Inject |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 81 | public ConversationPresenter(ContactService contactService, |
| 82 | AccountService accountService, |
Hadrien De Sousa | 45fb21b | 2017-12-14 11:06:48 -0500 | [diff] [blame] | 83 | HardwareService hardwareService, |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 84 | ConversationFacade conversationFacade, |
Hadrien De Sousa | 6cd2bd2 | 2018-01-02 16:11:32 -0500 | [diff] [blame] | 85 | VCardService vCardService, |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 86 | DeviceRuntimeService deviceRuntimeService) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 87 | this.mContactService = contactService; |
| 88 | this.mAccountService = accountService; |
Hadrien De Sousa | 45fb21b | 2017-12-14 11:06:48 -0500 | [diff] [blame] | 89 | this.mHardwareService = hardwareService; |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 90 | this.mConversationFacade = conversationFacade; |
Hadrien De Sousa | 6cd2bd2 | 2018-01-02 16:11:32 -0500 | [diff] [blame] | 91 | this.mVCardService = vCardService; |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 92 | this.mDeviceRuntimeService = deviceRuntimeService; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 96 | public void bindView(ConversationView view) { |
| 97 | super.bindView(view); |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 98 | mCompositeDisposable.add(mVisibilityDisposable); |
| 99 | if (mConversationDisposable == null && mConversation != null) |
| 100 | initView(mConversation, view); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 103 | public void init(Uri contactRingId, String accountId) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 104 | Log.w(TAG, "init " + contactRingId + " " + accountId); |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 105 | mContactUri = contactRingId; |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 106 | mAccountId = accountId; |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 107 | Account account = mAccountService.getAccount(accountId); |
Adrien Béraud | 9c16631 | 2019-10-25 14:24:15 -0400 | [diff] [blame] | 108 | if (account != null) { |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 109 | initContact(account, contactRingId, getView()); |
Adrien Béraud | 9c16631 | 2019-10-25 14:24:15 -0400 | [diff] [blame] | 110 | mCompositeDisposable.add(mConversationFacade.loadConversationHistory(account, contactRingId) |
| 111 | .observeOn(mUiScheduler) |
| 112 | .subscribe(this::setConversation, e -> getView().goToHome())); |
| 113 | } else { |
| 114 | getView().goToHome(); |
| 115 | } |
Amirhossein | 5ee9d41 | 2020-04-04 13:44:52 -0400 | [diff] [blame^] | 116 | |
| 117 | mCompositeDisposable.add(Observable.combineLatest( |
| 118 | mHardwareService.getConnectivityState(), |
| 119 | mAccountService.getObservableAccount(mAccountId), |
| 120 | (isConnected, a) -> isConnected || a.isRegistered()) |
| 121 | .observeOn(mUiScheduler) |
| 122 | .subscribe(isOk -> { |
| 123 | ConversationView view = getView(); |
| 124 | if (view != null) { |
| 125 | if (isOk) |
| 126 | view.hideErrorPanel(); |
| 127 | else |
| 128 | view.displayNetworkErrorPanel(); |
| 129 | } |
| 130 | })); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 131 | } |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 132 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 133 | private void setConversation(final Conversation conversation) { |
| 134 | if (conversation == null || mConversation == conversation) |
| 135 | return; |
| 136 | mConversation = conversation; |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 137 | mConversationSubject.onNext(conversation); |
| 138 | ConversationView view = getView(); |
| 139 | if (view != null) |
| 140 | initView(conversation, view); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | public void pause() { |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 144 | mVisibilityDisposable.clear(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 145 | if (mConversation != null) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 146 | mConversation.setVisible(false); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | public void resume() { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 151 | Log.w(TAG, "resume " + mConversation + " " + mAccountId + " " + mContactUri); |
Adrien Béraud | 7aa7a9e | 2018-06-29 19:50:32 -0400 | [diff] [blame] | 152 | mVisibilityDisposable.clear(); |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 153 | mVisibilityDisposable.add(mConversationSubject |
| 154 | .firstOrError() |
| 155 | .subscribe(conversation -> { |
| 156 | conversation.setVisible(true); |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 157 | updateOngoingCallView(conversation); |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 158 | mConversationFacade.readMessages(mAccountService.getAccount(mAccountId), conversation); |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 159 | }, e -> Log.e(TAG, "Error loading conversation", e))); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 162 | private CallContact initContact(final Account account, final Uri uri, |
| 163 | final ConversationView view) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 164 | CallContact contact; |
| 165 | if (account.isRing()) { |
| 166 | String rawId = uri.getRawRingId(); |
| 167 | contact = account.getContact(rawId); |
| 168 | if (contact == null) { |
| 169 | contact = account.getContactFromCache(uri); |
Adrien Béraud | bf81ead | 2019-06-29 00:16:43 -0400 | [diff] [blame] | 170 | TrustRequest req = account.getRequest(uri); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 171 | if (req == null) { |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 172 | view.switchToUnknownView(contact.getRingUsername()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 173 | } else { |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 174 | view.switchToIncomingTrustRequestView(req.getDisplayname()); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 175 | } |
| 176 | } else { |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 177 | view.switchToConversationView(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 178 | } |
| 179 | Log.w(TAG, "initContact " + contact.getUsername()); |
| 180 | if (contact.getUsername() == null) { |
| 181 | mAccountService.lookupAddress(mAccountId, "", rawId); |
| 182 | } |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 183 | } else { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 184 | contact = mContactService.findContact(account, uri); |
Adrien Béraud | e5ec895 | 2018-07-11 15:14:44 -0400 | [diff] [blame] | 185 | view.switchToConversationView(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 186 | } |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 187 | view.displayContact(contact); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 188 | return contact; |
| 189 | } |
| 190 | |
| 191 | private void initView(final Conversation c, final ConversationView view) { |
| 192 | Log.w(TAG, "initView"); |
| 193 | if (mConversationDisposable == null) { |
| 194 | mConversationDisposable = new CompositeDisposable(); |
| 195 | mCompositeDisposable.add(mConversationDisposable); |
| 196 | } |
| 197 | mConversationDisposable.clear(); |
| 198 | view.hideNumberSpinner(); |
| 199 | |
| 200 | Account account = mAccountService.getAccount(mAccountId); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 201 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 202 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 203 | mConversationDisposable.add(c.getSortedHistory() |
Adrien Béraud | f2c76ed | 2019-05-25 03:36:48 -0400 | [diff] [blame] | 204 | .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update element", e))); |
Adrien Béraud | a084cd1 | 2018-12-31 12:49:12 -0500 | [diff] [blame] | 205 | mConversationDisposable.add(c.getCleared() |
Adrien Béraud | 08eb45e | 2019-02-18 01:58:12 -0500 | [diff] [blame] | 206 | .observeOn(mUiScheduler) |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 207 | .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update elements", e))); |
Adrien Béraud | 9ec8244 | 2019-02-18 01:55:16 -0500 | [diff] [blame] | 208 | mConversationDisposable.add(mContactService.getLoadedContact(c.getAccountId(), c.getContact()) |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 209 | .observeOn(mUiScheduler) |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 210 | .subscribe(contact -> initContact(account, mContactUri, view), e -> Log.e(TAG, "Can't get contact", e))); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 211 | mConversationDisposable.add(c.getUpdatedElements() |
| 212 | .observeOn(mUiScheduler) |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 213 | .subscribe(elementTuple -> { |
| 214 | switch(elementTuple.second) { |
| 215 | case ADD: |
| 216 | view.addElement(elementTuple.first); |
| 217 | break; |
| 218 | case UPDATE: |
| 219 | view.updateElement(elementTuple.first); |
| 220 | break; |
| 221 | case REMOVE: |
| 222 | view.removeElement(elementTuple.first); |
| 223 | break; |
| 224 | } |
| 225 | }, e -> Log.e(TAG, "Can't update element", e))); |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 226 | mConversationDisposable.add(c.getComposingStatus() |
| 227 | .observeOn(mUiScheduler) |
| 228 | .subscribe(view::setComposingStatus)); |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 229 | mConversationDisposable.add(c.getLastDisplayed() |
| 230 | .observeOn(mUiScheduler) |
| 231 | .subscribe(view::setLastDisplayed)); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 232 | mConversationDisposable.add(c.getCalls() |
| 233 | .observeOn(mUiScheduler) |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 234 | .subscribe(calls -> updateOngoingCallView(mConversation), e -> Log.e(TAG, "Can't update call view", e))); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 235 | mConversationDisposable.add(c.getColor() |
| 236 | .observeOn(mUiScheduler) |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 237 | .subscribe(view::setConversationColor, e -> Log.e(TAG, "Can't update conversation color", e))); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 238 | |
| 239 | Log.e(TAG, "getLocationUpdates subscribe"); |
| 240 | mConversationDisposable.add(account |
| 241 | .getLocationUpdates(c.getContact().getPrimaryUri()) |
| 242 | .observeOn(mUiScheduler) |
| 243 | .subscribe(u -> { |
| 244 | Log.e(TAG, "getLocationUpdates: update"); |
| 245 | getView().showMap(c.getAccountId(), c.getContact().getPrimaryUri().getUri(), false); |
| 246 | })); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 249 | public void openContact() { |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 250 | if (mConversation != null) |
| 251 | getView().goToContactActivity(mAccountId, mConversation.getContact().getPrimaryNumber()); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 254 | public void sendTextMessage(String message) { |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 255 | if (StringUtils.isEmpty(message) || mConversation == null) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | Conference conference = mConversation.getCurrentCall(); |
| 259 | if (conference == null || !conference.isOnGoing()) { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 260 | mConversationFacade.sendTextMessage(mAccountId, mConversation, mContactUri, message).subscribe(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 261 | } else { |
| 262 | mConversationFacade.sendTextMessage(mConversation, conference, message); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 266 | public void selectFile() { |
| 267 | getView().openFilePicker(); |
| 268 | } |
| 269 | |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 270 | public void sendFile(File file) { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 271 | mConversationFacade.sendFile(mAccountId, mContactUri, file).subscribe(); |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 272 | } |
| 273 | |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 274 | /** |
| 275 | * Gets the absolute path of the file dataTransfer and sends both the DataTransfer and the |
| 276 | * found path to the ConversationView in order to start saving the file |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 277 | * |
| 278 | * @param interaction an interaction representing a datat transfer |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 279 | */ |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 280 | public void saveFile(Interaction interaction) { |
| 281 | DataTransfer transfer = (DataTransfer) interaction; |
| 282 | String fileAbsolutePath = getDeviceRuntimeService(). |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 283 | getConversationPath(transfer.getPeerId(), transfer.getStoragePath()) |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 284 | .getAbsolutePath(); |
| 285 | getView().startSaveFile(transfer, fileAbsolutePath); |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 288 | public void shareFile(Interaction interaction) { |
| 289 | DataTransfer file = (DataTransfer) interaction; |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 290 | File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath()); |
| 291 | getView().shareFile(path); |
| 292 | } |
| 293 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 294 | public void openFile(Interaction interaction) { |
| 295 | DataTransfer file = (DataTransfer) interaction; |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 296 | File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath()); |
| 297 | getView().openFile(path); |
| 298 | } |
| 299 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 300 | public void deleteConversationItem(Interaction element) { |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 301 | mConversationFacade.deleteConversationItem(element); |
| 302 | } |
| 303 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 304 | public void cancelMessage(Interaction message) { |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 305 | mConversationFacade.cancelMessage(message); |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 308 | private void sendTrustRequest() { |
Adrien Béraud | 0acf5a1 | 2018-08-02 13:40:40 -0400 | [diff] [blame] | 309 | final String accountId = mAccountId; |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 310 | final Uri contactId = mContactUri; |
Adrien Béraud | bdfb5e1 | 2019-02-18 15:46:44 -0500 | [diff] [blame] | 311 | mVCardService.loadSmallVCard(accountId, VCardService.MAX_SIZE_REQUEST) |
| 312 | .subscribeOn(Schedulers.computation()) |
| 313 | .subscribe(vCard -> { |
| 314 | mAccountService.sendTrustRequest(accountId, contactId.getRawRingId(), Blob.fromString(VCardUtils.vcardToString(vCard))); |
| 315 | CallContact contact = mContactService.findContact(mAccountService.getAccount(accountId), contactId); |
| 316 | if (contact == null) { |
| 317 | Log.e(TAG, "sendTrustRequest: not able to find contact"); |
| 318 | return; |
| 319 | } |
| 320 | contact.setStatus(CallContact.Status.REQUEST_SENT); |
| 321 | }); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 324 | public void clickOnGoingPane() { |
Adrien Beraud | 4f64438 | 2017-07-21 17:01:51 -0400 | [diff] [blame] | 325 | Conference conf = mConversation.getCurrentCall(); |
| 326 | if (conf != null) { |
| 327 | getView().goToCallActivity(conf.getId()); |
| 328 | } else { |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 329 | getView().displayOnGoingCallPane(false); |
Adrien Beraud | 4f64438 | 2017-07-21 17:01:51 -0400 | [diff] [blame] | 330 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 333 | public void goToCall(boolean audioOnly) { |
Adrien Béraud | d3bf4e4 | 2018-02-14 14:44:41 +0100 | [diff] [blame] | 334 | if (audioOnly && !mHardwareService.hasMicrophone()) { |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 335 | getView().displayErrorToast(Error.NO_MICROPHONE); |
Hadrien De Sousa | 45fb21b | 2017-12-14 11:06:48 -0500 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 339 | mCompositeDisposable.add(mConversationSubject |
| 340 | .firstElement() |
| 341 | .subscribe(conversation -> { |
| 342 | ConversationView view = getView(); |
| 343 | if (view != null) { |
| 344 | Conference conf = mConversation.getCurrentCall(); |
| 345 | if (conf != null |
| 346 | && !conf.getParticipants().isEmpty() |
| 347 | && conf.getParticipants().get(0).getCallStatus() != SipCall.CallStatus.INACTIVE |
| 348 | && conf.getParticipants().get(0).getCallStatus() != SipCall.CallStatus.FAILURE) { |
| 349 | view.goToCallActivity(conf.getId()); |
| 350 | } else { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 351 | view.goToCallActivityWithResult(mAccountId, mContactUri.getRawUriString(), audioOnly); |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | })); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 357 | private void updateOngoingCallView(Conversation conversation) { |
| 358 | Conference conf = conversation == null ? null : conversation.getCurrentCall(); |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 359 | if (conf != null && (conf.getState() == SipCall.CallStatus.CURRENT || conf.getState() == SipCall.CallStatus.HOLD || conf.getState() == SipCall.CallStatus.RINGING)) { |
Adrien Béraud | 20d4221 | 2018-03-02 14:40:38 -0500 | [diff] [blame] | 360 | getView().displayOnGoingCallPane(true); |
| 361 | } else { |
| 362 | getView().displayOnGoingCallPane(false); |
| 363 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 366 | public void onBlockIncomingContactRequest() { |
| 367 | String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId; |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 368 | mConversationFacade.discardRequest(accountId, mContactUri); |
| 369 | mAccountService.removeContact(accountId, mContactUri.getHost(), true); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 370 | |
| 371 | getView().goToHome(); |
| 372 | } |
| 373 | |
| 374 | public void onRefuseIncomingContactRequest() { |
| 375 | String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId; |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 376 | |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 377 | mConversationFacade.discardRequest(accountId, mContactUri); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 378 | getView().goToHome(); |
| 379 | } |
| 380 | |
| 381 | public void onAcceptIncomingContactRequest() { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 382 | mConversationFacade.acceptRequest(mAccountId, mContactUri); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 383 | getView().switchToConversationView(); |
| 384 | } |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 385 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 386 | public void onAddContact() { |
| 387 | sendTrustRequest(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 388 | getView().switchToConversationView(); |
| 389 | } |
| 390 | |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 391 | public DeviceRuntimeService getDeviceRuntimeService() { |
| 392 | return mDeviceRuntimeService; |
| 393 | } |
Pierre Duchemin | df6cb5a | 2018-02-09 18:05:21 -0500 | [diff] [blame] | 394 | |
| 395 | public void noSpaceLeft() { |
| 396 | Log.e(TAG, "configureForFileInfoTextMessage: no space left on device"); |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 397 | getView().displayErrorToast(Error.NO_SPACE_LEFT); |
Pierre Duchemin | df6cb5a | 2018-02-09 18:05:21 -0500 | [diff] [blame] | 398 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 399 | |
| 400 | public void setConversationColor(int color) { |
| 401 | mCompositeDisposable.add(mConversationSubject |
| 402 | .firstElement() |
| 403 | .subscribe(conversation -> conversation.setColor(color))); |
| 404 | } |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 405 | |
| 406 | public void cameraPermissionChanged(boolean isGranted) { |
| 407 | if (isGranted && mHardwareService.isVideoAvailable()) { |
Adrien Béraud | 99931dd | 2019-08-27 16:52:01 -0400 | [diff] [blame] | 408 | mHardwareService.initVideo().subscribe(); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 412 | public void shareLocation() { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 413 | getView().startShareLocation(mAccountId, mContactUri.getUri()); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | public Tuple<String, String> getPath() { |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 417 | return new Tuple<>(mAccountId, mContactUri.getUri()); |
| 418 | } |
| 419 | |
| 420 | public void onComposingChanged(boolean hasMessage) { |
| 421 | if (mConversation == null) { |
| 422 | return; |
| 423 | } |
| 424 | mConversationFacade.setIsComposing(mAccountId, mContactUri, hasMessage); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 425 | } |
Adrien Béraud | e32ab74 | 2018-08-25 21:15:08 -0400 | [diff] [blame] | 426 | } |