use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class UserProfileViewModel method onCloudMessageClick.
public void onCloudMessageClick() {
showLoading.set(View.VISIBLE);
retryRequestTime++;
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
long userId = (userInfo != null && userInfo.getUserId() > 0) ? userInfo.getUserId() : AccountManager.getInstance().getCurrentUser().getId();
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
showLoading.set(View.GONE);
goToChatPage.setValue(new GoToChatModel(realmRoom.getId(), userInfo.getUserId()));
} else {
if (retryRequestTime < 3) {
new RequestChatGetRoom().chatGetRoom((userInfo != null && userInfo.getUserId() > 0) ? userInfo.getUserId() : AccountManager.getInstance().getCurrentUser().getId(), new RequestChatGetRoom.OnChatRoomReady() {
@Override
public void onReady(ProtoGlobal.Room room) {
RealmRoom.putOrUpdate(room);
G.handler.post(() -> {
G.refreshRealmUi();
showLoading.set(View.GONE);
goToChatPage.postValue(new GoToChatModel(room.getId(), userInfo.getUserId()));
});
}
@Override
public void onError(int majorCode, int minorCode) {
if (majorCode == 5 && minorCode == 1) {
G.runOnUiThread(() -> {
showError.postValue(R.string.connection_error);
showLoading.set(View.GONE);
});
} else {
G.runOnUiThread(() -> {
showError.postValue(R.string.error);
showLoading.set(View.GONE);
});
}
}
});
} else {
showLoading.set(View.GONE);
showError.setValue(R.string.error);
retryRequestTime = -1;
}
}
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfileViewModel method onClickGoToChat.
public void onClickGoToChat() {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || enterFrom.equals("Others")) {
// Others is from FragmentMapUsers adapter
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
goToChatPage.setValue(realmRoom.getId());
} else {
new RequestChatGetRoom().chatGetRoom(userId, new RequestChatGetRoom.OnChatRoomReady() {
@Override
public void onReady(ProtoGlobal.Room room) {
DbManager.getInstance().doRealmTransaction(realm -> {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm);
realmRoom1.setDeleted(true);
});
G.handler.post(new Runnable() {
@Override
public void run() {
G.refreshRealmUi();
goToChatPage.setValue(room.getId());
}
});
}
@Override
public void onError(int major, int minor) {
}
});
}
} else {
goBack.setValue(true);
}
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class SearchFragment method goToRoomWithRealm.
public void goToRoomWithRealm(RealmRoom realmRoom, SearchType type, long id, long messageId) {
if (realmRoom != null) {
G.refreshRealmUi();
if (type == SearchType.message) {
new GoToChatActivity(realmRoom.getId()).setMessageID(messageId).startActivity(getActivity());
} else {
new GoToChatActivity(realmRoom.getId()).startActivity(getActivity());
}
} else {
new RequestChatGetRoom().chatGetRoom(id, new RequestChatGetRoom.OnChatRoomReady() {
@Override
public void onReady(ProtoGlobal.Room room) {
G.runOnUiThread(() -> DbManager.getInstance().doRealmTransaction(realm -> {
RealmRoom room2 = RealmRoom.putOrUpdate(room, realm);
room2.setDeleted(true);
}));
if (getActivity() != null && getActivity().getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new GoToChatActivity(room.getId()).setPeerID(id).setMessageID(messageId).startActivity(getActivity());
}
@Override
public void onError(int major, int minor) {
}
});
}
}
Aggregations