Trying implementations of the "Nope" feature on Meet account
* Nope is implemented by blocking the account, as by doing so, it won't appear anymore * However, accounts will be silenced as soon as a message comes from someone that did not match both parties
This commit is contained in:
parent
4291d4e442
commit
2b9c2424fe
|
@ -36,7 +36,7 @@
|
|||
<div class="like-div"><a class="status-favs-reblogs status-favs"
|
||||
rel="prefetch"
|
||||
href="javascript:void(0)"
|
||||
onclick="return api_status_fav(this,'{originalStatusId}');"
|
||||
onclick="return fediloveMastodon.API.statusFav(this,'{originalStatusId}');"
|
||||
aria-label={favoritesLabel}>
|
||||
<svg class="status-favs-reblogs-svg"><path d="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"></path></svg>
|
||||
<span>{numFavs}</span>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<textarea type="text" placeholder="Send your message"></textarea>
|
||||
</td>
|
||||
<td>
|
||||
<button id="send" onclick="return api_send_message();" class="primary compose-box-button" aria-label="Send!">
|
||||
<button id="send" onclick="return fediloveMastodon.API.sendMessage();" class="primary compose-box-button" aria-label="Send!">
|
||||
<svg xlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24" width="24">
|
||||
<path d="M0 0h24v24H0z" fill="none"/><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
|
@ -5,64 +5,66 @@
|
|||
|
||||
// Do simple XHR requests to the API on Mastodon
|
||||
// make sure you control errors correctly, as a Mastodon Server might not setup CORS correctly
|
||||
function mastodon_get(path, payload, callbk) { return mastodon_request('GET', path, payload, callbk); }
|
||||
function mastodon_post(path, payload, callbk) { return mastodon_request('POST', path, payload, callbk); }
|
||||
function mastodon_request(method, path, payload, callbk) {
|
||||
payload = payload || null;
|
||||
const fediloveMastodon = {
|
||||
request: function(method, path, payload, callbk) {
|
||||
payload = payload || null;
|
||||
const ACCESS_TOKEN = window.fediloveApi.getAccessToken();
|
||||
if (ACCESS_TOKEN === undefined)
|
||||
return callbk(undefined);
|
||||
const API_URL = 'https://'+fediloveApi.getCurrentInstance()+path;
|
||||
const oReq = new XMLHttpRequest();
|
||||
oReq.addEventListener("load", function() { callbk(this.responseText); });
|
||||
oReq.open(method, API_URL);
|
||||
oReq.setRequestHeader('Authorization', 'Bearer '+ACCESS_TOKEN);
|
||||
oReq.send(payload);
|
||||
},
|
||||
get: function(path, payload, callbk) {
|
||||
return fediloveMastodon.request('GET', path, payload, callbk);
|
||||
},
|
||||
post: function(path, payload, callbk) {
|
||||
return fediloveMastodon.request('POST', path, payload, callbk);
|
||||
},
|
||||
API: {
|
||||
discardAccount: function(account_id, cback) {
|
||||
fediloveMastodon.post('/api/v1/accounts/18084/block', {}, function(data) { cback() });
|
||||
},
|
||||
statusFav: function(dom, status_id) {
|
||||
var dislike = false;
|
||||
var path = `/api/v1/statuses/${status_id}/favourite`;
|
||||
if (dom.getAttribute('data-liked') === "1") {
|
||||
path = `/api/v1/statuses/${status_id}/unfavourite`;
|
||||
dislike = true;
|
||||
}
|
||||
fediloveMastodon.post(path, {}, function(data) {
|
||||
if (!dislike) {
|
||||
$(dom).addClass('liked-msg');
|
||||
$(dom).attr('data-liked', 1);
|
||||
dom.style.animation = "spin2 .5s linear 1";
|
||||
} else {
|
||||
$(dom).removeClass('liked-msg');
|
||||
$(dom).attr('aria-label', '0 '+$(dom).attr('aria-label'));
|
||||
$(dom).removeAttr('data-liked');
|
||||
dom.style.animation = undefined;
|
||||
}
|
||||
});
|
||||
},
|
||||
sendMessage: function() {
|
||||
// the message is composed from the current chat Acct (@user@domain) + the compose textarea value
|
||||
const text = fediloveData.chatAvatarCache.acct + ' ' + $('div#chat-compose-global textarea').val();
|
||||
|
||||
const ACCESS_TOKEN = window.fediloveApi.getAccessToken();
|
||||
if (ACCESS_TOKEN === undefined)
|
||||
return callbk(undefined);
|
||||
//async function postStatus(realm, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility, mediaDescriptions, inReplyToUuid, poll, mediaFocalPoints)
|
||||
const lastStatus = fediloveApi.getChatLastMessageId(true);
|
||||
fediloveFunctions.postStatus(lastStatus.id, text, lastStatus.id, [], false, undefined,
|
||||
'direct', undefined, lastStatus.uuid, undefined, undefined);
|
||||
|
||||
const API_URL = 'https://'+fediloveApi.getCurrentInstance()+path;
|
||||
// empty the current compose box
|
||||
$('div#chat-compose-global textarea').val('');
|
||||
|
||||
const oReq = new XMLHttpRequest();
|
||||
oReq.addEventListener("load", function() { callbk(this.responseText); });
|
||||
oReq.open(method, API_URL);
|
||||
oReq.setRequestHeader('Authorization', 'Bearer '+ACCESS_TOKEN);
|
||||
oReq.send(payload);
|
||||
}
|
||||
|
||||
function api_status_fav(dom, status_id) {
|
||||
var dislike = false;
|
||||
var path = `/api/v1/statuses/${status_id}/favourite`;
|
||||
if (dom.getAttribute('data-liked') === "1") {
|
||||
path = `/api/v1/statuses/${status_id}/unfavourite`;
|
||||
dislike = true;
|
||||
}
|
||||
mastodon_post(path, {}, function(data) {
|
||||
// to-do: check "data" if the POST succeded (for now we expect it did xD)
|
||||
if (!dislike) {
|
||||
$(dom).addClass('liked-msg');
|
||||
$(dom).attr('data-liked', 1);
|
||||
dom.style.animation = "spin2 .5s linear 1";
|
||||
} else {
|
||||
$(dom).removeClass('liked-msg');
|
||||
$(dom).attr('aria-label', '0 '+$(dom).attr('aria-label'));
|
||||
$(dom).removeAttr('data-liked');
|
||||
dom.style.animation = undefined;
|
||||
// scroll to the end as all chat Apps do
|
||||
fediloveUI.scrollChatToLastItem();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// The api to send a message on the current chat thread has been improved a lot
|
||||
// and now is much more rock-solid, and we reuse the React functions
|
||||
function api_send_message() {
|
||||
|
||||
// the message is composed from the current chat Acct (@user@domain) + the compose textarea value
|
||||
const text = fediloveData.chatAvatarCache.acct + ' ' + $('div#chat-compose-global textarea').val();
|
||||
|
||||
//async function postStatus(realm, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility, mediaDescriptions, inReplyToUuid, poll, mediaFocalPoints)
|
||||
const lastStatus = fediloveApi.getChatLastMessageId(true);
|
||||
fediloveFunctions.postStatus(lastStatus.id, text, lastStatus.id, [], false, undefined,
|
||||
'direct', undefined, lastStatus.uuid, undefined, undefined);
|
||||
|
||||
// empty the current compose box
|
||||
$('div#chat-compose-global textarea').val('');
|
||||
|
||||
// scroll to the end as all chat Apps do
|
||||
fediloveUI.scrollChatToLastItem();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var fediloveUI = {
|
||||
registerSwipeOnElementEvents: {
|
||||
|
@ -219,7 +221,16 @@ var fediloveUI = {
|
|||
$('div#chat-party-global > div#name > span').text(acct);
|
||||
if (accid != 0) $('div#chat-party-global > div#name > a').attr('href', `/accounts/${accid}`);
|
||||
},
|
||||
onAccountNope: function() {},
|
||||
onAccountNope: function() {
|
||||
const accObj = fediloveApi.getMeetAccount();
|
||||
if (accObj === undefined) return;
|
||||
if (!fediloveData.tmpDiscardedAccounts.includes(accObj.id))
|
||||
fediloveData.tmpDiscardedAccounts.push(accObj.id);
|
||||
fediloveMastodon.API.discardAccount(accObj.id, function() {
|
||||
$('div.virtual-list')[0].style.animation = 'nopeMeet .25s linear 1';
|
||||
setTimeout(function() { window.history.back() }, 220);
|
||||
});
|
||||
},
|
||||
onAccountMatch: function() {},
|
||||
onAccountMaybe: function() {}
|
||||
};
|
||||
|
@ -301,6 +312,7 @@ var fediloveData = {
|
|||
myAccountId: undefined,
|
||||
currentAccountIsEmpty: false,
|
||||
currentIDMeetTimeline: null,
|
||||
tmpDiscardedAccounts: [],
|
||||
gotEmojifyTextFunction: false,
|
||||
composeTxtKeypressEvent: false
|
||||
};
|
||||
|
@ -338,7 +350,7 @@ var fediloveEvents = {
|
|||
account_id = data.mentions[0].id;
|
||||
}
|
||||
if (account_id === null || account_id === undefined) return;
|
||||
mastodon_get(`/api/v1/accounts/${account_id}`, {}, function(newData) {
|
||||
fediloveMastodon.get(`/api/v1/accounts/${account_id}`, {}, function(newData) {
|
||||
var json = JSON.parse(newData);
|
||||
if (json !== undefined) {
|
||||
waitForEmojifyAndDo( account_id, `@${json.acct}`, json.avatar, json.display_name, json.emojis );
|
||||
|
@ -385,7 +397,7 @@ function fedilove_customization() {
|
|||
// get the userAccountId to check against the href /account/NUM on the messages
|
||||
// so we can apply different style to my messages
|
||||
if (fediloveData.myAccountId === undefined) {
|
||||
mastodon_get('/api/v1/accounts/verify_credentials', {}, function(data) {
|
||||
fediloveMastodon.get('/api/v1/accounts/verify_credentials', {}, function(data) {
|
||||
const json = JSON.parse(data);
|
||||
if (json !== undefined) {
|
||||
fediloveData.myAccountId = json.id;
|
||||
|
@ -432,6 +444,10 @@ function fedilove_customization() {
|
|||
0% {position: relative; left: 0}
|
||||
100% {position: relative; left: 95%}
|
||||
}
|
||||
@keyframes nopeMeet {
|
||||
0% {position: relative; top: 0}
|
||||
100% {position: relative; top: 95vh}
|
||||
}
|
||||
`;
|
||||
document.body.appendChild(style);
|
||||
}
|
||||
|
@ -619,6 +635,10 @@ function fedilove_customization() {
|
|||
fediloveUI.meetPageGoToCurrentAccount(swiperightBol)
|
||||
});
|
||||
|
||||
// remove discarded accounts from timeline (temporal, if /federated is reloaded, blocked accounts won't show either)
|
||||
for (var accId of fediloveData.tmpDiscardedAccounts)
|
||||
$('article[data-account='+accId+']').parent().remove();
|
||||
|
||||
// make sure only the wanted items in timeline are shown
|
||||
const _this = setInterval(function()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue