How to know that when the user goes offline in AgsXMPP? - xmpp

I am currently trying with agsXMPP library ,
i added users to a treenode on OnPresence event.
its works well, but when the other user goes offline i want to update the tree node,
for that i need his Offline Presence ,How i get result when a chat buddy goes offline ?

When a buddy goes offline you get a OnPresence event with the Type of unavailable.
private void XmppCon_OnPresence(object sender, Presence pres)
{
if (pres.Type == PresenceType.unavailable)
{
// user goes offline
}
}

Related

Conversejs has support to get archive message in indexedDb by plugin not?

Please show me how conversejs can get the message stored in indexedDb by plugin if possible? I want to create my own chat history list interface because controlbox is not suitable for my business.
The messages are stored in a Collection which is set as the messages attribute on the ChatBox model. A ChatBox represents the Chat conversation with a particular contact.
converse.plugins.add("my-plugin", {
initialize() {
const { api } = this._converse;
const chat = api.chats.get('contact#example.org');
// log all messages to the console
chat.messages.forEach(m => console.log(m.get('body'));
}
});

FCM send to specific user

I am using cloud Firestore.
When I use cloud messaging to send push notifications to an app, a message goes to all users (users registered with Authentication) who are registered in the app.
The app has a login function, so I hope only the logged-in user gets notified.
That is, how can I send notifications only to specific users?
I want to set the time and day of the week with cloud messaging and send it to a specific device.
Now I even marked the token on the logcat and tested it in cloud messaging as shown in the picture.
However, the test cannot set the time and day of the week.
Is it possible to do this in the Fire Store? Or do I have to set the time and day of the week in the code as shown in the link?
enter image description here
//FirebaseMessagingService
#Override
public void onNewToken(String token) {
Log.e("NEW_TOKEN", token);
}
//MainActivity
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
#Override
public void onComplete(#NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
// Log and toast
//String msg = getString(R.string.msg_token_fmt, token);
Log.d("NEW_TOKEN", token);
Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();
}
});
I'll just write an answer just for better track.
As #Doug already mentioned, you could try using this code sample and try on your own.
Finally, is a good practice to show what you have tried and a code snippet to better understand your question.

Ionic 4 + WhatsApp share - Get receiver / contact details after I share my message

I am using Ionic 4 + SocialSharing-PhoneGap-Plugin.
After I share a message with my contact, how can I get back the contact's name/number and other info back in the promise, so that I can save it in the database?
I have the following code:
import { SocialSharing } from '#ionic-native/social-sharing/ngx';
constructor(private socialSharing: SocialSharing) { }
// Share message via WhatsApp
this.socialSharing.shareViaWhatsApp('Hi', null, null).then(() => {
// How to get the contact's details here, with whom
// I shared my message? Would like to get the name, number
// and all other contact info.
// Following Toast does not seem to trigger
this.toastService.presentToast('Successfully shared coupon on WhatsApp', 'success');
}).catch(() => {
// Sharing via WhatsApp is not possible. How to trigger a toast here as well?
});
How can I show a toast message immediately after return, so that I know that the message was shared successfully? As can be seen from the code, I have a toastService that shows the toast, but it never gets triggered. How can I trigger the toast after successfully sharing my message on WhatsApp, both in success & error cases?
To access contacts, you'll need a separate plugin like Contacts -- maybe get the contact first using that plugin and then use shareViaWhatsAppToPhone to share directly to that number.
The toast should work. From your example, it doesn't look like you've injected the ToastService into the class.

Cancel sent Web Push notifications

I'm sending push notifications to my website users when they (for example) receive a private message.
That notification goes to all browsers subscribed for that user. So could be desktop, mobile, work computer etc.
What I would like to do is close all the sent notifications once the user has a read a message.
So user logs in on mobile, reads the private message - at this point I want all the previously sent notifications for that PM to be closed/cancelled.
Is this possible?
Thanks in advance!
Matt
Yes this is possible, but not silently. For example, Chrome will replace the notification with a new one saying "This site has been updated in the background".
There are two separate APIs: the Push API which "gives web applications the ability to receive messages pushed to them from a server", and the Notification API which "is used to configure and display desktop notifications to the user".
The Notification API provides Notification.close(), which cancels the display of a notification.
You can use the Push API to trigger Notification.close(). Here's a sample which should go in your service worker:
self.addEventListener('push', async event => {
const data = event.data.json();
if (data.type === 'display_notification') {
self.registration.showNotification(data.title, data.options);
} else if (data.type === 'cancel_notification') {
const notifications = await self.registration.getNotifications({
tag: data.notificationTag
});
for (notification of notifications) {
notification.close();
}
} else {
console.warn("Unknown message type", event, data);
}
});
However! This design means that your cancel_notification message won't display a notification. This violates some browser policies, for example Chrome will display a new notification saying "This site has been updated in the background".

How can I approve an XMPP subscription request 'later' in Smack ("Add later" functionality)?

Let us suppose that Alice sends a subscription request to Bob using the next code.
public bool AddBuddy(string jid) {
var roster = conn.Roster;
// 2` param is nickname
roster.CreateEntry(jid, null, null);
roster.SetSubscriptionMode(Roster.SubscriptionMode.Manual);
Presence subscribe = new Presence(Presence.Type.Subscribe);
subscribe.To = jid;
conn.SendPacket(subscribe);
}
When Bob has logged, it receives a popup where tell you if you want to added or not in the next method.
public void ProcessPacket (Packet p0)
{
Presence presence = p0.JavaCast<Presence> ();
var a = presence;
}
But I need to implement a "Add Later" functionality. I have no idea how to save the messages in the server and also how to receive all of them
You can delay the subscription as long as you want, there is no need to save the subscriptions packets on the server. And in order to query the deferred subscriptions requests, simply query the roster for subscriptions not in mode both.
One remark regarding your code: Roster.createEntry(String, String, String[] will automatically send the presence packat. No need to send it again.
No need to save anything on the server as it maintains pending subscribe requests automatically, ie. whenever you login to the server at a later time, the subscribe request will be pushed to you again (if it wasn't dealt with before). Therefore, just save the subscribe request locally in your application in a list or something whenever you receive it from the server, and show that local request list to the user as a "Friend request page" for the user to accept/reject. If your application's lifecycle restarts, it will be receiving all pending subsribe presences again from the server (or whenever it re-logins). Let me know if this works for you.