How to get incoming messages from specific user?
For example:
VKRequest requestOutMessages = VKApi.messages().get(VKParameters.from(VKApiConst.USER_ID, vkUserId));
VKRequest requestInMessages = VKApi.messages().get(VKParameters.from(VKApiConst.OUT, vkUserId));
Which is giving me all 40 last messages from all my last conversations.
EDIT
public class VKApiMessagesExtension extends VKApiMessages {
public VKRequest getHistory(VKParameters params) {
return prepareRequest("getHistory", params, new VKParser() {
#Override
public Object createModel(JSONObject object) {
return new VKApiGetMessagesResponse(object);
}
});
}
}
Messages in VK can only be accessed by the user involved in the conversation. If you use the VK API to get messages, they will be for the logged in user.
In other words, messages are private.
The documentation states that "Returns a list of the current user's incoming or outgoing private messages."
Related
I am working on an app where my requirement is to transfer some files from one device to another. I am using Google's Nearby Connections API for this. As per the app requirement, when the advertiser (Receiver) receives the complete data, I need to send an acknowledegment to the Discoverer (Sender) in order to perform some operations on it. So can someone guide me through how it can be done?
If you only want to be notified when the advertiser received the data you sent, you can use the callback onPayloadTransferUpdate which works like a notification/acknowledgement about a payload transfer. You can do something like this:
private PayloadCallback payloadCallback =
new PayloadCallback() {
#Override
public void onPayloadReceived(#NonNull String endpointId, #NonNull Payload payload) {
}
#Override
public void onPayloadTransferUpdate(#NonNull String endpointId, #NonNull PayloadTransferUpdate payloadTransferUpdate) {
if (payloadTransferUpdate.getStatus() == PayloadTransferUpdate.Status.SUCCESS) {
// handle payload transfer success event - ACK
} else if (payloadTransferUpdate.getStatus() == PayloadTransferUpdate.Status.FAILURE) {
// handle payload transfer fail event - NAK
} else {
// handle other events like CANCELED and IN_PROGRESS
}
}
};
i'm using quickblox SDK in my project .
And i have a question about that.
Plz advise
I want to send push notification to other user in PUBLIC chat group.
I can do it with private chat by creating an event and sent to friend like this
public void createEvent(String message, List<Integer> userIds) {
StringifyArrayList<Integer> userIds_ = new StringifyArrayList<Integer>(userIds);
QBEvent event = new QBEvent();
event.setUserIds(userIds_);
event.setEnvironment(QBEnvironment.PRODUCTION);
event.setNotificationType(QBNotificationType.PUSH);
HashMap<String, Object> messageData = new HashMap<>();
messageData.put("message", message);
messageData.put("firID", KApp.getInstance().getCurrentUser().getId());
messageData.put("name", KApp.getInstance().getCurrentUser().getName());
event.setMessage(messageData);
QBPushNotifications.createEvent(event).performAsync(new QBEntityCallback<QBEvent>() {
#Override
public void onSuccess(QBEvent qbEvent, Bundle bundle) {
System.out.print("Create event success");
System.out.print(qbEvent.toString());
}
#Override
public void onError(QBResponseException e) {
System.out.print("Create event error : " + e.getLocalizedMessage());
}
});
}
But with PUBLIC chat dialog , i can't get list user id, it alway return empty.
How can i send push notification to other member in PUBLIC group ?
There is no sense in sending pushes to PUBLIC_GROUP because all users can chatting in public group chat. If you need notify occupants of dialog, use GROUP dialog. Note: in PUBLIC_GROUP you will also not receive pushes about messages when user is offline because PUBLIC_GROUP dialog not contain occupants_ids.
PUBLIC_GROUPS are open group. The difference between GROUP and PUBLIC_GROUP is that it does not keep associated participant's records like user_ids or unread_count . You have to store your participants data in your own backend server or else locally.
i was try to create login session with session key, the session key always generate new key either we do Login/registration, i can retrieve the data from my gson
LoginService loginService = retrofit.create(LoginService.class);
Observable<LoginResponse> obs = loginService.logins(emai,pass,"1", Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID), Build.MODEL, Build.VERSION.RELEASE);
obs.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).
subscribe(new Observer<LoginResponse>() {
#Override
public void onCompleted() {
}
#Override
public void onError(Throwable e) {
}
public void onNext(LoginResponse loginResponse) {
int responses = loginResponse.getCODE();
String texts="";
if(responses == 1)
{
User user = loginResponse.getDATALIST().get(0);
setPrefIsLogin(true);
setPrefSessionUid(user.getSESSIONKEY(),user.getUSERID());
nextActivity();
}
else{
}
}
});
the question is, how to make handler to handle the save session check if there is another login activity with the same account?
You should never assign two accessToken/Session for one user. You will send the same accessToken to the other instance of the new user. Plus side, user won't be able to duplicate his/her work by two accessToken.
If you want to force the other/first one AUTO-LOGOUT, you can use Firebase notification feature to send a notification to that particular deviceID and force it to stop. You can check firebase's tutorial to see how they work.
Another slow procedure is to check before login & everyother server side work to check if there are instance of same user. You will send an error and user end will receive it and show the error accompanying by logging out the user.
We have created a chat application using pubnub api on phonegap. We are using a common unique channel for two users (say A & B) to send and receive messages. Also, in addition to this, we have enabled pubnub gcm notification so that users can receive notifications when their app is either in the background or closed. Now when a user A sends a pubnub message to B and instantly changes the application or hides it, then the user A himself also receives a gcm notification oh his own message. This is the only issue that is troubling us. Rest all is working fine.
In your subscribe callback, can you detect if the application is not in the foreground, and if not in the foreground, return immediately?
This way, the logic which would deliver received messages to your application logic simply doesnt fire unless you are in foreground... ?
I ran into the same similar problem you did and so I rigged something together that works for me.
private boolean isFromSelf(final Object msgSent){
boolean isEcho = false;
String msgText = msgSent.toString();
JSONObject j;
String receiver = currentUserId; //a unique string ID for each user
try
{
j = new JSONObject(msgText);
String senderID = j.get("senderID").toString();
if (senderID.equals(receiver)){
isEcho = true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return isEcho;
}
It makes the assumption that every user that publishes a message to a channel will send their unique Id as "senderID" included in the payload. Then when a message is received, extract it from the payload and check it against the user's Id. So I add isFromSelf method as the first thing that is called when I receive a message, like this:
pN = new Pubnub(pub_key, sub_key);
try {
pN.subscribe(CHANNEL_NAME, new Callback() {
public void successCallback(String channel, Object msg) {
if (!isFromSelf(msg)) {
//Now add here what you want to do with the message
}
}
public void errorCallback(String channel, PubnubError error) {
Toast.makeText(MainActivity.this, "there was an error connecting", Toast.LENGTH_SHORT).show();
}
});
} catch (PubnubException e) {
e.printStackTrace();
}
So in your case, perhaps rig together a senderID check so that if you do receive a GCM from yourself, do not display notification at all, even if app is in background.
I use the following methods to get status updates from multiple users.
public void getUserFeed(long userID, RequestListener listener) {
long time = System.currentTimeMillis();
Bundle params = new Bundle();
params.putString("uid", userID + "");
params.putString("fields", "statuses");
asyncFacebookRunner.request(FRIENDS, params, listener);
}
public void getFeedsForUsers(List<User> facebookUsersInFeed,
final RequestListener listener) {
for (final User user : facebookUsersInFeed) {
getUserFeed(user.getId(), listener);
}
}
Most of the time, this works fine. But every now and then, I get a response in which the data array is completely empty. Any ideas?
The most likely reason is because that specific user has blocked 3rd party apps from accessing their data, therefore, when you try to fetch their info it will return empty.