Search in sources :

Example 1 with RealmMessageRepository

use of chat.rocket.persistence.realm.repositories.RealmMessageRepository 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 RealmMessageRepository

use of chat.rocket.persistence.realm.repositories.RealmMessageRepository in project Rocket.Chat.Android by RocketChat.

the class RoomFragment method setupMessageComposer.

private void setupMessageComposer() {
    final MessageFormLayout messageFormLayout = (MessageFormLayout) rootView.findViewById(R.id.message_composer);
    messageFormManager = new MessageFormManager(messageFormLayout, this::showExtraActionSelectionDialog);
    messageFormManager.setSendMessageCallback(this::sendMessage);
    messageFormLayout.setEditTextCommitContentListener(this::onCommitContent);
    autocompleteManager = new AutocompleteManager((ViewGroup) rootView.findViewById(R.id.message_list_root));
    autocompleteManager.registerSource(new ChannelSource(new AutocompleteChannelInteractor(roomRepository, new RealmSpotlightRoomRepository(hostname), new DeafultTempSpotlightRoomCaller(methodCallHelper)), AndroidSchedulers.from(BackgroundLooper.get()), AndroidSchedulers.mainThread()));
    Disposable disposable = Single.zip(absoluteUrlHelper.getRocketChatAbsoluteUrl(), roomRepository.getById(roomId).first(Optional.absent()), Pair::create).subscribe(pair -> {
        if (pair.first.isPresent() && pair.second.isPresent()) {
            autocompleteManager.registerSource(new UserSource(new AutocompleteUserInteractor(pair.second.get(), userRepository, new RealmMessageRepository(hostname), new RealmSpotlightUserRepository(hostname), new DefaultTempSpotlightUserCaller(methodCallHelper)), pair.first.get(), RocketChatUserStatusProvider.getInstance(), AndroidSchedulers.from(BackgroundLooper.get()), AndroidSchedulers.mainThread()));
        }
    }, throwable -> {
    });
    compositeDisposable.add(disposable);
    autocompleteManager.bindTo(messageFormLayout.getEditText(), messageFormLayout);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RealmSpotlightRoomRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository) AutocompleteChannelInteractor(chat.rocket.core.interactors.AutocompleteChannelInteractor) ViewGroup(android.view.ViewGroup) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) MessageFormLayout(chat.rocket.android.widget.message.MessageFormLayout) AutocompleteUserInteractor(chat.rocket.core.interactors.AutocompleteUserInteractor) RealmSpotlightUserRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository) DefaultTempSpotlightUserCaller(chat.rocket.android.service.temp.DefaultTempSpotlightUserCaller) MessageFormManager(chat.rocket.android.layouthelper.chatroom.MessageFormManager) UserSource(chat.rocket.android.widget.message.autocomplete.user.UserSource) DeafultTempSpotlightRoomCaller(chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller) AutocompleteManager(chat.rocket.android.widget.message.autocomplete.AutocompleteManager) ChannelSource(chat.rocket.android.widget.message.autocomplete.channel.ChannelSource)

Example 3 with RealmMessageRepository

use of chat.rocket.persistence.realm.repositories.RealmMessageRepository 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)

Example 4 with RealmMessageRepository

use of chat.rocket.persistence.realm.repositories.RealmMessageRepository in project Rocket.Chat.Android by RocketChat.

the class RoomFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    hostname = args.getString(HOSTNAME);
    roomId = args.getString(ROOM_ID);
    roomRepository = new RealmRoomRepository(hostname);
    MessageInteractor messageInteractor = new MessageInteractor(new RealmMessageRepository(hostname), roomRepository);
    userRepository = new RealmUserRepository(hostname);
    absoluteUrlHelper = new AbsoluteUrlHelper(hostname, new RealmServerInfoRepository(), userRepository, new SessionInteractor(new RealmSessionRepository(hostname)));
    methodCallHelper = new MethodCallHelper(getContext(), hostname);
    presenter = new RoomPresenter(roomId, userRepository, messageInteractor, roomRepository, absoluteUrlHelper, methodCallHelper, ConnectivityManager.getInstance(getContext()));
    if (savedInstanceState == null) {
        presenter.loadMessages();
    }
}
Also used : SessionInteractor(chat.rocket.core.interactors.SessionInteractor) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) RealmSessionRepository(chat.rocket.persistence.realm.repositories.RealmSessionRepository) MessageInteractor(chat.rocket.core.interactors.MessageInteractor) Bundle(android.os.Bundle) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmServerInfoRepository(chat.rocket.persistence.realm.repositories.RealmServerInfoRepository) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository)

Aggregations

RealmMessageRepository (chat.rocket.persistence.realm.repositories.RealmMessageRepository)4 RealmRoomRepository (chat.rocket.persistence.realm.repositories.RealmRoomRepository)3 Bundle (android.os.Bundle)2 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 RealmPermissionRepository (chat.rocket.persistence.realm.repositories.RealmPermissionRepository)2 RealmPublicSettingRepository (chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository)2 RealmRoomRoleRepository (chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository)2 RealmUserRepository (chat.rocket.persistence.realm.repositories.RealmUserRepository)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1