Commit f19c9522 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add quote message action

parent 975bedbd
package chat.rocket.android.fragment.chatroom; package chat.rocket.android.fragment.chatroom;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import java.util.List; import java.util.List;
...@@ -55,11 +56,11 @@ public interface RoomContract { ...@@ -55,11 +56,11 @@ public interface RoomContract {
void sendMessage(String messageText); void sendMessage(String messageText);
void resendMessage(Message message); void resendMessage(@NonNull Message message);
void updateMessage(Message message, String content); void updateMessage(@NonNull Message message, String content);
void deleteMessage(Message message); void deleteMessage(@NonNull Message message);
void onUnreadCount(); void onUnreadCount();
...@@ -67,8 +68,6 @@ public interface RoomContract { ...@@ -67,8 +68,6 @@ public interface RoomContract {
void refreshRoom(); void refreshRoom();
void replyMessage(Message message); void replyMessage(@NonNull Message message, boolean justQuote);
void copyMessage(Message message);
} }
} }
...@@ -666,9 +666,10 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -666,9 +666,10 @@ public class RoomFragment extends AbstractChatRoomFragment implements
Activity context = getActivity(); Activity context = getActivity();
if (context != null && context instanceof MainActivity) { if (context != null && context instanceof MainActivity) {
MessagePopup.take(message) MessagePopup.take(message)
.setReplyAction(presenter::replyMessage) .setReplyAction(msg -> presenter.replyMessage(message, false))
.setEditAction(this::onEditMessage) .setEditAction(this::onEditMessage)
.setCopyAction(msg -> onCopy(message.getMessage())) .setCopyAction(msg -> onCopy(message.getMessage()))
.setQuoteAction(msg -> presenter.replyMessage(message, true))
.showWith(context); .showWith(context);
} }
} }
......
...@@ -123,7 +123,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -123,7 +123,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
} }
@Override @Override
public void replyMessage(Message message) { public void replyMessage(@NonNull Message message, boolean justQuote) {
this.absoluteUrlHelper.getRocketChatAbsoluteUrl() this.absoluteUrlHelper.getRocketChatAbsoluteUrl()
.cache() .cache()
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
...@@ -131,20 +131,16 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -131,20 +131,16 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.subscribe( .subscribe(
serverUrl -> { serverUrl -> {
if (serverUrl.isPresent()) { if (serverUrl.isPresent()) {
String baseUrl = serverUrl.get().getBaseUrl(); RocketChatAbsoluteUrl absoluteUrl = serverUrl.get();
view.onReply(serverUrl.get(), buildReplyMarkDown(baseUrl, message), message); String baseUrl = absoluteUrl.getBaseUrl();
view.onReply(absoluteUrl, buildReplyOrQuoteMarkdown(baseUrl, message, justQuote), message);
} }
}, },
Logger::report Logger::report
); );
} }
@Override private String buildReplyOrQuoteMarkdown(String baseUrl, Message message, boolean justQuote) {
public void copyMessage(Message message) {
view.onCopy(message.getMessage());
}
private String buildReplyMarkDown(String baseUrl, Message message) {
if (currentRoom == null || message.getUser() == null) { if (currentRoom == null || message.getUser() == null) {
return ""; return "";
} }
...@@ -154,10 +150,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -154,10 +150,10 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
message.getUser().getUsername(), message.getUser().getUsername(),
message.getId()); message.getId());
} else { } else {
return String.format("[ ](%s/channel/%s?msg=%s) @%s ", baseUrl, return String.format("[ ](%s/channel/%s?msg=%s) %s", baseUrl,
currentRoom.getName(), currentRoom.getName(),
message.getId(), message.getId(),
message.getUser().getUsername()); justQuote ? "" : "@" + message.getUser().getUsername() + " ");
} }
} }
...@@ -185,7 +181,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -185,7 +181,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
} }
@Override @Override
public void resendMessage(Message message) { public void resendMessage(@NonNull Message message) {
final Disposable subscription = getCurrentUser() final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.resend(message, user)) .flatMap(user -> messageInteractor.resend(message, user))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
...@@ -196,7 +192,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -196,7 +192,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
} }
@Override @Override
public void updateMessage(Message message, String content) { public void updateMessage(@NonNull Message message, String content) {
view.disableMessageInput(); view.disableMessageInput();
final Disposable subscription = getCurrentUser() final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.update(message, user, content)) .flatMap(user -> messageInteractor.update(message, user, content))
...@@ -219,7 +215,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -219,7 +215,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
} }
@Override @Override
public void deleteMessage(Message message) { public void deleteMessage(@NonNull Message message) {
final Disposable subscription = messageInteractor.delete(message) final Disposable subscription = messageInteractor.delete(message)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
...@@ -9,7 +9,6 @@ import java.util.ArrayList; ...@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.RocketChatApplication;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.helper.Logger; import chat.rocket.android.helper.Logger;
import chat.rocket.core.interactors.EditMessageInteractor; import chat.rocket.core.interactors.EditMessageInteractor;
...@@ -35,9 +34,10 @@ import io.reactivex.disposables.Disposable; ...@@ -35,9 +34,10 @@ import io.reactivex.disposables.Disposable;
public class MessagePopup { public class MessagePopup {
private static volatile MessagePopup singleton = null; private static volatile MessagePopup singleton = null;
private static final Action REPLY_ACTION_INFO = new Action("Reply", null, true); private static final Action REPLY_ACTION_INFO = new Action("Reply", null, true);
private static final Action QUOTE_ACTION_INFO = new Action("Quote", null, true);
private static final Action EDIT_ACTION_INFO = new Action("Edit", null, true); private static final Action EDIT_ACTION_INFO = new Action("Edit", null, true);
private static final Action COPY_ACTION_INFO = new Action("Copy", null, true); private static final Action COPY_ACTION_INFO = new Action("Copy", null, true);
private final List<Action> defaultActions = new ArrayList<>(3); private final List<Action> defaultActions = new ArrayList<>(4);
private final List<Action> otherActions = new ArrayList<>(); private final List<Action> otherActions = new ArrayList<>();
private Message message; private Message message;
private CompositeDisposable compositeDisposable = new CompositeDisposable(); private CompositeDisposable compositeDisposable = new CompositeDisposable();
...@@ -47,7 +47,7 @@ public class MessagePopup { ...@@ -47,7 +47,7 @@ public class MessagePopup {
} }
private void showAvailableActionsOnly(Context context) { private void showAvailableActionsOnly(Context context) {
RocketChatCache cache = new RocketChatCache(RocketChatApplication.getInstance()); RocketChatCache cache = new RocketChatCache(context.getApplicationContext());
String hostname = cache.getSelectedServerHostname(); String hostname = cache.getSelectedServerHostname();
...@@ -107,6 +107,7 @@ public class MessagePopup { ...@@ -107,6 +107,7 @@ public class MessagePopup {
private void addDefaultActions() { private void addDefaultActions() {
singleton.defaultActions.add(REPLY_ACTION_INFO); singleton.defaultActions.add(REPLY_ACTION_INFO);
singleton.defaultActions.add(QUOTE_ACTION_INFO);
singleton.defaultActions.add(EDIT_ACTION_INFO); singleton.defaultActions.add(EDIT_ACTION_INFO);
singleton.defaultActions.add(COPY_ACTION_INFO); singleton.defaultActions.add(COPY_ACTION_INFO);
} }
...@@ -148,17 +149,22 @@ public class MessagePopup { ...@@ -148,17 +149,22 @@ public class MessagePopup {
} }
public MessagePopup setReplyAction(ActionListener actionListener) { public MessagePopup setReplyAction(ActionListener actionListener) {
REPLY_ACTION_INFO.actionListener= actionListener; REPLY_ACTION_INFO.actionListener = actionListener;
return singleton; return singleton;
} }
public MessagePopup setEditAction(ActionListener actionListener) { public MessagePopup setEditAction(ActionListener actionListener) {
EDIT_ACTION_INFO.actionListener= actionListener; EDIT_ACTION_INFO.actionListener = actionListener;
return singleton; return singleton;
} }
public MessagePopup setCopyAction(ActionListener actionListener) { public MessagePopup setCopyAction(ActionListener actionListener) {
COPY_ACTION_INFO.actionListener= actionListener; COPY_ACTION_INFO.actionListener = actionListener;
return singleton;
}
public MessagePopup setQuoteAction(ActionListener actionListener) {
QUOTE_ACTION_INFO.actionListener = actionListener;
return singleton; return singleton;
} }
...@@ -192,6 +198,7 @@ public class MessagePopup { ...@@ -192,6 +198,7 @@ public class MessagePopup {
private static class Builder { private static class Builder {
private final Message message; private final Message message;
Builder(Message message) { Builder(Message message) {
if (message == null) { if (message == null) {
throw new IllegalArgumentException("Message must not be null"); throw new IllegalArgumentException("Message must not be null");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment