blob: 8a8186630f7e5fc2344a8b9738523606c829a935 [file] [log] [blame]
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -04001/*
Sébastien Blinab53ada2019-01-02 17:23:00 -05002 * Copyright (C) 2004-2019 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;
Rayan Osseiran6f415662019-10-25 14:23:25 -040035import cx.ring.model.Interaction;
Adrien Bérauda0226ff2019-11-21 15:24:42 -050036import cx.ring.model.Error;
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;
Hadrien De Sousa6cd2bd22018-01-02 16:11:32 -050045import cx.ring.services.VCardService;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050046import cx.ring.utils.Log;
Adrien Béraudace37a22018-06-22 14:58:36 -040047import cx.ring.utils.StringUtils;
Adrien Béraud5477ce82020-02-24 11:13:54 -050048import cx.ring.utils.Tuple;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040049import cx.ring.utils.VCardUtils;
Amirhossein5ee9d412020-04-04 13:44:52 -040050import io.reactivex.Observable;
Adrien Béraudace37a22018-06-22 14:58:36 -040051import io.reactivex.Scheduler;
52import io.reactivex.disposables.CompositeDisposable;
53import io.reactivex.schedulers.Schedulers;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040054import io.reactivex.subjects.BehaviorSubject;
55import io.reactivex.subjects.Subject;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040056
Adrien Béraudace37a22018-06-22 14:58:36 -040057public class ConversationPresenter extends RootPresenter<ConversationView> {
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040058
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050059 private static final String TAG = ConversationPresenter.class.getSimpleName();
Adrien Béraud68f1adb2018-07-18 18:35:21 -040060 private final ContactService mContactService;
Adrien Béraudace37a22018-06-22 14:58:36 -040061 private final AccountService mAccountService;
Adrien Béraudace37a22018-06-22 14:58:36 -040062 private final HardwareService mHardwareService;
63 private final ConversationFacade mConversationFacade;
64 private final VCardService mVCardService;
65 private final DeviceRuntimeService mDeviceRuntimeService;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040066
67 private Conversation mConversation;
Adrien Béraudfd458ea2020-02-28 13:40:18 -050068 private Uri mContactUri;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050069 private String mAccountId;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040070
Adrien Béraudace37a22018-06-22 14:58:36 -040071 private CompositeDisposable mConversationDisposable;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040072 private final CompositeDisposable mVisibilityDisposable = new CompositeDisposable();
Adrien Béraudace37a22018-06-22 14:58:36 -040073
74 @Inject
75 @Named("UiScheduler")
76 protected Scheduler mUiScheduler;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040077
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040078 private final Subject<Conversation> mConversationSubject = BehaviorSubject.create();
79
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040080 @Inject
Adrien Béraud64538722018-03-15 17:34:00 -040081 public ConversationPresenter(ContactService contactService,
82 AccountService accountService,
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -050083 HardwareService hardwareService,
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050084 ConversationFacade conversationFacade,
Hadrien De Sousa6cd2bd22018-01-02 16:11:32 -050085 VCardService vCardService,
Adrien Béraud7c505112018-03-20 16:03:28 -040086 DeviceRuntimeService deviceRuntimeService) {
Adrien Béraud64538722018-03-15 17:34:00 -040087 this.mContactService = contactService;
88 this.mAccountService = accountService;
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -050089 this.mHardwareService = hardwareService;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -050090 this.mConversationFacade = conversationFacade;
Hadrien De Sousa6cd2bd22018-01-02 16:11:32 -050091 this.mVCardService = vCardService;
Pierre Duchemin1fa61922018-01-18 10:09:02 -050092 this.mDeviceRuntimeService = deviceRuntimeService;
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -040093 }
94
95 @Override
Adrien Béraudace37a22018-06-22 14:58:36 -040096 public void bindView(ConversationView view) {
97 super.bindView(view);
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -040098 mCompositeDisposable.add(mVisibilityDisposable);
99 if (mConversationDisposable == null && mConversation != null)
100 initView(mConversation, view);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400101 }
102
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500103 public void init(Uri contactRingId, String accountId) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400104 Log.w(TAG, "init " + contactRingId + " " + accountId);
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500105 mContactUri = contactRingId;
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500106 mAccountId = accountId;
Adrien Béraude5ec8952018-07-11 15:14:44 -0400107 Account account = mAccountService.getAccount(accountId);
Adrien Béraud9c166312019-10-25 14:24:15 -0400108 if (account != null) {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400109 initContact(account, contactRingId, getView());
Adrien Béraud9c166312019-10-25 14:24:15 -0400110 mCompositeDisposable.add(mConversationFacade.loadConversationHistory(account, contactRingId)
111 .observeOn(mUiScheduler)
112 .subscribe(this::setConversation, e -> getView().goToHome()));
113 } else {
114 getView().goToHome();
115 }
Amirhossein5ee9d412020-04-04 13:44:52 -0400116
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éraudace37a22018-06-22 14:58:36 -0400131 }
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500132
Adrien Béraudace37a22018-06-22 14:58:36 -0400133 private void setConversation(final Conversation conversation) {
134 if (conversation == null || mConversation == conversation)
135 return;
136 mConversation = conversation;
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400137 mConversationSubject.onNext(conversation);
138 ConversationView view = getView();
139 if (view != null)
140 initView(conversation, view);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400141 }
142
143 public void pause() {
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400144 mVisibilityDisposable.clear();
Adrien Béraudace37a22018-06-22 14:58:36 -0400145 if (mConversation != null) {
Adrien Béraud64538722018-03-15 17:34:00 -0400146 mConversation.setVisible(false);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400147 }
148 }
149
150 public void resume() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500151 Log.w(TAG, "resume " + mConversation + " " + mAccountId + " " + mContactUri);
Adrien Béraud7aa7a9e2018-06-29 19:50:32 -0400152 mVisibilityDisposable.clear();
Adrien Béraude5ec8952018-07-11 15:14:44 -0400153 mVisibilityDisposable.add(mConversationSubject
154 .firstOrError()
155 .subscribe(conversation -> {
156 conversation.setVisible(true);
Adrien Béraud4a643052019-11-18 12:41:23 -0500157 updateOngoingCallView(conversation);
Adrien Béraude5ec8952018-07-11 15:14:44 -0400158 mConversationFacade.readMessages(mAccountService.getAccount(mAccountId), conversation);
Rayan Osseiran6f415662019-10-25 14:23:25 -0400159 }, e -> Log.e(TAG, "Error loading conversation", e)));
Adrien Béraudace37a22018-06-22 14:58:36 -0400160 }
161
Rayan Osseiran6f415662019-10-25 14:23:25 -0400162 private CallContact initContact(final Account account, final Uri uri,
163 final ConversationView view) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400164 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éraudbf81ead2019-06-29 00:16:43 -0400170 TrustRequest req = account.getRequest(uri);
Adrien Béraudace37a22018-06-22 14:58:36 -0400171 if (req == null) {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400172 view.switchToUnknownView(contact.getRingUsername());
Adrien Béraudace37a22018-06-22 14:58:36 -0400173 } else {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400174 view.switchToIncomingTrustRequestView(req.getDisplayname());
Adrien Béraudace37a22018-06-22 14:58:36 -0400175 }
176 } else {
Adrien Béraude5ec8952018-07-11 15:14:44 -0400177 view.switchToConversationView();
Adrien Béraudace37a22018-06-22 14:58:36 -0400178 }
179 Log.w(TAG, "initContact " + contact.getUsername());
180 if (contact.getUsername() == null) {
181 mAccountService.lookupAddress(mAccountId, "", rawId);
182 }
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500183 } else {
Adrien Béraudace37a22018-06-22 14:58:36 -0400184 contact = mContactService.findContact(account, uri);
Adrien Béraude5ec8952018-07-11 15:14:44 -0400185 view.switchToConversationView();
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500186 }
Adrien Béraud78ae7b92018-08-25 19:04:17 -0400187 view.displayContact(contact);
Adrien Béraudace37a22018-06-22 14:58:36 -0400188 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éraudace37a22018-06-22 14:58:36 -0400201
Rayan Osseiran6f415662019-10-25 14:23:25 -0400202
Adrien Béraudace37a22018-06-22 14:58:36 -0400203 mConversationDisposable.add(c.getSortedHistory()
Adrien Béraudf2c76ed2019-05-25 03:36:48 -0400204 .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update element", e)));
Adrien Bérauda084cd12018-12-31 12:49:12 -0500205 mConversationDisposable.add(c.getCleared()
Adrien Béraud08eb45e2019-02-18 01:58:12 -0500206 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400207 .subscribe(view::refreshView, e -> Log.e(TAG, "Can't update elements", e)));
Adrien Béraud9ec82442019-02-18 01:55:16 -0500208 mConversationDisposable.add(mContactService.getLoadedContact(c.getAccountId(), c.getContact())
Adrien Béraudace37a22018-06-22 14:58:36 -0400209 .observeOn(mUiScheduler)
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500210 .subscribe(contact -> initContact(account, mContactUri, view), e -> Log.e(TAG, "Can't get contact", e)));
Adrien Béraudace37a22018-06-22 14:58:36 -0400211 mConversationDisposable.add(c.getUpdatedElements()
212 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400213 .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éraudfd458ea2020-02-28 13:40:18 -0500226 mConversationDisposable.add(c.getComposingStatus()
227 .observeOn(mUiScheduler)
228 .subscribe(view::setComposingStatus));
Adrien Béraud263cd5c2020-03-13 13:36:57 -0400229 mConversationDisposable.add(c.getLastDisplayed()
230 .observeOn(mUiScheduler)
231 .subscribe(view::setLastDisplayed));
Adrien Béraudace37a22018-06-22 14:58:36 -0400232 mConversationDisposable.add(c.getCalls()
233 .observeOn(mUiScheduler)
Adrien Béraud4a643052019-11-18 12:41:23 -0500234 .subscribe(calls -> updateOngoingCallView(mConversation), e -> Log.e(TAG, "Can't update call view", e)));
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500235 mConversationDisposable.add(c.getColor()
236 .observeOn(mUiScheduler)
Rayan Osseiran6f415662019-10-25 14:23:25 -0400237 .subscribe(view::setConversationColor, e -> Log.e(TAG, "Can't update conversation color", e)));
Adrien Béraud5477ce82020-02-24 11:13:54 -0500238
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 Sousaec95e5e2017-03-21 15:28:23 -0400247 }
248
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500249 public void openContact() {
Adrien Béraud91f88742019-09-09 00:46:46 -0400250 if (mConversation != null)
251 getView().goToContactActivity(mAccountId, mConversation.getContact().getPrimaryNumber());
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400252 }
253
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500254 public void sendTextMessage(String message) {
Adrien Béraud91f88742019-09-09 00:46:46 -0400255 if (StringUtils.isEmpty(message) || mConversation == null) {
Adrien Béraudace37a22018-06-22 14:58:36 -0400256 return;
257 }
258 Conference conference = mConversation.getCurrentCall();
259 if (conference == null || !conference.isOnGoing()) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500260 mConversationFacade.sendTextMessage(mAccountId, mConversation, mContactUri, message).subscribe();
Adrien Béraudace37a22018-06-22 14:58:36 -0400261 } else {
262 mConversationFacade.sendTextMessage(mConversation, conference, message);
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400263 }
264 }
265
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500266 public void selectFile() {
267 getView().openFilePicker();
268 }
269
Adrien Béraud64538722018-03-15 17:34:00 -0400270 public void sendFile(File file) {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500271 mConversationFacade.sendFile(mAccountId, mContactUri, file).subscribe();
Pierre Duchemine0c3a492018-02-01 16:22:45 -0500272 }
273
amine younes7c56f312019-06-10 11:34:25 -0400274 /**
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 Osseiran6f415662019-10-25 14:23:25 -0400277 *
278 * @param interaction an interaction representing a datat transfer
amine younes7c56f312019-06-10 11:34:25 -0400279 */
Rayan Osseiran6f415662019-10-25 14:23:25 -0400280 public void saveFile(Interaction interaction) {
281 DataTransfer transfer = (DataTransfer) interaction;
282 String fileAbsolutePath = getDeviceRuntimeService().
amine younes7c56f312019-06-10 11:34:25 -0400283 getConversationPath(transfer.getPeerId(), transfer.getStoragePath())
Rayan Osseiran6f415662019-10-25 14:23:25 -0400284 .getAbsolutePath();
285 getView().startSaveFile(transfer, fileAbsolutePath);
Adrien Béraud7c505112018-03-20 16:03:28 -0400286 }
287
Rayan Osseiran6f415662019-10-25 14:23:25 -0400288 public void shareFile(Interaction interaction) {
289 DataTransfer file = (DataTransfer) interaction;
Adrien Béraudfcf457f2018-04-03 17:46:34 -0400290 File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
291 getView().shareFile(path);
292 }
293
Rayan Osseiran6f415662019-10-25 14:23:25 -0400294 public void openFile(Interaction interaction) {
295 DataTransfer file = (DataTransfer) interaction;
Adrien Béraudb2b3f442018-12-01 17:42:38 -0500296 File path = getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
297 getView().openFile(path);
298 }
299
Rayan Osseiran6f415662019-10-25 14:23:25 -0400300 public void deleteConversationItem(Interaction element) {
Rayan Osseirane634a562019-05-29 13:44:55 -0400301 mConversationFacade.deleteConversationItem(element);
302 }
303
Rayan Osseiran6f415662019-10-25 14:23:25 -0400304 public void cancelMessage(Interaction message) {
Rayan Osseirane634a562019-05-29 13:44:55 -0400305 mConversationFacade.cancelMessage(message);
Adrien Béraud7c505112018-03-20 16:03:28 -0400306 }
307
Adrien Béraud4a643052019-11-18 12:41:23 -0500308 private void sendTrustRequest() {
Adrien Béraud0acf5a12018-08-02 13:40:40 -0400309 final String accountId = mAccountId;
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500310 final Uri contactId = mContactUri;
Adrien Béraudbdfb5e12019-02-18 15:46:44 -0500311 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 Sousaec95e5e2017-03-21 15:28:23 -0400322 }
323
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400324 public void clickOnGoingPane() {
Adrien Beraud4f644382017-07-21 17:01:51 -0400325 Conference conf = mConversation.getCurrentCall();
326 if (conf != null) {
327 getView().goToCallActivity(conf.getId());
328 } else {
Hadrien De Sousa0dc83162017-11-10 16:15:18 -0500329 getView().displayOnGoingCallPane(false);
Adrien Beraud4f644382017-07-21 17:01:51 -0400330 }
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400331 }
332
Adrien Béraud4a643052019-11-18 12:41:23 -0500333 public void goToCall(boolean audioOnly) {
Adrien Béraudd3bf4e42018-02-14 14:44:41 +0100334 if (audioOnly && !mHardwareService.hasMicrophone()) {
Adrien Bérauda0226ff2019-11-21 15:24:42 -0500335 getView().displayErrorToast(Error.NO_MICROPHONE);
Hadrien De Sousa45fb21b2017-12-14 11:06:48 -0500336 return;
337 }
338
Adrien Béraud4a643052019-11-18 12:41:23 -0500339 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éraudfd458ea2020-02-28 13:40:18 -0500351 view.goToCallActivityWithResult(mAccountId, mContactUri.getRawUriString(), audioOnly);
Adrien Béraud4a643052019-11-18 12:41:23 -0500352 }
353 }
354 }));
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400355 }
356
Adrien Béraud4a643052019-11-18 12:41:23 -0500357 private void updateOngoingCallView(Conversation conversation) {
358 Conference conf = conversation == null ? null : conversation.getCurrentCall();
Rayan Osseiran6f415662019-10-25 14:23:25 -0400359 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 -0500360 getView().displayOnGoingCallPane(true);
361 } else {
362 getView().displayOnGoingCallPane(false);
363 }
Hadrien De Sousaec95e5e2017-03-21 15:28:23 -0400364 }
365
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500366 public void onBlockIncomingContactRequest() {
367 String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId;
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500368 mConversationFacade.discardRequest(accountId, mContactUri);
369 mAccountService.removeContact(accountId, mContactUri.getHost(), true);
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500370
371 getView().goToHome();
372 }
373
374 public void onRefuseIncomingContactRequest() {
375 String accountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId;
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500376
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500377 mConversationFacade.discardRequest(accountId, mContactUri);
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500378 getView().goToHome();
379 }
380
381 public void onAcceptIncomingContactRequest() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500382 mConversationFacade.acceptRequest(mAccountId, mContactUri);
Adrien Béraudace37a22018-06-22 14:58:36 -0400383 getView().switchToConversationView();
384 }
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500385
Adrien Béraudace37a22018-06-22 14:58:36 -0400386 public void onAddContact() {
387 sendTrustRequest();
Pierre Duchemin1fa61922018-01-18 10:09:02 -0500388 getView().switchToConversationView();
389 }
390
Pierre Duchemin4af6b392018-02-02 11:23:56 -0500391 public DeviceRuntimeService getDeviceRuntimeService() {
392 return mDeviceRuntimeService;
393 }
Pierre Duchemindf6cb5a2018-02-09 18:05:21 -0500394
395 public void noSpaceLeft() {
396 Log.e(TAG, "configureForFileInfoTextMessage: no space left on device");
Adrien Bérauda0226ff2019-11-21 15:24:42 -0500397 getView().displayErrorToast(Error.NO_SPACE_LEFT);
Pierre Duchemindf6cb5a2018-02-09 18:05:21 -0500398 }
Adrien Béraud0f3ee3d2018-12-08 22:03:54 -0500399
400 public void setConversationColor(int color) {
401 mCompositeDisposable.add(mConversationSubject
402 .firstElement()
403 .subscribe(conversation -> conversation.setColor(color)));
404 }
Rayan Osseiran38206c62019-05-15 14:49:03 -0400405
406 public void cameraPermissionChanged(boolean isGranted) {
407 if (isGranted && mHardwareService.isVideoAvailable()) {
Adrien Béraud99931dd2019-08-27 16:52:01 -0400408 mHardwareService.initVideo().subscribe();
Rayan Osseiran38206c62019-05-15 14:49:03 -0400409 }
410 }
411
Adrien Béraud5477ce82020-02-24 11:13:54 -0500412 public void shareLocation() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500413 getView().startShareLocation(mAccountId, mContactUri.getUri());
Adrien Béraud5477ce82020-02-24 11:13:54 -0500414 }
415
416 public Tuple<String, String> getPath() {
Adrien Béraudfd458ea2020-02-28 13:40:18 -0500417 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éraud5477ce82020-02-24 11:13:54 -0500425 }
Adrien Béraude32ab742018-08-25 21:15:08 -0400426}