use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class HelperUrl method goToActivity.
private static void goToActivity(FragmentActivity activity, final long roomId, final long peerId, ChatEntry chatEntry, final long messageId) {
switch(chatEntry) {
case chat:
if (roomId != FragmentChat.lastChatRoomId) {
DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {
@Override
public void doTask(Realm realm) {
final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
if (realmRoom != null) {
new GoToChatActivity(realmRoom.getId()).setMessageID(messageId).startActivity(activity);
} else {
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
DbManager.getInstance().doRealmTransaction(realm2 -> {
if (realm2.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm2);
realmRoom1.setDeleted(true);
} else {
RealmRoom.putOrUpdate(room, realm2);
}
});
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
G.onChatGetRoom = null;
}
}, 500);
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(peerId);
}
}
});
}
break;
case profile:
G.handler.post(new Runnable() {
@Override
public void run() {
FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
Bundle bundle = new Bundle();
bundle.putLong("peerId", peerId);
bundle.putLong("RoomId", roomId);
bundle.putString("enterFrom", GROUP.toString());
contactsProfile.setArguments(bundle);
new HelperFragment(activity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
}
});
break;
}
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class HelperUrl method goToActivityFromFCM.
public static void goToActivityFromFCM(FragmentActivity activity, final long roomId, final long peerId) {
if (roomId != FragmentChat.lastChatRoomId) {
DbManager.getInstance().doRealmTask(realm -> {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomId).findFirst();
if (realmRoom != null) {
// room with given roomID exists.
new GoToChatActivity(realmRoom.getId()).startActivity(activity);
} else if (peerId > 0) {
realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
if (realmRoom != null) {
new GoToChatActivity(realmRoom.getId()).startActivity(activity);
} else {
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {
@Override
public void doTask(Realm realm1) {
realm1.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
if (realm.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm);
realmRoom1.setDeleted(true);
} else {
RealmRoom.putOrUpdate(room, realm);
}
}
});
}
});
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
G.onChatGetRoom = null;
}
}, 500);
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(peerId);
}
} else {
G.onClientGetRoomResponse = new OnClientGetRoomResponse() {
@Override
public void onClientGetRoomResponse(ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
G.onClientGetRoomResponse = null;
G.handler.postDelayed(() -> {
new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
G.onChatGetRoom = null;
}, 500);
}
@Override
public void onError(int majorCode, int minorCode) {
}
@Override
public void onTimeOut() {
}
};
new RequestClientGetRoom().clientGetRoom(roomId, null);
Toast.makeText(activity, "Please Wait...", Toast.LENGTH_SHORT).show();
}
});
}
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class HelperLogMessage method gotToUserRoom.
private static void gotToUserRoom(final long id) {
DbManager.getInstance().doRealmTask(realm -> {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", id).findFirst();
if (realmRoom != null) {
// Intent intent = new Intent(G.currentActivity, ActivityChat.class);
// intent.putExtra("RoomId", realmRoom.getId());
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// G.currentActivity.startActivity(intent);
// Intent intent = new Intent(G.context, ActivityContactsProfile.class);
// intent.putExtra("peerId", id);
// intent.putExtra("RoomId", realmRoom.getId());
// intent.putExtra("enterFrom", "GROUP");
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// G.currentActivity.startActivity(intent);
FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
Bundle bundle = new Bundle();
bundle.putLong("peerId", id);
bundle.putLong("RoomId", realmRoom.getId());
bundle.putString("enterFrom", "GROUP");
contactsProfile.setArguments(bundle);
// ToDo:fixed it and change to do not use G.currentActivity
new HelperFragment(G.currentActivity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
} else {
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
G.handler.post(new Runnable() {
@Override
public void run() {
FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
Bundle bundle = new Bundle();
bundle.putLong("peerId", id);
bundle.putLong("RoomId", room.getId());
bundle.putString("enterFrom", "GROUP");
contactsProfile.setArguments(bundle);
// ToDo:fixed it and change to do not use G.currentActivity
new HelperFragment(G.currentActivity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
G.onChatGetRoom = null;
}
});
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(id);
}
});
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class BotInit method checkDrIgap.
public static void checkDrIgap() {
if (!BotInit.getCheckDrIgap())
return;
new RequestClientGetPromote().getPromote();
G.ipromote = new Ipromote() {
@Override
public void onGetPromoteResponse(ProtoClientGetPromote.ClientGetPromoteResponse.Builder builder) {
setCheckDrIgap(false);
ArrayList<Long> promoteIds = new ArrayList<>();
for (int i = 0; i < builder.getPromoteList().size(); i++) promoteIds.add(builder.getPromoteList().get(i).getId());
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<RealmRoom> roomList = realm.where(RealmRoom.class).equalTo("isFromPromote", true).findAll();
for (RealmRoom room : roomList) {
if (!promoteIds.contains(room.getPromoteId())) {
room.setFromPromote(false);
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), false);
}
}
}
});
for (int i = builder.getPromoteList().size() - 1; i >= 0; i--) {
ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type TYPE = builder.getPromoteList().get(i).getType();
RealmRoom realmRoom;
if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
} else {
realmRoom = realm.where(RealmRoom.class).equalTo("id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
}
if (realmRoom == null) {
if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
// RealmRoom.setPromote(builder.getPromoteList().get(i).getId(), TYPE);
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
G.onChatGetRoom = null;
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm1);
realmRoom1.setFromPromote(true);
realmRoom1.setPromoteId(realmRoom1.getChatRoom().getPeerId());
// RealmRoom.setPromote(2297310L, ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER);
});
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), true);
ActivityPopUpNotification.sendMessage("/start", room.getId(), ProtoGlobal.Room.Type.CHAT);
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(builder.getPromoteList().get(i).getId());
} else {
new RequestClientGetRoom().clientGetRoom(builder.getPromoteList().get(i).getId(), RequestClientGetRoom.CreateRoomMode.getPromote);
}
} else {
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(realmRoom.getId(), true);
}
}
});
}
};
}
use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.
the class FragmentChat method forwardToChatRoom.
private void forwardToChatRoom(final ArrayList<StructBottomSheetForward> forwardList, boolean isMessage) {
if (forwardList != null && forwardList.size() > 0) {
final int[] count = { 0 };
for (int i = 0; i < forwardList.size(); i++) {
new RequestChatGetRoom().chatGetRoom(forwardList.get(i).getId(), new RequestChatGetRoom.OnChatRoomReady() {
@Override
public void onReady(ProtoGlobal.Room room) {
if (!multiForwardList.contains(room.getId())) {
multiForwardList.add(room.getId());
RealmRoom.putOrUpdate(room);
}
count[0]++;
if (count[0] >= forwardList.size()) {
G.handler.post(new Runnable() {
@Override
public void run() {
G.refreshRealmUi();
bottomSheetDialogForward.dismiss();
hideProgress();
forwardList.clear();
manageForwardedMessage(isMessage);
}
});
}
}
@Override
public void onError(int major, int minor) {
G.handler.post(new Runnable() {
@Override
public void run() {
bottomSheetDialogForward.dismiss();
hideProgress();
error(G.fragmentActivity.getResources().getString(R.string.faild));
}
});
}
});
}
} else {
manageForwardedMessage(isMessage);
bottomSheetDialogForward.dismiss();
hideProgress();
}
}
Aggregations