blob: 13273fd88319a8f2a91791d88f92014030a298c9 [file] [log] [blame]
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -04001/*
Adrien Béraude552f692020-11-03 14:30:52 -05002 * Copyright (C) 2004-2020 Savoir-faire Linux Inc.
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -04003 *
4 * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com>
Adrien Béraud64538722018-03-15 17:34:00 -04005 * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -04006 *
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 */
21package cx.ring.conversation;
22
Pierre Duchemine0c3a492018-02-01 16:22:45 -050023import java.io.File;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040024
25import javax.inject.Inject;
Adrien Béraudace37a22018-06-22 14:58:36 -040026import javax.inject.Named;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040027
28import cx.ring.daemon.Blob;
29import cx.ring.facades.ConversationFacade;
Adrien Béraud20d42212018-03-02 14:40:38 -050030import cx.ring.model.Account;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040031import cx.ring.model.CallContact;
32import cx.ring.model.Conference;
33import cx.ring.model.Conversation;
Adrien Béraud7c505112018-03-20 16:03:28 -040034import cx.ring.model.DataTransfer;
Adrien Bérauda0226ff2019-11-21 15:24:42 -050035import cx.ring.model.Error;
Adrien Béraud37fb52e2020-10-02 19:24:31 -040036import cx.ring.model.Interaction;
Aline Bonnet15fdf0a2017-04-26 17:02:58 -040037import cx.ring.model.SipCall;
Pierre Duchemin1fa61922018-01-18 10:09:02 -050038import cx.ring.model.TrustRequest;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040039import cx.ring.model.Uri;
40import cx.ring.mvp.RootPresenter;
41import cx.ring.services.AccountService;
42import cx.ring.services.ContactService;
Pierre Duchemin4af6b392018-02-02 11:23:56 -050043import cx.ring.services.DeviceRuntimeService;
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -050044import cx.ring.services.HardwareService;
Amirhossein4ae37ef2020-11-30 23:26:27 -050045import cx.ring.services.PreferencesService;
Hadrien De Sousa6cd2bd22018-01-02 16:11:32 -050046import cx.ring.services.VCardService;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050047import cx.ring.utils.Log;
Adrien Béraudace37a22018-06-22 14:58:36 -040048import cx.ring.utils.StringUtils;
Adrien Béraud5477ce82020-02-24 11:13:54 -050049import cx.ring.utils.Tuple;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040050import cx.ring.utils.VCardUtils;
Amirhossein5ee9d412020-04-04 13:44:52 -040051import io.reactivex.Observable;
Adrien Béraudace37a22018-06-22 14:58:36 -040052import io.reactivex.Scheduler;
53import io.reactivex.disposables.CompositeDisposable;
54import io.reactivex.schedulers.Schedulers;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040055import io.reactivex.subjects.BehaviorSubject;
56import io.reactivex.subjects.Subject;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040057
Adrien Béraudace37a22018-06-22 14:58:36 -040058public class ConversationPresenter extends RootPresenter<ConversationView> {
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040059
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050060 private static final String TAG = ConversationPresenter.class.getSimpleName();
Adrien Béraud68f1adb2018-07-18 18:35:21 -040061 private final ContactService mContactService;
Adrien Béraudace37a22018-06-22 14:58:36 -040062 private final AccountService mAccountService;
Adrien Béraudace37a22018-06-22 14:58:36 -040063 private final HardwareService mHardwareService;
64 private final ConversationFacade mConversationFacade;
65 private final VCardService mVCardService;
66 private final DeviceRuntimeService mDeviceRuntimeService;
Amirhossein4ae37ef2020-11-30 23:26:27 -050067 private final PreferencesService mPreferencesService;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040068
69 private Conversation mConversation;
Adrien Béraudfd458ea2020-02-28 13:40:18 -050070 private Uri mContactUri;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050071 private String mAccountId;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040072
Adrien Béraudace37a22018-06-22 14:58:36 -040073 private CompositeDisposable mConversationDisposable;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040074 private final CompositeDisposable mVisibilityDisposable = new CompositeDisposable();
Adrien Béraudace37a22018-06-22 14:58:36 -040075
76 @Inject
77 @Named("UiScheduler")
78 protected Scheduler mUiScheduler;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040079
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040080 private final Subject<Conversation> mConversationSubject = BehaviorSubject.create();
81
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040082 @Inject
Adrien Béraud64538722018-03-15 17:34:00 -040083 public ConversationPresenter(ContactService contactService,
84 AccountService accountService,
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -050085 HardwareService hardwareService,
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050086 ConversationFacade conversationFacade,
Hadrien De Sousa6cd2bd22018-01-02 16:11:32 -050087 VCardService vCardService,
Amirhossein7bb77aa2020-12-18 16:30:44 -050088 DeviceRuntimeService deviceRuntimeService,
89 PreferencesService preferencesService) {
Adrien Béraudc35f7f42020-04-15 15:29:29 -040090 mContactService = contactService;
91 mAccountService = accountService;
92 mHardwareService = hardwareService;
93 mConversationFacade = conversationFacade;
94 mVCardService = vCardService;
95 mDeviceRuntimeService = deviceRuntimeService;
Amirhossein4ae37ef2020-11-30 23:26:27 -050096 mPreferencesService = preferencesService;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040097 }
98
99 @Override
Adrien Béraudace37a22018-06-22 14:58:36 -0400100 public void bindView(ConversationView view) {
101 super.bindView(view);
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400102 mCompositeDisposable.add(mVisibilityDisposable);
103 if (mConversationDisposable == null && mConversation != null)
104 initView(mConversation, view);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400105 }
106
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500107 public void init(Uri contactRingId, String accountId) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400108 Log.w(TAG, "init " + contactRingId + " " + accountId);
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500109 mContactUri = contactRingId;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500110 mAccountId = accountId;
Adrien Béraude5ec8952018-07-11 15:14:44 -0400111 Account account = mAccountService.getAccount(accountId);
Adrien Béraud9c166312019-10-25 14:24:15 -0400112 if (account != null) {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400113 initContact(account, contactRingId, getView());
Adrien Béraud9c166312019-10-25 14:24:15 -0400114 mCompositeDisposable.add(mConversationFacade.loadConversationHistory(account, contactRingId)
115 .observeOn(mUiScheduler)
116 .subscribe(this::setConversation, e -> getView().goToHome()));
117 } else {
118 getView().goToHome();
Adrien Bérauddbb351f2020-12-04 18:20:04 -0500119 return;
Adrien Béraud9c166312019-10-25 14:24:15 -0400120 }
Amirhossein5ee9d412020-04-04 13:44:52 -0400121
122 mCompositeDisposable.add(Observable.combineLatest(
123 mHardwareService.getConnectivityState(),
Adrien Bérauddbb351f2020-12-04 18:20:04 -0500124 mAccountService.getObservableAccount(account),
Amirhossein5ee9d412020-04-04 13:44:52 -0400125 (isConnected, a) -> isConnected || a.isRegistered())
126 .observeOn(mUiScheduler)
127 .subscribe(isOk -> {
128 ConversationView view = getView();
129 if (view != null) {
130 if (isOk)
131 view.hideErrorPanel();
132 else
133 view.displayNetworkErrorPanel();
134 }
135 }));
Amirhossein85b3f2e2020-12-01 13:05:43 -0500136
Amirhossein7bb77aa2020-12-18 16:30:44 -0500137 getView().setReadIndicatorStatus(showReadIndicator());
Adrien Béraudace37a22018-06-22 14:58:36 -0400138 }
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500139
Adrien Béraudace37a22018-06-22 14:58:36 -0400140 private void setConversation(final Conversation conversation) {
141 if (conversation == null || mConversation == conversation)
142 return;
143 mConversation = conversation;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400144 mConversationSubject.onNext(conversation);
145 ConversationView view = getView();
146 if (view != null)
147 initView(conversation, view);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400148 }
149
150 public void pause() {
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400151 mVisibilityDisposable.clear();
Adrien Béraudace37a22018-06-22 14:58:36 -0400152 if (mConversation != null) {
Adrien Béraud64538722018-03-15 17:34:00 -0400153 mConversation.setVisible(false);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400154 }
155 }
156
Amirhossein68916382020-07-19 11:23:59 -0400157 public void resume(boolean isBubble) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500158 Log.w(TAG, "resume " + mConversation + " " + mAccountId + " " + mContactUri);
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400159 mVisibilityDisposable.clear();
Adrien Béraude5ec8952018-07-11 15:14:44 -0400160 mVisibilityDisposable.add(mConversationSubject
161 .firstOrError()
162 .subscribe(conversation -> {
163 conversation.setVisible(true);
Adrien Béraud4a643052019-11-18 12:41:23 -0500164 updateOngoingCallView(conversation);
Amirhossein68916382020-07-19 11:23:59 -0400165 mConversationFacade.readMessages(mAccountService.getAccount(mAccountId), conversation, !isBubble);
Rayan Osseiran6f415662019-10-25 14:23:25 -0400166 }, e -> Log.e(TAG, "Error loading conversation", e)));
Adrien Béraudace37a22018-06-22 14:58:36 -0400167 }
168
Rayan Osseiran6f415662019-10-25 14:23:25 -0400169 private CallContact initContact(final Account account, final Uri uri,
170 final ConversationView view) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400171 CallContact contact;
Adrien Béraudf5d5ce92020-05-07 03:02:19 -0400172 if (account.isJami()) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400173 String rawId = uri.getRawRingId();
174 contact = account.getContact(rawId);
175 if (contact == null) {
176 contact = account.getContactFromCache(uri);
Adrien Béraudbf81ead2019-06-29 00:16:43 -0400177 TrustRequest req = account.getRequest(uri);
Adrien Béraudace37a22018-06-22 14:58:36 -0400178 if (req == null) {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400179 view.switchToUnknownView(contact.getRingUsername());
Adrien Béraudace37a22018-06-22 14:58:36 -0400180 } else {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400181 view.switchToIncomingTrustRequestView(req.getDisplayname());
Adrien Béraudace37a22018-06-22 14:58:36 -0400182 }
183 } else {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400184 view.switchToConversationView();
Adrien Béraudace37a22018-06-22 14:58:36 -0400185 }
186 Log.w(TAG, "initContact " + contact.getUsername());
187 if (contact.getUsername() == null) {
188 mAccountService.lookupAddress(mAccountId, "", rawId);
189 }
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500190 } else {
Adrien Béraudace37a22018-06-22 14:58:36 -0400191 contact = mContactService.findContact(account, uri);
Adrien Béraude5ec8952018-07-11 15:14:44 -0400192 view.switchToConversationView();
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500193 }
Adrien Béraud78ae7b92018-08-25 19:04:17 -0400194 view.displayContact(contact);
Adrien Béraudace37a22018-06-22 14:58:36 -0400195 return contact;
196 }
197
198 private void initView(final Conversation c, final ConversationView view) {
199 Log.w(TAG, "initView");
200 if (mConversationDisposable == null) {
201 mConversationDisposable = new CompositeDisposable();
202 mCompositeDisposable.add(mConversationDisposable);
203 }
204 mConversationDisposable.clear();
205 view.hideNumberSpinner();
206
207 Account account = mAccountService.getAccount(mAccountId);
Adrien Béraudace37a22018-06-22 14:58:36 -0400208
Rayan Osseiran6f415662019-10-25 14:23:25 -0400209
Adrien Béraudace37a22018-06-22 14:58:36 -0400210 mConversationDisposable.add(c.getSortedHistory()
Adrien Béraudf2c76ed2019-05-25 03:36:48 -0400211 .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update element", e)));
Adrien Bérauda084cd12018-12-31 12:49:12 -0500212 mConversationDisposable.add(c.getCleared()
Adrien Béraud08eb45e2019-02-18 01:58:12 -0500213 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400214 .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update elements", e)));
Adrien Béraud9ec82442019-02-18 01:55:16 -0500215 mConversationDisposable.add(mContactService.getLoadedContact(c.getAccountId(), c.getContact())
Adrien Béraudace37a22018-06-22 14:58:36 -0400216 .observeOn(mUiScheduler)
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500217 .subscribe(contact -> initContact(account, mContactUri, view), e -> Log.e(TAG, "Can't get contact", e)));
Adrien Béraudace37a22018-06-22 14:58:36 -0400218 mConversationDisposable.add(c.getUpdatedElements()
219 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400220 .subscribe(elementTuple -> {
221 switch(elementTuple.second) {
222 case ADD:
223 view.addElement(elementTuple.first);
224 break;
225 case UPDATE:
226 view.updateElement(elementTuple.first);
227 break;
228 case REMOVE:
229 view.removeElement(elementTuple.first);
230 break;
231 }
232 }, e -> Log.e(TAG, "Can't update element", e)));
Amirhossein4ae37ef2020-11-30 23:26:27 -0500233 if (showTypingIndicator()) {
234 mConversationDisposable.add(c.getComposingStatus()
235 .observeOn(mUiScheduler)
236 .subscribe(view::setComposingStatus));
237 }
Adrien Béraud263cd5c2020-03-13 13:36:57 -0400238 mConversationDisposable.add(c.getLastDisplayed()
239 .observeOn(mUiScheduler)
240 .subscribe(view::setLastDisplayed));
Adrien Béraudace37a22018-06-22 14:58:36 -0400241 mConversationDisposable.add(c.getCalls()
242 .observeOn(mUiScheduler)
Adrien Béraud4a643052019-11-18 12:41:23 -0500243 .subscribe(calls -> updateOngoingCallView(mConversation), e -> Log.e(TAG, "Can't update call view", e)));
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500244 mConversationDisposable.add(c.getColor()
245 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400246 .subscribe(view::setConversationColor, e -> Log.e(TAG, "Can't update conversation color", e)));
Adrien Béraud5477ce82020-02-24 11:13:54 -0500247
248 Log.e(TAG, "getLocationUpdates subscribe");
249 mConversationDisposable.add(account
250 .getLocationUpdates(c.getContact().getPrimaryUri())
251 .observeOn(mUiScheduler)
252 .subscribe(u -> {
253 Log.e(TAG, "getLocationUpdates: update");
254 getView().showMap(c.getAccountId(), c.getContact().getPrimaryUri().getUri(), false);
255 }));
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400256 }
257
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500258 public void openContact() {
Adrien Béraud91f88742019-09-09 00:46:46 -0400259 if (mConversation != null)
260 getView().goToContactActivity(mAccountId, mConversation.getContact().getPrimaryNumber());
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400261 }
262
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500263 public void sendTextMessage(String message) {
Adrien Béraud91f88742019-09-09 00:46:46 -0400264 if (StringUtils.isEmpty(message) || mConversation == null) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400265 return;
266 }
267 Conference conference = mConversation.getCurrentCall();
268 if (conference == null || !conference.isOnGoing()) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500269 mConversationFacade.sendTextMessage(mAccountId, mConversation, mContactUri, message).subscribe();
Adrien Béraudace37a22018-06-22 14:58:36 -0400270 } else {
271 mConversationFacade.sendTextMessage(mConversation, conference, message);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400272 }
273 }
274
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500275 public void selectFile() {
276 getView().openFilePicker();
277 }
278
Adrien Béraud64538722018-03-15 17:34:00 -0400279 public void sendFile(File file) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500280 mConversationFacade.sendFile(mAccountId, mContactUri, file).subscribe();
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500281 }
282
amine younes7c56f312019-06-10 11:34:25 -0400283 /**
284 * Gets the absolute path of the file dataTransfer and sends both the DataTransfer and the
285 * found path to the ConversationView in order to start saving the file
Rayan Osseiran6f415662019-10-25 14:23:25 -0400286 *
287 * @param interaction an interaction representing a datat transfer
amine younes7c56f312019-06-10 11:34:25 -0400288 */
Rayan Osseiran6f415662019-10-25 14:23:25 -0400289 public void saveFile(Interaction interaction) {
290 DataTransfer transfer = (DataTransfer) interaction;
291 String fileAbsolutePath = getDeviceRuntimeService().
amine younes7c56f312019-06-10 11:34:25 -0400292 getConversationPath(transfer.getPeerId(), transfer.getStoragePath())
Rayan Osseiran6f415662019-10-25 14:23:25 -0400293 .getAbsolutePath();
294 getView().startSaveFile(transfer, fileAbsolutePath);
Adrien Béraud7c505112018-03-20 16:03:28 -0400295 }
296
Rayan Osseiran6f415662019-10-25 14:23:25 -0400297 public void shareFile(Interaction interaction) {
298 DataTransfer file = (DataTransfer) interaction;
Adrien Béraudfcf457f2018-04-03 17:46:34 -0400299 File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
300 getView().shareFile(path);
301 }
302
Rayan Osseiran6f415662019-10-25 14:23:25 -0400303 public void openFile(Interaction interaction) {
304 DataTransfer file = (DataTransfer) interaction;
Adrien Béraudb2b3f442018-12-01 17:42:38 -0500305 File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
306 getView().openFile(path);
307 }
308
Rayan Osseiran6f415662019-10-25 14:23:25 -0400309 public void deleteConversationItem(Interaction element) {
Rayan Osseirane634a562019-05-29 13:44:55 -0400310 mConversationFacade.deleteConversationItem(element);
311 }
312
Rayan Osseiran6f415662019-10-25 14:23:25 -0400313 public void cancelMessage(Interaction message) {
Rayan Osseirane634a562019-05-29 13:44:55 -0400314 mConversationFacade.cancelMessage(message);
Adrien Béraud7c505112018-03-20 16:03:28 -0400315 }
316
Adrien Béraud4a643052019-11-18 12:41:23 -0500317 private void sendTrustRequest() {
Adrien Béraud0acf5a12018-08-02 13:40:40 -0400318 final String accountId = mAccountId;
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500319 final Uri contactId = mContactUri;
Adrien Béraud1cab7d12020-08-06 12:38:58 -0400320 CallContact contact = mContactService.findContact(mAccountService.getAccount(accountId), contactId);
321 if (contact != null) {
322 contact.setStatus(CallContact.Status.REQUEST_SENT);
323 }
Adrien Béraudbdfb5e12019-02-18 15:46:44 -0500324 mVCardService.loadSmallVCard(accountId, VCardService.MAX_SIZE_REQUEST)
325 .subscribeOn(Schedulers.computation())
Adrien Béraud1cab7d12020-08-06 12:38:58 -0400326 .subscribe(vCard -> mAccountService.sendTrustRequest(accountId, contactId.getRawRingId(), Blob.fromString(VCardUtils.vcardToString(vCard))),
327 e -> mAccountService.sendTrustRequest(accountId, contactId.getRawRingId(), null));
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400328 }
329
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400330 public void clickOnGoingPane() {
Amirhossein1cbc8df2020-08-14 11:48:30 -0400331 Conference conf = mConversation == null ? null : mConversation.getCurrentCall();
Adrien Beraud4f644382017-07-21 17:01:51 -0400332 if (conf != null) {
333 getView().goToCallActivity(conf.getId());
334 } else {
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500335 getView().displayOnGoingCallPane(false);
Adrien Beraud4f644382017-07-21 17:01:51 -0400336 }
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400337 }
338
Adrien Béraud4a643052019-11-18 12:41:23 -0500339 public void goToCall(boolean audioOnly) {
Adrien Béraudd3bf4e42018-02-14 14:44:41 +0100340 if (audioOnly && !mHardwareService.hasMicrophone()) {
Adrien Bérauda0226ff2019-11-21 15:24:42 -0500341 getView().displayErrorToast(Error.NO_MICROPHONE);
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -0500342 return;
343 }
344
Adrien Béraud4a643052019-11-18 12:41:23 -0500345 mCompositeDisposable.add(mConversationSubject
346 .firstElement()
347 .subscribe(conversation -> {
348 ConversationView view = getView();
349 if (view != null) {
350 Conference conf = mConversation.getCurrentCall();
351 if (conf != null
352 && !conf.getParticipants().isEmpty()
353 && conf.getParticipants().get(0).getCallStatus() != SipCall.CallStatus.INACTIVE
354 && conf.getParticipants().get(0).getCallStatus() != SipCall.CallStatus.FAILURE) {
355 view.goToCallActivity(conf.getId());
356 } else {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500357 view.goToCallActivityWithResult(mAccountId, mContactUri.getRawUriString(), audioOnly);
Adrien Béraud4a643052019-11-18 12:41:23 -0500358 }
359 }
360 }));
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400361 }
362
Adrien Béraud4a643052019-11-18 12:41:23 -0500363 private void updateOngoingCallView(Conversation conversation) {
364 Conference conf = conversation == null ? null : conversation.getCurrentCall();
Rayan Osseiran6f415662019-10-25 14:23:25 -0400365 if (conf != null && (conf.getState() == SipCall.CallStatus.CURRENT || conf.getState() == SipCall.CallStatus.HOLD || conf.getState() == SipCall.CallStatus.RINGING)) {
Adrien Béraud20d42212018-03-02 14:40:38 -0500366 getView().displayOnGoingCallPane(true);
367 } else {
368 getView().displayOnGoingCallPane(false);
369 }
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400370 }
371
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500372 public void onBlockIncomingContactRequest() {
373 String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId;
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500374 mConversationFacade.discardRequest(accountId, mContactUri);
375 mAccountService.removeContact(accountId, mContactUri.getHost(), true);
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500376
377 getView().goToHome();
378 }
379
380 public void onRefuseIncomingContactRequest() {
381 String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId;
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500382
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500383 mConversationFacade.discardRequest(accountId, mContactUri);
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500384 getView().goToHome();
385 }
386
387 public void onAcceptIncomingContactRequest() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500388 mConversationFacade.acceptRequest(mAccountId, mContactUri);
Adrien Béraudace37a22018-06-22 14:58:36 -0400389 getView().switchToConversationView();
390 }
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500391
Adrien Béraudace37a22018-06-22 14:58:36 -0400392 public void onAddContact() {
393 sendTrustRequest();
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500394 getView().switchToConversationView();
395 }
396
Pierre Duchemin4af6b392018-02-02 11:23:56 -0500397 public DeviceRuntimeService getDeviceRuntimeService() {
398 return mDeviceRuntimeService;
399 }
Pierre Duchemindf6cb5a2018-02-09 18:05:21 -0500400
401 public void noSpaceLeft() {
402 Log.e(TAG, "configureForFileInfoTextMessage: no space left on device");
Adrien Bérauda0226ff2019-11-21 15:24:42 -0500403 getView().displayErrorToast(Error.NO_SPACE_LEFT);
Pierre Duchemindf6cb5a2018-02-09 18:05:21 -0500404 }
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500405
406 public void setConversationColor(int color) {
407 mCompositeDisposable.add(mConversationSubject
408 .firstElement()
409 .subscribe(conversation -> conversation.setColor(color)));
410 }
Rayan Osseiran38206c62019-05-15 14:49:03 -0400411
412 public void cameraPermissionChanged(boolean isGranted) {
413 if (isGranted && mHardwareService.isVideoAvailable()) {
Adrien Béraud37fb52e2020-10-02 19:24:31 -0400414 mHardwareService.initVideo()
415 .onErrorComplete()
416 .subscribe();
Rayan Osseiran38206c62019-05-15 14:49:03 -0400417 }
418 }
419
Adrien Béraud5477ce82020-02-24 11:13:54 -0500420 public void shareLocation() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500421 getView().startShareLocation(mAccountId, mContactUri.getUri());
Adrien Béraud5477ce82020-02-24 11:13:54 -0500422 }
423
424 public Tuple<String, String> getPath() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500425 return new Tuple<>(mAccountId, mContactUri.getUri());
426 }
427
428 public void onComposingChanged(boolean hasMessage) {
Amirhossein4ae37ef2020-11-30 23:26:27 -0500429 if (mConversation == null || !showTypingIndicator()) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500430 return;
431 }
432 mConversationFacade.setIsComposing(mAccountId, mContactUri, hasMessage);
Adrien Béraud5477ce82020-02-24 11:13:54 -0500433 }
Amirhossein4ae37ef2020-11-30 23:26:27 -0500434
435 public boolean showTypingIndicator() {
436 return mPreferencesService.getSettings().isAllowTypingIndicator();
437 }
438
Amirhossein7bb77aa2020-12-18 16:30:44 -0500439 private boolean showReadIndicator() {
Amirhossein85b3f2e2020-12-01 13:05:43 -0500440 return mPreferencesService.getSettings().isAllowReadIndicator();
441 }
442
Amirhossein7bb77aa2020-12-18 16:30:44 -0500443 public boolean isRecordingBlocked(){
444 return mPreferencesService.getSettings().isRecordingBlocked();
445 }
446
Adrien Béraude32ab742018-08-25 21:15:08 -0400447}