|
|
|
@ -4,8 +4,8 @@
|
|
|
|
|
(function() {
|
|
|
|
|
window.libloki = window.libloki || {};
|
|
|
|
|
|
|
|
|
|
async function sendFriendRequestAccepted(pubKey) {
|
|
|
|
|
return sendEmptyMessage(pubKey, true);
|
|
|
|
|
async function sendBackgroundMessage(pubKey) {
|
|
|
|
|
return sendOnlineBroadcastMessage(pubKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function broadcastOnlineStatus() {
|
|
|
|
@ -30,9 +30,6 @@
|
|
|
|
|
let type;
|
|
|
|
|
|
|
|
|
|
if (!window.localLokiServer.isListening()) {
|
|
|
|
|
// Skip if server is not running AND we're not trying to ping a contact
|
|
|
|
|
if (!isPing) return;
|
|
|
|
|
|
|
|
|
|
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
|
|
|
|
|
} else {
|
|
|
|
|
// clearnet change: getMyLokiAddress -> getMyClearIP
|
|
|
|
@ -66,51 +63,8 @@
|
|
|
|
|
await outgoingMessage.sendToNumber(pubKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function sendEmptyMessage(pubKey, sendContentMessage = false) {
|
|
|
|
|
const options = {};
|
|
|
|
|
// send an empty message.
|
|
|
|
|
if (sendContentMessage) {
|
|
|
|
|
// The logic downstream will attach the prekeys and our profile.
|
|
|
|
|
await textsecure.messaging.sendMessageToNumber(
|
|
|
|
|
pubKey, // number
|
|
|
|
|
null, // messageText
|
|
|
|
|
[], // attachments
|
|
|
|
|
null, // quote
|
|
|
|
|
[], // preview
|
|
|
|
|
Date.now(), // timestamp
|
|
|
|
|
null, // expireTimer
|
|
|
|
|
null, // profileKey
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// empty content message
|
|
|
|
|
const content = new textsecure.protobuf.Content();
|
|
|
|
|
|
|
|
|
|
// will be called once the transmission succeeded or failed
|
|
|
|
|
const callback = res => {
|
|
|
|
|
if (res.errors.length > 0) {
|
|
|
|
|
res.errors.forEach(error => log.error(error));
|
|
|
|
|
} else {
|
|
|
|
|
log.info('empty message sent successfully');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// send an empty message. The logic in ougoing_message will attach the prekeys.
|
|
|
|
|
const outgoingMessage = new textsecure.OutgoingMessage(
|
|
|
|
|
null, // server
|
|
|
|
|
Date.now(), // timestamp,
|
|
|
|
|
[pubKey], // numbers
|
|
|
|
|
content, // message
|
|
|
|
|
true, // silent
|
|
|
|
|
callback, // callback
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
await outgoingMessage.sendToNumber(pubKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.libloki.api = {
|
|
|
|
|
sendFriendRequestAccepted,
|
|
|
|
|
sendEmptyMessage,
|
|
|
|
|
sendBackgroundMessage,
|
|
|
|
|
sendOnlineBroadcastMessage,
|
|
|
|
|
broadcastOnlineStatus,
|
|
|
|
|
};
|
|
|
|
|