e.onNext(new MessageSendProgress(message)); e.onNext(new MessageSendProgress(message, result.progress)); message.update(); e.onNext(new MessageSendProgress(message));
@Override public void onNext(@NonNull MessageSendProgress messageSendProgress) { Timber.d("Message Status: " + messageSendProgress.getStatus()); // It's best not to sort here because then we are just adding the message // to the bottom of the list. We only sort after the message has also been // received from Firebase so the datestamp is also correct if(messageListAdapter.addRow(messageSendProgress.message, false, true, messageSendProgress.uploadProgress)) { scrollListTo(ListPosition.Bottom, false); } }
/** * Preparing a text message, * This is only the build part of the send from here the message will passed to "sendMessage" Method. * From there the message will be uploaded to the server if the upload fails the message will be deleted from the local db. * If the upload is successful we will update the message entity so the entityId given from the server will be saved. * The message will be received before sending in the onMainFinished Callback with a Status that its in the sending process. * When the message is fully sent the status will be changed and the onItem callback will be invoked. * When done or when an error occurred the calling method will be notified. */ public Observable<MessageSendProgress> sendMessageWithText(final String text, final Thread thread) { return Observable.create((ObservableOnSubscribe<MessageSendProgress>) e -> { final Message message = newMessage(MessageType.Text, thread); message.setText(text); e.onNext(new MessageSendProgress(message)); ObservableConnector<MessageSendProgress> connector = new ObservableConnector<>(); connector.connect(implSendMessage(message), e); }).subscribeOn(Schedulers.single()); }
/** * Send a message, * The message need to have a owner thread attached to it or it cant be added. * If the destination thread is public the system will add the user to the message thread if needed. * The uploading to the server part can bee seen her {@see FirebaseCoreAdapter#PushMessageWithComplition}. */ public Observable<MessageSendProgress> sendMessage(final Message message) { return Observable.create(e -> new MessageWrapper(message).send() .subscribeOn(Schedulers.single()) .subscribe(() -> { pushForMessage(message); e.onNext(new MessageSendProgress(message)); e.onComplete(); }, throwable -> e.onError(throwable))); }
message.setValueForKey(imageURL, Keys.MessageThumbnailURL); e.onNext(new MessageSendProgress(message));
/** /* Convenience method to save the message to the database then pass it to the token network adapter * send method so it can be sent via the network */ public Observable<MessageSendProgress> implSendMessage(final Message message) { return Observable.create((ObservableOnSubscribe<MessageSendProgress>) e -> { message.update(); message.getThread().update(); if (ChatSDK.encryption() != null) { ChatSDK.encryption().encrypt(message); } e.onNext(new MessageSendProgress(message)); e.onComplete(); }).concatWith(sendMessage(message)) .subscribeOn(Schedulers.single()).doOnComplete(() -> { message.setMessageStatus(MessageSendStatus.Sent); message.update(); }).doOnError(throwable -> { message.setMessageStatus(MessageSendStatus.Failed); message.update(); }); }