use of net.iGap.request.RequestSignalingGetConfiguration in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfileViewModel method mainStart.
private void mainStart() {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || roomId == 0) {
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
shearedId = realmRoom.getId();
}
} else {
shearedId = roomId;
}
if (!RealmRoom.isNotificationServices(roomId)) {
isShowReportView.set(true);
} else {
isShowReportView.set(false);
}
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
cloudVisibility.postValue(true);
} else
cloudVisibility.postValue(false);
registeredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, userId);
});
if (registeredInfo != null) {
registeredInfo.addChangeListener((RealmObjectChangeListener<RealmRegisteredInfo>) (realmModel, changeSet) -> {
if (changeSet != null) {
for (int i = 0; i < changeSet.getChangedFields().length; i++) {
if (changeSet.getChangedFields()[i].equals("blockUser")) {
userBlockState.set(realmModel.isBlockUser() ? R.string.un_block_user : R.string.block);
}
}
}
});
isBot = registeredInfo.isBot();
if (isBot || userId == AccountManager.getInstance().getCurrentUser().getId()) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
callVisibility.setValue(View.VISIBLE);
menuVisibility.setValue(View.VISIBLE);
videoCallVisibility.setValue(View.VISIBLE);
}
isBlockUser = registeredInfo.isBlockUser();
userBlockState.set(isBlockUser ? R.string.un_block_user : R.string.block);
registeredInfo.addChangeListener(element -> isBlockUser = registeredInfo.isBlockUser());
DbManager.getInstance().doRealmTask(realm -> {
if (registeredInfo.getLastAvatar(realm) != null) {
String mainFilePath = registeredInfo.getLastAvatar(realm).getFile().getLocalFilePath();
if (mainFilePath != null && new File(mainFilePath).exists()) {
// if main image is exist showing that
avatarPath = mainFilePath;
} else {
avatarPath = registeredInfo.getLastAvatar(realm).getFile().getLocalThumbnailPath();
}
avatarList = registeredInfo.getAvatars(realm);
}
});
}
RealmContacts realmUser = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("id", userId).findFirst();
});
if (registeredInfo != null) {
if (registeredInfo.getDisplayName() != null && !registeredInfo.getDisplayName().equals("")) {
contactName.setValue(registeredInfo.getDisplayName());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
if (registeredInfo.getBio() == null || registeredInfo.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(registeredInfo.getBio());
}
username.set(registeredInfo.getUsername());
phone.set(registeredInfo.getPhoneNumber());
phoneNumber = "+" + registeredInfo.getPhoneNumber();
firstName = registeredInfo.getFirstName();
lastName = registeredInfo.getLastName();
lastSeenValue = registeredInfo.getLastSeen();
color = registeredInfo.getColor();
initials = registeredInfo.getInitials();
userStatus = registeredInfo.getStatus();
isVerified = registeredInfo.isVerified();
} else if (realmUser != null) {
if (realmUser.getDisplay_name() != null && !realmUser.getDisplay_name().equals("")) {
contactName.setValue(realmUser.getDisplay_name());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
username.set(realmUser.getUsername());
phone.set(Long.toString(realmUser.getPhone()));
phoneNumber = "+" + realmUser.getPhone();
firstName = realmUser.getFirst_name();
lastName = realmUser.getLast_name();
lastSeenValue = realmUser.getLast_seen();
color = realmUser.getColor();
initials = realmUser.getInitials();
isVerified = realmUser.isVerified();
if (realmUser.getBio() == null || realmUser.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(realmUser.getBio());
}
}
if (isVerified) {
verifyTextVisibility.set(View.VISIBLE);
} else {
verifyTextVisibility.set(View.INVISIBLE);
}
// todo: fixed it two times check it and first and her
if (userId != 134 && AccountManager.getInstance().getCurrentUser().getId() != userId) {
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (isBot) {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
if (callConfig.isVoice_calling()) {
callVisibility.setValue(View.VISIBLE);
}
if (callConfig.isVideo_calling()) {
videoCallVisibility.setValue(View.VISIBLE);
}
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
} else {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
RealmContacts realmContacts = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("phone", Long.parseLong(phone.get())).findFirst();
});
/**
* if this user isn't in my contacts don't show phone number
*/
if (realmContacts == null && enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString())) {
showNumber.set(false);
disableDeleteContact = true;
menuVisibility.setValue(View.GONE);
}
if (!G.isAppRtl) {
textsGravity.set(Gravity.LEFT);
} else {
textsGravity.set(Gravity.RIGHT);
}
setUserStatus(userStatus, lastSeenValue);
setAvatar.setValue(userId != AccountManager.getInstance().getCurrentUser().getId());
// todo: change it
FragmentShearedMedia.getCountOfSharedMedia(shearedId);
if (registeredInfo == null) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
}
use of net.iGap.request.RequestSignalingGetConfiguration in project iGap-Android by KianIranian-STDG.
the class FragmentChat method startPageFastInitialize.
/**
* set just important item to view in onCreate and load another objects in onResume
* actions : set app color, load avatar, set background, set title, set status chat or member for group or channel
*/
private void startPageFastInitialize() {
Bundle extras = getArguments();
if (extras != null) {
mRoomId = extras.getLong("RoomId");
isGoingFromUserLink = extras.getBoolean("GoingFromUserLink");
isNotJoin = extras.getBoolean("ISNotJoin");
userName = extras.getString("UserName");
messageId = extras.getLong("MessageId");
documentId = extras.getLong("DocumentId");
chatPeerId = extras.getLong("peerId");
}
attachFile = new AttachFile(G.fragmentActivity);
RealmRoom realmRoom = getRoom();
pageSettings();
// avi = (AVLoadingIndicatorView) rootView.findViewById(R.id.avi);
verifiedIcon.setVisibility(View.GONE);
/**
* need this info for load avatar
*/
if (realmRoom != null) {
chatType = realmRoom.getType();
if (chatType == CHAT) {
chatPeerId = realmRoom.getChatRoom().getPeerId();
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
title = realmRegisteredInfo.getDisplayName();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
isBot = realmRegisteredInfo.isBot();
if (isBot) {
if (getMessagesCount() == 0) {
layoutMute.setVisibility(View.VISIBLE);
txtChannelMute.setText(R.string.start);
iconChannelMute.setText("");
View layoutAttach = rootView.findViewById(R.id.layout_attach_file);
layoutAttach.setVisibility(View.GONE);
layoutMute.setOnClickListener(v -> {
if (!isChatReadOnly) {
edtChat.setText("/Start");
imvSendButton.performClick();
removeStartButton();
}
});
isShowStartButton = true;
}
}
if (realmRegisteredInfo.isVerified()) {
verifiedIcon.setVisibility(View.VISIBLE);
}
} else {
/**
* when userStatus isn't EXACTLY lastSeen time not used so don't need
* this time and also this time not exist in room info
*/
title = realmRoom.getTitle();
userStatus = G.fragmentActivity.getResources().getString(R.string.last_seen_recently);
}
} else {
mRoomId = realmRoom.getId();
title = realmRoom.getTitle();
if (chatType == GROUP && realmRoom.getGroupRoom() != null) {
groupParticipantsCountLabel = realmRoom.getGroupRoom().getParticipantsCountLabel();
isPublicGroup = roomIsPublic = !realmRoom.getGroupRoom().isPrivate();
} else if (chatType == CHANNEL && realmRoom.getChannelRoom() != null) {
groupParticipantsCountLabel = realmRoom.getChannelRoom().getParticipantsCountLabel();
showVoteChannel = realmRoom.getChannelRoom().isReactionStatus();
if (realmRoom.getChannelRoom().isVerified()) {
verifiedIcon.setVisibility(View.VISIBLE);
}
roomIsPublic = !realmRoom.getChannelRoom().isPrivate();
}
}
if (chatType == CHAT) {
setUserStatus(userStatus, lastSeen);
} else if ((chatType == GROUP) || (chatType == CHANNEL)) {
if (groupParticipantsCountLabel != null) {
if (HelperString.isNumeric(groupParticipantsCountLabel) && Integer.parseInt(groupParticipantsCountLabel) == 1) {
mToolbar.setSubTitle(groupParticipantsCountLabel + " " + G.fragmentActivity.getResources().getString(R.string.one_member_chat));
} else {
mToolbar.setSubTitle(groupParticipantsCountLabel + " " + G.fragmentActivity.getResources().getString(R.string.member_chat));
}
// avi.setVisibility(View.GONE);
}
}
} else if (chatPeerId != 0) {
/**
* when user start new chat this block will be called
*/
chatType = CHAT;
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
title = realmRegisteredInfo.getDisplayName();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
setUserStatus(userStatus, lastSeen);
}
if (title != null) {
mToolbar.setTitle(EmojiManager.getInstance().replaceEmoji(title, null));
}
/**
* change english number to persian number
*/
if (HelperCalander.isPersianUnicode) {
mToolbar.setTitle(EmojiManager.getInstance().replaceEmoji(mToolbar.getTitleTextView().getText().toString(), mToolbar.getTitleTextView().getPaint().getFontMetricsInt()));
mToolbar.setSubTitle(convertToUnicodeFarsiNumber(mToolbar.getSubTitleText()));
}
/**
* hint: don't check isCloudRoom with (( RealmRoom.isCloudRoom(mRoomId, realm); ))
* because in first time room not exist in RealmRoom and value is false always.
* so just need to check this value with chatPeerId
*/
if (chatPeerId == AccountManager.getInstance().getCurrentUser().getId()) {
isCloudRoom = true;
}
viewAttachFile = rootView.findViewById(R.id.layout_attach_file);
iconMute = mToolbar.getMuteIcon();
if (realmRoom != null) {
iconMute.setVisibility(realmRoom.getMute() ? View.VISIBLE : View.GONE);
isMuteNotification = realmRoom.getMute();
isChatReadOnly = realmRoom.getReadOnly();
}
// gone video , voice button call then if status was ok visible them
// mHelperToolbar.getSecondRightButton().setVisibility(View.GONE);
callItem.setVisibility(View.GONE);
if (isChatReadOnly) {
viewAttachFile.setVisibility(View.GONE);
(rootView.findViewById(R.id.chl_recycler_view_chat)).setPadding(0, 0, 0, 0);
} else if (chatType == CHAT && AccountManager.getInstance().getCurrentUser().getId() != chatPeerId && !isBot) {
// gone or visible view call
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (callConfig.isVoice_calling()) {
// mHelperToolbar.getSecondRightButton().setVisibility(View.VISIBLE);
callItem.setVisibility(View.VISIBLE);
} else {
callItem.setVisibility(View.VISIBLE);
// mHelperToolbar.getSecondRightButton().setVisibility(View.GONE);
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
}
createMoreItems();
manageExtraLayout();
}
use of net.iGap.request.RequestSignalingGetConfiguration in project iGap-Android by KianIranian-STDG.
the class UserLoginResponse method handler.
@Override
public void handler() {
super.handler();
HelperConnectionState.connectionState(ConnectionState.IGAP);
ProtoUserLogin.UserLoginResponse.Builder builder = (ProtoUserLogin.UserLoginResponse.Builder) message;
G.serverHashContact = builder.getContactHash();
if (builder.getUpdateAvailable() && !isUpdateAvailable) {
new android.os.Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if (G.onVersionCallBack != null) {
G.onVersionCallBack.isUpdateAvailable();
isUpdateAvailable = true;
}
}
}, 1000);
}
if (builder.getDeprecatedClient() && !isDeprecated) {
new android.os.Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if (G.onVersionCallBack != null) {
G.onVersionCallBack.isDeprecated();
isDeprecated = true;
G.isDepricatedApp = true;
}
}
}, 1000);
} else {
G.isDepricatedApp = false;
}
G.isNeedToCheckProfileWallpaper = true;
G.currentServerTime = builder.getResponse().getTimestamp();
G.bothChatDeleteTime = builder.getChatDeleteMessageForBothPeriod() * 1000;
RequestManager.getInstance(AccountManager.selectedAccount).setUserLogin(true);
TokenContainer.getInstance().updateToken(builder.getAccessToken(), false);
if (BuildConfig.SHOW_RATE_DIALOG_PERIOD_HOURE != 0 && sharedPreferences.getLong(SHP_SETTING.KEY_LOGIN_TIME_STAMP, 0) == 0) {
sharedPreferences.edit().putLong(SHP_SETTING.KEY_LOGIN_TIME_STAMP, new Date().getTime()).apply();
}
/**
* get Signaling Configuration
* (( hint : call following request after set G.userLogin=true ))
*/
DbManager.getInstance().doRealmTask(realm -> {
if (realm.where(RealmCallConfig.class).findFirst() == null) {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
});
new Thread(() -> {
G.clientConditionGlobal = RealmClientCondition.computeClientCondition(null);
new RequestClientGetRoomList().clientGetRoomList(0, Config.LIMIT_LOAD_ROOM, "0");
}).start();
G.onUserLogin.onLogin();
boolean doUserNeedFcmToken = builder.getNeedFcmToken();
if (doUserNeedFcmToken) {
RealmUserInfo.sendPushNotificationToServer();
}
DbManager.getInstance().doRealmTransaction(realm -> {
RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
contactCount = realm.where(RealmContacts.class).findAll().size();
if (realmUserInfo != null) {
realmUserInfo.setWalletActive(builder.getWalletActive());
realmUserInfo.setMplActive(builder.getMplActive());
realmUserInfo.setWalletRegister(builder.getWalletAgreementAccepted());
realmUserInfo.setAccessToken(builder.getAccessToken());
}
});
if (!isFetched) {
MessageController.getInstance(AccountManager.selectedAccount).getStories(contactCount);
}
}
Aggregations