diff --git a/home.html b/home.html
index 0880b8d..be90061 100644
--- a/home.html
+++ b/home.html
@@ -49,6 +49,7 @@
Fulano da Silva
View
+
diff --git a/js/interface_common.js b/js/interface_common.js
index 66f1171..de8222f 100644
--- a/js/interface_common.js
+++ b/js/interface_common.js
@@ -802,6 +802,30 @@ function openConversationModal(peerAlias, resource) {
});
}
+function openRequestShortURIForm() {
+ if (!defaultScreenName) {
+ alertPopup({
+ //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS
+ txtMessage: 'You can\'t short links because you are not logged in.'
+ });
+ }
+ var uri = prompt('enter a link, watch yourself carefully'); // FIXME
+ newShortURI(uri,
+ function (req, uriLong, uriShort) {
+ if (uriShort)
+ alertPopup({
+ txtTitle: 'URI shortener',
+ txtMessage: uriLong + ' — `' + uriShort + '`'
+ });
+ else
+ alertPopup({
+ txtTitle: 'URI shortener',
+ txtMessage: 'something went wrong. RPC error message:\n' + (uriShort && uriShort.message) ? uriShort.message : uriShort
+ });
+ }
+ );
+}
+
function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) {
var formatted = htmlFormatMsg(txt, htmlFormatMsgOpt);
@@ -2251,6 +2275,8 @@ function initInterfaceCommon() {
$('.tox-ctc').on('click', promptCopyAttrData);
$('.bitmessage-ctc').on('click', promptCopyAttrData);
+ $('.uri-shortener').on('click', openRequestShortURIForm); // FIXME implement Uri Shortener Center with links library etc
+
if ($.fn.textcomplete) {
$('.post-area-new textarea')
.on('focus', {req: getMentionsForAutoComplete}, setTextcompleteOnEventTarget)
diff --git a/js/twister_actions.js b/js/twister_actions.js
index 28e90df..4f178ca 100644
--- a/js/twister_actions.js
+++ b/js/twister_actions.js
@@ -322,6 +322,37 @@ function newRtMsg(postData, msg) {
}
}
+function newShortURI(uri, cbFunc, cbReq) {
+ if (!uri || !defaultScreenName) return;
+
+ for (var i in twister.URIs)
+ if (twister.URIs[i] === uri) {
+ if (typeof cbFunc === 'function')
+ cbFunc(cbReq, uri, i);
+ return;
+ }
+
+ twisterRpc('newshorturl', [defaultScreenName, lastPostId + 1, uri],
+ function (req, ret) {
+ if (ret) {
+ ret = ret[0]; // FIXME there should be 1 element anyway for daemon version 93500
+ twister.URIs[ret] = req.uri;
+ $.localStorage.set('twistaURIs', twister.URIs);
+ incLastPostId();
+ } else
+ console.warn('RPC "newshorturl" error: empty response');
+
+ if (typeof req.cbFunc === 'function')
+ req.cbFunc(req.cbReq, req.uri, ret);
+ }, {uri: uri, cbFunc: cbFunc, cbReq: cbReq},
+ function (req, ret) {
+ console.warn('RPC "newshorturl" error: ' + (ret && ret.message) ? ret.message : ret);
+ if (typeof req.cbFunc === 'function')
+ req.cbFunc(req.cbReq, req.uri, ret);
+ }, {uri: uri, cbFunc: cbFunc, cbReq: cbReq}
+ );
+}
+
function updateProfileData(profileModalContent, username) {
//profileModalContent.find("a").attr("href",$.MAL.userUrl(username));