Commit f19c9522 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add quote message action

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