QuickBlox get presence of user which isn't in the contacts - java

I'm developing android chat application using QuickBlox.. My app will be like : The user logs in and chooses any another user to chat with.. (Not in the roster).. I managed to get users using the following code :
retrieveAllUsersFromPage(1);
private void retrieveAllUsersFromPage(int page){
QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(page);
pagedRequestBuilder.setPerPage(100);
QBUsers.getUsers(pagedRequestBuilder, this);
}
int userNumber = 1;
#Override
public void onSuccess(ArrayList<QBUser> users, Bundle params) {
for(QBUser user : users){
this.users.add(user);
userNumber ++;
}
int currentPage = params.getInt(Consts.CURR_PAGE);
int totalEntries = params.getInt(Consts.TOTAL_ENTRIES);
if(userNumber < totalEntries){
retrieveAllUsersFromPage(currentPage+1);
}
}
but I wanna filter them to add only the available(online) users.. I can't find a way to do that.. Any Idea ?

With no roster you can use next trick with user.lastRequestAt field
http://quickblox.com/developers/SimpleSample-users-android#Online.5COffline_status

Related

how to integrate with Zoom app using android?

I'm new with zoom integration.
I wants user login and create meeting in their account. I've done login user part using loginWithZoom method but now wants to create meeting for that auth token needed.
How can I get token when user login in zoom without OAuth?
I've found but not getting much idea. I tried with JWT token it works with
https://api.zoom.us/v2/users/me/meetings api. I gave Authorization token and content-type in
headers. it gives me all meetings of that specific user. but problem to get different authorization token for different users. I don't have idea is it possible or not.
Suggest if anyone knows
Code I've used for Login:
public void initializeSdk(Context context) {
ZoomSDK sdk = ZoomSDK.getInstance();
// TODO: Do not use hard-coded values for your key/secret in your app in production!
ZoomSDKInitParams params = new ZoomSDKInitParams();
params.appKey = "a...t4.."; // TODO: Retrieve your SDK key and enter it here
params.appSecret = "y...19"; // TODO: Retrieve your SDK secret and enter it here
params.domain = "zoom.us";
params.enableLog = true;
// TODO: Add functionality to this listener (e.g. logs for debugging)
ZoomSDKInitializeListener listener = new ZoomSDKInitializeListener() {
/**
* #param errorCode {#link us.zoom.sdk.ZoomError#ZOOM_ERROR_SUCCESS} if the SDK has been initialized successfully.
*/
#Override
public void onZoomSDKInitializeResult(int errorCode, int internalErrorCode) {
Log.i("","onZoomSDKInitializeResult Error code"+errorCode);
Toast.makeText(getApplicationContext()," error code : " + errorCode,Toast.LENGTH_LONG).show();
}
#Override
public void onZoomAuthIdentityExpired() {
System.out.println(" identity expired..");
}
};
sdk.initialize(context, listener, params);
}
findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "onclick of login", Toast.LENGTH_LONG).show();
Log.i(" ","onclick of login : "+ ZoomSDK.getInstance().isLoggedIn());
if (ZoomSDK.getInstance().isLoggedIn()) {
//wants to create meeting
} else {
createLoginDialog();
}
}
});
private void createLoginDialog() {
new AlertDialog.Builder(this)
.setView(R.layout.dialog_login)
.setPositiveButton("Log in", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog dialog = (AlertDialog) dialogInterface;
TextInputEditText emailInput = dialog.findViewById(R.id.email_input);
TextInputEditText passwordInput = dialog.findViewById(R.id.pw_input);
if (emailInput != null && emailInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
String email = emailInput.getText().toString();
String password = passwordInput.getText().toString();
if (email.trim().length() > 0 && password.trim().length() > 0) {
login(email, password);
}
}
dialog.dismiss();
}
})
.show();
}
public void login(String username, String password) {
int result = ZoomSDK.getInstance().loginWithZoom(username, password);
if (result == ZoomApiError.ZOOM_API_ERROR_SUCCESS) {
// Request executed, listen for result to start meeting
ZoomSDK.getInstance().addAuthenticationListener(authListener);
}
}
public void onZoomSDKLoginResult(long result) {
if (result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_SUCCESS) {
// Once we verify that the request was successful, we may start the meeting
Toast.makeText(getApplicationContext(), "Login successfully", Toast.LENGTH_SHORT).show();
} else if(result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_USER_NOT_EXIST || result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_WRONG_PASSWORD){
Toast.makeText(getApplicationContext(),"Invalid username or password",Toast.LENGTH_LONG).show();
}
}
Thanks in advance.
I tried with JWT token it works with
https://api.zoom.us/v2/users/me/meetings api. I gave Authorization
token and content-type in headers. it gives me all meetings of that
specific user. but problem to get different authorization token for
different users. I don't have idea is it possible or not.
Assuming these users are not part of the same Zoom account, then no, it is not possible as of 2021-08-28. JWT-based authentication is only for Zoom integration in internal applications/services:
Note: JWT may only be used for internal applications and processes. All apps created for third-party usage must use our OAuth app type.
In this context, "internal" means "only to be used with a single Zoom account." Note that there can be many users under one account (e.g., all employees of Corporation XYZ are part of XYZ's Zoom account). Put differently, you can use a JWT issued for the XYZ Zoom account to access information for all users under the XYZ Zoom account, but if you need data for users that are not part of the XYZ Zoom account, then you need an API Key and API Secret for their Zoom account(s) as well to generate JWTs that you can use to retrieve their data.
If you are building an integration/service that you want to make available to the general public, then you need to use OAuth:
This app can either be installed and managed across an account by
account admins (account-level app) or by users individually
(user-managed app).

Getting basic user data from authorised google account

In this android application, I want to get the user data (email id, name, etc) from the authorised google account. In this case I'm caching tokens to see if the user is logged in or not, and if the user is already logged in, it will fetch the basic user data.
The code uses a button to login.
public void login(View view){
if (loadUserTokenCache(mClient)){
TextView tv1 = (TextView)findViewById(R.id.textView2);
tv1.setVisibility(View.VISIBLE);
}
else {
ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);
Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
#Override
public void onFailure(Throwable exc) {
createAndShowDialog("You must log in. Login Required", "Error");
}
#Override
public void onSuccess(MobileServiceUser user) {
createAndShowDialog(String.format(
"You are now logged in - %1$2s",
user.getUserId()), "Success");
cacheUserToken(mClient.getCurrentUser());
}
});
}
}
You can do this using the AccountsManager. For example, this is how you could retrieve the user's gmail.
// Retrieve the gmail associated with the device that is being used.
String gmailID = "";
Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google");
if(accounts.length > 0) {
gmailID = accounts[0].name;
}

GWT AutoComplete Or Suggest Box

I am using suggest box for implementing autocomplete in GWT.
For retrieving data from entity i am using objectify and for mapping data to suggest box i have used MultiWordSuggestOracle.
On form load i am firing a query for retrieving data and passing it to MultiWordSuggestOracle. It is working fine.
For eg if i am loading customer data in suggestion it is working
But for eg if i have 5000 - 50000 customer records in my entity, so to retrieve all data and show it in suggestion could not be successful.
So is there any other technique for using autocomplete in gwt?
Thanks in advance
Instead of loading allt he customer records in on form load, dynamically filter the data on the backend based on what the user types into the SuggestBox. You can do this by implementing a custom SuggestOracle (maybe extending the MultiWordSuggestOracle).
public class ServerSuggestOracle extends SuggestOracle{
protected DataSource datasource;
protected int startQueryLength;
protected ArrayList<T> suggestions = new ArrayList<T>();
protected boolean isMoreSuggestions = false;
protected int previousQueryLength = 0;
public ServerSuggestOracle(DataSource datasource,int startQueryLength)
{
super();
this.datasource = datasource;
this.startQueryLength = startQueryLength;
}
#Override
public void requestSuggestions(final Request request, final Callback callback) {
// start the backend call only if the user types in more than startQueryLength characters.
if (request.getQuery().length() < startQueryLength)
return;
// if the user expands the search or a serach hasn't been carried out, call the backend. Otherwise filte the existing list
if (isMoreSuggestions || previousQueryLength > request.getQuery().length() || suggestions.size() == 0)
{
datasource.fetchDataFromBackend(request.getQuery(), new FetchDataFromBackendCallback() {
#Override
public void onFetchData(ArrayList<T> genes,Integer count,boolean isMore) {
suggestions.clear();
for (int i = 0;i<genes.size();i++) {
Suggestion suggestion = new Suggestion();
suggestions.add(suggestion);
}
SuggestOracle.Response response = new SuggestOracle.Response(suggestions);
isMoreSuggestions = isMore;
if (count != null)
response.setMoreSuggestionsCount(count);
else
response.setMoreSuggestions(isMore);
previousQueryLength = request.getQuery().length();
callback.onSuggestionsReady(request,response);
}
});
}
else
{
super.requestSuggestions(request,cabllack);
}
}
}

HttpServletRequest gets lost once every three requests

Despite of being hard to choose a title for my question, here is the problem.
For my login page, I have managed to use spring web flow. One of the main stages in login process is that, if the user is trying to login and has provided wrong username and password more than three times, there should be a captcha verification as well. Hence, here is the captcha class:
public final class CaptchaErrorCountAction extends AbstractAction {
private String COUNT = "count";
private String SHOWCAPTCHA = "showCaptcha";
protected Event doExecute(final RequestContext context) {
Integer count;
HttpServletRequest request = WebUtils.getHttpServletRequest(context);
try {
count = (Integer) request.getSession().getAttribute("count");
if (count == null) {
count = 0;
}
} catch (Exception e) {
count = 0;
}
count++;
request.getSession().setAttribute(COUNT, count);
request.getSession().setAttribute(SHOWCAPTCHA, true);
return success();
}
}
In google chrome, everything is fine and the count variable shows the number of failed login attempts with a simple break point. But in firefox, 3rd, 6th, 9th, ... failed login attempts never gets to count++ and seemly gets lots. what would seem to be the problem?

Play2 Framework Better solution

So I am doing an edit profile feature with Play! Framework (2.2.0);
I have this code
public static Result doEditProfile(){
final User localUser = getLocalUser(session());
Form<User> formData = editProfileForm.bindFromRequest();
if (formData.hasErrors()) {
return badRequest(views.html.editprofile.render(localUser, editProfileForm));
} else {
localUser.firstName = formData.field("firstName").value();
localUser.lastName = formData.field("lastName").value();
localUser.locale = formData.field("locale").value();
localUser.gender = formData.field("gender").value();
localUser.country = formData.field("country").value();
localUser.save();
}
return redirect("/profile/edit");
}
It works. But I want to know is there a better way of doing this ?
I have tried this things:
1)
public static Result doEditProfile(){
final User localUser = getLocalUser(session());
Form<User> formData = editProfileForm.bindFromRequest();
if (formData.hasErrors()) {
return badRequest(views.html.editprofile.render(localUser, editProfileForm));
} else {
User localUser = formData.get();
localUser.save();
}
return redirect("/profile/edit");
}
but this says that variable localUser is already defined.
2) also, I tried this
public static Result doEditProfile(){
final User localUser = getLocalUser(session());
Form<User> formData = editProfileForm.bindFromRequest();
if (formData.hasErrors()) {
return badRequest(views.html.editprofile.render(localUser, editProfileForm));
} else {
User updatedUser = formData.get();
updatedUser.save();
}
return redirect("/profile/edit");
}
but this code is creating a new user in the database.
I am new to Play so I am waiting for any advice. Thanks and sorry for my english
Does your user have a unique id? If so, you could try the following:
updatedUser.setId(localUser.getId())
updatedUser.save()
Saw this example here:
How to update an existing object in playframework 2.0.2? aka CRUD in 1.2.x
... along the lines of what #mantithetical was saying. Better to have an update method in your User class:
public static Result update(Long id) {
Form<User> userForm = form(User.class).bindFromRequest();
if(userForm.hasErrors()) {
return badRequest(editForm.render(id, userForm));
}
userForm.get().update(id);
...
Just a matter of providing the unique id (note that also, we're relying on the id, rather than the entire user, when handling bad requests). You can do that by adding a parameter to your controller in the routes file:
POST /update/:id controllers.doEditProfile(id: Long)
Then when you direct to your controller method, you have to pass that unique id in.

Categories

Resources