use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class FragmentNewGroupViewModel method getRoom.
private void getRoom(final long roomId, final ProtoGlobal.Room.Type typeCreate, boolean isGroup) {
G.onClientGetRoomResponse = new OnClientGetRoomResponse() {
@Override
public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
return;
}
try {
G.handler.post(new Runnable() {
@Override
public void run() {
if (existAvatar) {
showProgressBar();
if (room.getType() == ProtoGlobal.Room.Type.GROUP) {
new RequestGroupAvatarAdd().groupAvatarAdd(roomId, token);
} else {
new RequestChannelAvatarAdd().channelAvatarAdd(roomId, token);
}
} else {
hideProgressBar();
if (isGroup) {
createdRoomId.postValue(roomId);
} else {
goToContactGroupPage.setValue(new ContactGroupFragmentModel(roomId, room.getGroupRoomExtra().getParticipantsCountLimitLabel(), typeCreate.toString(), true));
}
}
}
});
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
@Override
public void onError(int majorCode, int minorCode) {
hideProgressBar();
}
@Override
public void onTimeOut() {
hideProgressBar();
}
};
new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class FragmentNewGroupViewModel method getChannelRoom.
private void getChannelRoom(final long roomId) {
G.onClientGetRoomResponse = new OnClientGetRoomResponse() {
@Override
public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
return;
}
G.onClientGetRoomResponse = null;
G.handler.post(new Runnable() {
@Override
public void run() {
mInviteLink = room.getChannelRoomExtra().getPrivateExtra().getInviteLink();
if (existAvatar) {
MessageController.getInstance(currentAccount).saveChannelAvatar(imagePath, room.getId());
} else {
hideProgressBar();
goToCreateChannelPage.setValue(new CreateChannelModel(room.getId(), mInviteLink, token));
}
}
});
}
@Override
public void onError(int majorCode, int minorCode) {
G.onClientGetRoomResponse = null;
}
@Override
public void onTimeOut() {
G.onClientGetRoomResponse = null;
}
};
new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method updateRoomAddedStory.
public void updateRoomAddedStory(final List<ProtoGlobal.Story> stories) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "updateRoomAddedStory roomId " + stories.get(0).getRoomId() + " storiesId " + stories.get(0).getId());
try {
database.beginTransaction();
RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", stories.get(0).getRoomId()).findFirst();
if (realmRoom != null && realmRoom.getTitle() != null) {
RealmStory realmStory;
if (stories.get(0).getUserId() == AccountManager.getInstance().getCurrentUser().getId()) {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", stories.get(0).getUserId()).findFirst();
} else {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", stories.get(0).getRoomId()).findFirst();
}
if (realmStory == null) {
realmStory = database.createObject(RealmStory.class, SUID.id().get());
}
List<StoryObject> storyObjects = new ArrayList<>();
for (int i = 0; i < stories.size(); i++) {
if (stories.get(i).getTypeValue() == 0) {
StoryObject storyObject = StoryObject.create(stories.get(i), i, realmRoom.getTitle(), realmRoom != null ? realmRoom.getColor() : "#4aca69", true, realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
storyObjects.add(storyObject);
}
}
realmStory.setLastCreatedAt(storyObjects.get(storyObjects.size() - 1).createdAt);
realmStory.setDisplayName(realmRoom.getTitle());
realmStory.setProfileColor(realmRoom.getColor());
realmStory.setSessionId(AccountManager.getInstance().getCurrentUser().getId());
if (stories.get(0).getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
realmStory.setUserId(0);
realmStory.setOrginatorValue(1);
realmStory.setVerified(realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
} else {
realmStory.setUserId(AccountManager.getInstance().getCurrentUser().getId());
}
realmStory.setRoomId(stories.get(0).getRoomId());
realmStory.setSeenAll(false);
realmStory.setRealmStoryProtos(database, storyObjects);
int[] storyUnReadCount = new int[1];
RealmResults<RealmStory> otherStories = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isSeenAll", false).findAll();
if (otherStories != null && otherStories.size() > 0) {
storyUnReadCount[0] = otherStories.size();
} else {
storyUnReadCount[0] = 0;
}
database.commitTransaction();
G.runOnUiThread(() -> {
if (G.onUnreadChange != null) {
G.onUnreadChange.onChange(storyUnReadCount[0], true);
}
getEventManager().postEvent(EventManager.STORY_USER_ADD_NEW);
});
} else {
new RequestClientGetRoom().clientGetRoom(stories.get(0).getRoomId(), RequestClientGetRoom.CreateRoomMode.justInfo);
}
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class HelperUrl method joinToRoom.
private static void joinToRoom(FragmentActivity activity, String token, final ProtoGlobal.Room room) {
if (RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
showIndeterminateProgressDialog(activity);
G.onClientJoinByInviteLink = new OnClientJoinByInviteLink() {
@Override
public void onClientJoinByInviteLinkResponse(long roomId) {
closeDialogWaiting();
new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
if (roomId != FragmentChat.lastChatRoomId) {
new GoToChatActivity(roomId).startActivity(activity);
}
G.onClientJoinByInviteLink = null;
}
@Override
public void onError(int majorCode, int minorCode) {
closeDialogWaiting();
G.onClientJoinByInviteLink = null;
}
};
new RequestClientJoinByInviteLink().clientJoinByInviteLink(token);
} else {
closeDialogWaiting();
HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false);
}
}
use of net.iGap.request.RequestClientGetRoom 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();
}
});
}
}
Aggregations