Search in sources :

Example 1 with EditMessageInteractor

use of chat.rocket.core.interactors.EditMessageInteractor in project Rocket.Chat.Android by RocketChat.

the class MessageOptionsDialogFragment method setUpDialog.

private void setUpDialog(final BottomSheetDialog bottomSheetDialog, String messageId) {
    RocketChatCache cache = new RocketChatCache(bottomSheetDialog.getContext());
    String hostname = cache.getSelectedServerHostname();
    EditMessageInteractor editMessageInteractor = getEditMessageInteractor(hostname);
    MessageRepository messageRepository = new RealmMessageRepository(hostname);
    Disposable disposable = messageRepository.getById(messageId).flatMap(it -> {
        if (!it.isPresent()) {
            return Single.just(Pair.<Message, Boolean>create(null, false));
        }
        Message message = it.get();
        return Single.zip(Single.just(message), editMessageInteractor.isAllowed(message), Pair::create);
    }).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(pair -> {
        if (pair.second) {
            bottomSheetDialog.findViewById(R.id.message_options_info).setVisibility(View.GONE);
            View editView = bottomSheetDialog.findViewById(R.id.message_options_edit_action);
            editView.setVisibility(View.VISIBLE);
            editView.setOnClickListener(view -> internalListener.onEdit(pair.first));
        } else {
            ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_permissions_info);
        }
    }, throwable -> {
        ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_message_info);
        Logger.report(throwable);
    });
    compositeDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) MessageRepository(chat.rocket.core.repositories.MessageRepository) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) RealmPublicSettingRepository(chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository) Bundle(android.os.Bundle) UserRepository(chat.rocket.core.repositories.UserRepository) RocketChatCache(chat.rocket.android.RocketChatCache) RoomRepository(chat.rocket.core.repositories.RoomRepository) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RealmRoomRoleRepository(chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository) PermissionRepository(chat.rocket.core.repositories.PermissionRepository) PublicSettingRepository(chat.rocket.core.repositories.PublicSettingRepository) PermissionInteractor(chat.rocket.core.interactors.PermissionInteractor) View(android.view.View) RoomRoleRepository(chat.rocket.core.repositories.RoomRoleRepository) R(chat.rocket.android.R) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) BottomSheetDialogFragment(android.support.design.widget.BottomSheetDialogFragment) DialogInterface(android.content.DialogInterface) Logger(chat.rocket.android.helper.Logger) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) Message(chat.rocket.core.models.Message) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Pair(android.support.v4.util.Pair) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository) BackgroundLooper(chat.rocket.android.BackgroundLooper) RealmPermissionRepository(chat.rocket.persistence.realm.repositories.RealmPermissionRepository) Message(chat.rocket.core.models.Message) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) RocketChatCache(chat.rocket.android.RocketChatCache) MessageRepository(chat.rocket.core.repositories.MessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Example 2 with EditMessageInteractor

use of chat.rocket.core.interactors.EditMessageInteractor in project Rocket.Chat.Android by RocketChat.

the class MessageOptionsDialogFragment method getEditMessageInteractor.

private EditMessageInteractor getEditMessageInteractor(String hostname) {
    UserRepository userRepository = new RealmUserRepository(hostname);
    RoomRoleRepository roomRoleRepository = new RealmRoomRoleRepository(hostname);
    PermissionRepository permissionRepository = new RealmPermissionRepository(hostname);
    PermissionInteractor permissionInteractor = new PermissionInteractor(userRepository, roomRoleRepository, permissionRepository);
    MessageRepository messageRepository = new RealmMessageRepository(hostname);
    RoomRepository roomRepository = new RealmRoomRepository(hostname);
    PublicSettingRepository publicSettingRepository = new RealmPublicSettingRepository(hostname);
    return new EditMessageInteractor(permissionInteractor, userRepository, messageRepository, roomRepository, publicSettingRepository);
}
Also used : RealmPermissionRepository(chat.rocket.persistence.realm.repositories.RealmPermissionRepository) PermissionInteractor(chat.rocket.core.interactors.PermissionInteractor) PermissionRepository(chat.rocket.core.repositories.PermissionRepository) RealmPermissionRepository(chat.rocket.persistence.realm.repositories.RealmPermissionRepository) RealmPublicSettingRepository(chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository) PublicSettingRepository(chat.rocket.core.repositories.PublicSettingRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmPublicSettingRepository(chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository) UserRepository(chat.rocket.core.repositories.UserRepository) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository) RealmRoomRoleRepository(chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) RealmRoomRoleRepository(chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository) RoomRoleRepository(chat.rocket.core.repositories.RoomRoleRepository) MessageRepository(chat.rocket.core.repositories.MessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) RoomRepository(chat.rocket.core.repositories.RoomRepository) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository)

Aggregations

EditMessageInteractor (chat.rocket.core.interactors.EditMessageInteractor)2 PermissionInteractor (chat.rocket.core.interactors.PermissionInteractor)2 MessageRepository (chat.rocket.core.repositories.MessageRepository)2 PermissionRepository (chat.rocket.core.repositories.PermissionRepository)2 PublicSettingRepository (chat.rocket.core.repositories.PublicSettingRepository)2 RoomRepository (chat.rocket.core.repositories.RoomRepository)2 RoomRoleRepository (chat.rocket.core.repositories.RoomRoleRepository)2 UserRepository (chat.rocket.core.repositories.UserRepository)2 RealmMessageRepository (chat.rocket.persistence.realm.repositories.RealmMessageRepository)2 RealmPermissionRepository (chat.rocket.persistence.realm.repositories.RealmPermissionRepository)2 RealmPublicSettingRepository (chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository)2 RealmRoomRepository (chat.rocket.persistence.realm.repositories.RealmRoomRepository)2 RealmRoomRoleRepository (chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository)2 RealmUserRepository (chat.rocket.persistence.realm.repositories.RealmUserRepository)2 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)1 BottomSheetDialogFragment (android.support.design.widget.BottomSheetDialogFragment)1