Add acct @user@domain on chat header + allow more messages even if party did not respond any

This commit is contained in:
Bofh 2020-12-29 17:49:35 +01:00
parent 719b9f21f0
commit b15694c349
4 changed files with 43 additions and 21 deletions

View File

@ -19,7 +19,8 @@
<img alt="Your possible crush" src="/missing.png"/>
</div>
<div id="name">
<span>...</span>
<a href="/">...</a>
<span>-</span>
</div>
<div id="back">
<a href="/direct">

View File

@ -25,8 +25,10 @@
}
}
window.fediloveFunctions.emojifyText = emojifyText;
window.fediloveEvents.onGotEmojifyTextFunction();
if (window.fediloveFunctions !== undefined) {
window.fediloveFunctions.emojifyText = emojifyText;
window.fediloveEvents.onGotEmojifyTextFunction();
}
return emojifyText(accountName, emojis, $autoplayGifs)
}
}

View File

@ -67,6 +67,7 @@ div#chat-party-global {
max-width: 60em;
margin: auto;
padding: .2em 1em;
padding-right: 0;
div#image {
display: flex;
@ -82,9 +83,15 @@ div#chat-party-global {
display: flex;
width: 100%;
padding-left: 1em;
span {
a {
font-weight: bold;
margin: auto 0;
color: #000;
}
span {
margin: auto 0;
margin-left: .5em;
color: #8a8a8a;
}
}

View File

@ -45,7 +45,7 @@ function api_status_fav(dom, status_id) {
function api_send_message() {
// the message is composed from the current chat Acct (@user@domain) + the compose textarea value
const text = fediloveData.chatCurrentAcct + ' ' + $('div#chat-compose-global textarea').val();
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);
@ -72,20 +72,28 @@ var fediloveUI = {
}
}, 150);
},
paintChatAvatarAndName: function(avatar, name) {
paintChatAvatarAndName: function(accid, acct, avatar, name) {
accid = accid || null;
acct = acct || null;
avatar = avatar || null;
name = name || null;
if (avatar === null || name === null) {
if ((accid+acct+avatar+name) === 0) {
accid = 0;
avatar = '/missing.png';
name = '...';
} else {
fediloveData.chatAvatarCache = { avatar: avatar, name: name };
fediloveData.chatAvatarCache = {
id: accid, acct: acct,
avatar: avatar, name: name
};
}
// to-do: check is it XSS safe to add it like this :) !!
// to-do: check is it XSS safe to add it like this :) ??
$('div#chat-party-global > div#image > img').attr('src', avatar);
$('div#chat-party-global > div#name > span').html(name);
$('div#chat-party-global > div#name > a').html(name);
$('div#chat-party-global > div#name > span').text(acct);
if (accid != 0) $('div#chat-party-global > div#name > a').attr('href', `/accounts/${accid}`);
}
};
@ -97,7 +105,7 @@ var fediloveApi = {
},
getChatLastMessageId: function(andUuid) {
andUuid = andUuid || false;
const lastUuid = $('div.the-list article.status-article.partymsg').last().attr('id');
const lastUuid = $('div.the-list article.status-article').last().attr('id');
if (lastUuid === undefined) {
return undefined;
}
@ -115,7 +123,6 @@ var fediloveApi = {
var fediloveFunctions = {};
var fediloveData = {
chatAvatarCache: undefined,
chatCurrentAcct: undefined,
gotEmojifyTextFunction: false
};
var fediloveEvents = {
@ -126,10 +133,8 @@ var fediloveEvents = {
// dont do anything if avatar and name is cached
if (fediloveData.chatAvatarCache !== undefined) return;
fediloveData.chatCurrentAcct = `@${data.account.acct}`;
// waits for the React code to call the "onGotEmojifyTextFunction" so we can use it
var waitForEmojifyAndDo = function(avatar, dname, emojis) {
var waitForEmojifyAndDo = function(accid, acct, avatar, dname, emojis) {
var count = 0;
var _this = setInterval(function() {
if (count > 100) {
@ -137,7 +142,7 @@ var fediloveEvents = {
return;
}
if (fediloveData.gotEmojifyTextFunction) {
fediloveUI.paintChatAvatarAndName(avatar, fediloveFunctions.emojifyText(dname, emojis));
fediloveUI.paintChatAvatarAndName(accid, acct, avatar, fediloveFunctions.emojifyText(dname, emojis));
clearInterval(_this);
}
count++;
@ -147,15 +152,21 @@ var fediloveEvents = {
// if the message is mine, search which account is doing it for,
// and do the same with the party's data
if (localStorage.store_userAccountId === data.account.id) {
mastodon_get(`/api/v1/accounts/${data.in_reply_to_account_id}`, {}, function(newData) {
var account_id = data.in_reply_to_account_id;
if (account_id === null && data.mentions.length > 0) {
account_id = data.mentions[0].id;
}
if (account_id === null || account_id === undefined) return;
mastodon_get(`/api/v1/accounts/${account_id}`, {}, function(newData) {
var json = JSON.parse(newData);
if (json !== undefined) {
waitForEmojifyAndDo( json.avatar, json.display_name, json.emojis );
waitForEmojifyAndDo( account_id, `@${json.acct}`, json.avatar, json.display_name, json.emojis );
}
});
} else {
// this means the message we are loading is from the other party, so we continue as normal
waitForEmojifyAndDo( data.account.avatar, data.account.display_name, data.account.emojis );
waitForEmojifyAndDo( data.account.id, `@${data.account.acct}`, data.account.avatar,
data.account.display_name, data.account.emojis );
}
}
},
@ -169,7 +180,7 @@ var fediloveEvents = {
if (window.location.pathname.startsWith('/statuses/')) {
if (fediloveFunctions.updateStatusAndThread !== undefined) {
fediloveFunctions.updateStatusAndThread( fediloveApi.getCurrentInstance(), fediloveApi.getAccessToken(),
window.location.pathname, fediloveApi.getChatStatusId() );
window.location.pathname, fediloveApi.getChatMessageId() );
fediloveUI.scrollChatToLastItem();
}
}
@ -197,7 +208,8 @@ function fedilove_customization() {
// *******
// load cached avatars or paint it empty (automated process after this will fill it)
if (fediloveData.chatAvatarCache !== undefined) {
fediloveUI.paintChatAvatarAndName( chatAvatarData.avatar, chatAvataData.name );
fediloveUI.paintChatAvatarAndName( fediloveData.chatAvatarCache.id, fediloveData.chatAvatarCache.acct,
fediloveData.chatAvatarCache.avatar, fediloveData.chatAvatarCache.name );
} else {
fediloveUI.paintChatAvatarAndName();
}