reapply dramacoin-transfers on top of master
This commit is contained in:
parent
ff31fe7b89
commit
5526f5e682
4 changed files with 106 additions and 15 deletions
|
@ -261,10 +261,18 @@ function post(url, callback, errortext) {
|
||||||
xhr.send(form);
|
xhr.send(form);
|
||||||
};
|
};
|
||||||
|
|
||||||
function post_toast(url, callback) {
|
function post_toast(url, callback, data) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("POST", url, true);
|
xhr.open("POST", url, true);
|
||||||
var form = new FormData()
|
var form = new FormData()
|
||||||
|
|
||||||
|
if(typeof data === 'object' && data !== null) {
|
||||||
|
for(let k of Object.keys(data)) {
|
||||||
|
form.append(k, data[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
form.append("formkey", formkey());
|
form.append("formkey", formkey());
|
||||||
xhr.withCredentials=true;
|
xhr.withCredentials=true;
|
||||||
|
|
||||||
|
@ -280,13 +288,20 @@ function post_toast(url, callback) {
|
||||||
} else if (xhr.status >= 300 && xhr.status < 400) {
|
} else if (xhr.status >= 300 && xhr.status < 400) {
|
||||||
window.location.href = JSON.parse(xhr.response)["redirect"]
|
window.location.href = JSON.parse(xhr.response)["redirect"]
|
||||||
} else {
|
} else {
|
||||||
data=JSON.parse(xhr.response);
|
try {
|
||||||
|
data=JSON.parse(xhr.response);
|
||||||
$('#toast-post-error').toast('dispose');
|
|
||||||
$('#toast-post-error').toast('show');
|
$('#toast-post-error').toast('dispose');
|
||||||
document.getElementById('toast-post-error-text').innerText = data["error"];
|
$('#toast-post-error').toast('show');
|
||||||
return false
|
document.getElementById('toast-post-error-text').innerText = data["error"];
|
||||||
|
return false
|
||||||
|
} catch(e) {
|
||||||
|
$('#toast-post-success').toast('dispose');
|
||||||
|
$('#toast-post-error').toast('dispose');
|
||||||
|
$('#toast-post-error').toast('show');
|
||||||
|
document.getElementById('toast-post-error-text').innerText = "Error. Try again later.";
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -396,4 +411,4 @@ $('.mention-user').click(function (event) {
|
||||||
|
|
||||||
window.location.href='/@' + $(this).data('original-name');
|
window.location.href='/@' + $(this).data('original-name');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,6 +34,42 @@ def suicide(v, username):
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
@app.get("/@<username>/coins")
|
||||||
|
@auth_required
|
||||||
|
def get_coins(v, username):
|
||||||
|
user = get_user(username)
|
||||||
|
if user is not None: return {"coins": user.coins}, 200
|
||||||
|
else: return {"error": "invalid_user"}, 404
|
||||||
|
|
||||||
|
@app.post("/@<username>/transfer_coins")
|
||||||
|
@auth_required
|
||||||
|
@validate_formkey
|
||||||
|
def transfer_coins(v, username):
|
||||||
|
receiver = get_user(username)
|
||||||
|
|
||||||
|
if receiver is None: return {"error": "That user doesn't exist."}, 404
|
||||||
|
|
||||||
|
if receiver.id != v.id:
|
||||||
|
amount = request.form.get("amount", "")
|
||||||
|
amount = int(amount) if amount.isdigit() else None
|
||||||
|
|
||||||
|
if amount is None or amount <= 0: return {"error": f"Invalid amount of {app.config['SITE_NAME']}coins."}, 400
|
||||||
|
if v.coins < amount: return {"error": f"You don't have enough {app.config['SITE_NAME']}coins"}, 400
|
||||||
|
if amount < 100: return {"error": f"You have to gift at least 100 {app.config['SITE_NAME']}coins."}, 400
|
||||||
|
|
||||||
|
v.coins -= amount
|
||||||
|
receiver.coins += amount
|
||||||
|
g.db.add(receiver)
|
||||||
|
g.db.add(v)
|
||||||
|
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
|
transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['SITE_NAME']}coins!"
|
||||||
|
send_notification(v.id, receiver, transfer_message)
|
||||||
|
return {"message": f"{amount} {app.config['SITE_NAME']}coins transferred!"}, 200
|
||||||
|
|
||||||
|
return "", 204
|
||||||
|
|
||||||
@app.get("/leaderboard")
|
@app.get("/leaderboard")
|
||||||
@auth_desired
|
@auth_desired
|
||||||
def leaderboard(v):
|
def leaderboard(v):
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
<div><img src="{{v.profile_url}}" class="profile-pic-35"></div>
|
<div><img src="{{v.profile_url}}" class="profile-pic-35"></div>
|
||||||
<div class="text-left pl-2">
|
<div class="text-left pl-2">
|
||||||
<div style="color: #{{v.namecolor}}" class="text-small font-weight-bold {% if v.animatedname %}{% if v.patron %}patron{% else %}leaderboard{% endif %}{% endif %}">{{v.username}}</div>
|
<div style="color: #{{v.namecolor}}" class="text-small font-weight-bold {% if v.animatedname %}{% if v.patron %}patron{% else %}leaderboard{% endif %}{% endif %}">{{v.username}}</div>
|
||||||
<div class="text-small-extra text-purple"><i class="fad fa-coins mr-1"></i>{{v.coins}} {{"SITE_NAME" | app_config}}coins</div>
|
<div class="text-small-extra text-purple"><i class="fad fa-coins mr-1"></i><span id="user-coins-amount">{{v.coins}}</span> {{"SITE_NAME" | app_config}}coins</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
@ -176,4 +176,4 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -54,6 +54,38 @@
|
||||||
if (audio.paused) audio.play();
|
if (audio.paused) audio.play();
|
||||||
}, {once : true});
|
}, {once : true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transferCoins() {
|
||||||
|
let t = event.target;
|
||||||
|
t.disabled = true;
|
||||||
|
|
||||||
|
post_toast("/@{{ u.username }}/transfer_coins",
|
||||||
|
xhr => {
|
||||||
|
if(xhr.status == 200) {
|
||||||
|
fetch("/@{{ u.username }}/coins")
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(m => document.getElementById("profile-coins-amount").innerText = m["coins"])
|
||||||
|
|
||||||
|
fetch("/@{{ v.username }}/coins")
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(m => document.getElementById("user-coins-amount").innerText = m["coins"])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"amount": document.getElementById("coins-transfer-amount").value}
|
||||||
|
);
|
||||||
|
|
||||||
|
setTimeout(_ => t.disabled = false, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleElement(group, id) {
|
||||||
|
for(let el of document.getElementsByClassName(group)) {
|
||||||
|
if(el.id != id) {
|
||||||
|
el.classList.add('d-none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById(id).classList.toggle('d-none');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<textarea id="userid" style="display: none;">{% if u.song %}{{u.id}}{% else %}nosong{% endif %}</textarea>
|
<textarea id="userid" style="display: none;">{% if u.song %}{{u.id}}{% else %}nosong{% endif %}</textarea>
|
||||||
<div class="row d-none d-md-block">
|
<div class="row d-none d-md-block">
|
||||||
|
@ -119,7 +151,8 @@
|
||||||
{% if u.customtitle %}<p class="font-weight-bolder" style="color: #{{u.titlecolor}}">{{u.customtitle | safe}}</p>{% endif %}
|
{% if u.customtitle %}<p class="font-weight-bolder" style="color: #{{u.titlecolor}}">{{u.customtitle | safe}}</p>{% endif %}
|
||||||
|
|
||||||
<div class="font-weight-bolder">
|
<div class="font-weight-bolder">
|
||||||
<span>{{u.coins}}</span> {{"SITE_NAME" | app_config}}coins {% if u.stored_subscriber_count >=1 and not u.is_nofollow %}<a href="/@{{u.username}}/followers">{{u.stored_subscriber_count}} follower{{'s' if u.stored_subscriber_count != 1 else ''}}</a> {% endif %}joined <span data-toggle="tooltip" data-placement="bottom" title="" data-original-title="{{u.created_datetime}}">{{u.created_date}}</span>
|
<span id="profile-coins-amount">{{u.coins}}</span> {{"SITE_NAME" | app_config}}coins {% if u.stored_subscriber_count >=1 and not u.is_nofollow %}<a href="/@{{u.username}}/followers">{{u.stored_subscriber_count}} follower{{'s' if u.stored_subscriber_count != 1 else ''}}</a> {% endif %}joined <span data-toggle="tooltip" data-placement="bottom" title="" data-original-title="{{u.created_datetime}}">{{u.created_date}}</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% if u.bio_html %}
|
{% if u.bio_html %}
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
|
@ -136,9 +169,11 @@
|
||||||
<a id="button-unsub" class="btn btn-secondary {% if not is_following %}d-none{% endif %}" href="javascript:void(0)" onclick="post('/unfollow/{{u.username}}', callback=function(){document.getElementById('button-unsub').classList.toggle('d-none');document.getElementById('button-sub').classList.toggle('d-none');})">Unfollow</a>
|
<a id="button-unsub" class="btn btn-secondary {% if not is_following %}d-none{% endif %}" href="javascript:void(0)" onclick="post('/unfollow/{{u.username}}', callback=function(){document.getElementById('button-unsub').classList.toggle('d-none');document.getElementById('button-sub').classList.toggle('d-none');})">Unfollow</a>
|
||||||
<a id="button-sub" class="btn btn-primary {% if is_following or u.is_nofollow or u.is_blocked %}d-none{% endif %}" href="javascript:void(0)" onclick="post('/follow/{{u.username}}', callback=function(){document.getElementById('button-sub').classList.toggle('d-none');document.getElementById('button-unsub').classList.toggle('d-none');})">Follow</a>
|
<a id="button-sub" class="btn btn-primary {% if is_following or u.is_nofollow or u.is_blocked %}d-none{% endif %}" href="javascript:void(0)" onclick="post('/follow/{{u.username}}', callback=function(){document.getElementById('button-sub').classList.toggle('d-none');document.getElementById('button-unsub').classList.toggle('d-none');})">Follow</a>
|
||||||
|
|
||||||
<a class="btn btn-primary" href="javascript:void(0)" onclick="document.getElementById('message').classList.toggle('d-none')">Message</a>
|
<a class="btn btn-primary" href="javascript:void(0)" onclick="toggleElement('profile-toggleable', 'message')">Message</a>
|
||||||
|
|
||||||
<a class="btn btn-primary" href="javascript:void(0)" onclick="post('/@{{u.username}}/suicide', function(){window.location.reload(true);})">Get them help</a>
|
<a class="btn btn-primary" href="javascript:void(0)" onclick="post('/@{{u.username}}/suicide', function(){window.location.reload(true);})">Get them help</a>
|
||||||
<form class="d-none" id="message" action="/@{{u.username}}/message" method="post">
|
<a class="btn btn-primary" href="javascript:void(0)" onclick="toggleElement('profile-toggleable', 'coin-transfer')">Gift {{"SITE_NAME" | app_config}}coins</a>
|
||||||
|
<form class="d-none profile-toggleable" id="message" action="/@{{u.username}}/message" method="post">
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<textarea id="input-message" form="message" name="message" rows="3" class="form-control" required></textarea>
|
<textarea id="input-message" form="message" name="message" rows="3" class="form-control" required></textarea>
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
|
@ -155,6 +190,11 @@
|
||||||
<input type="submit" value="Submit" class="btn btn-primary mt-3">
|
<input type="submit" value="Submit" class="btn btn-primary mt-3">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div class="d-none mt-3 profile-toggleable" id="coin-transfer">
|
||||||
|
<input id="coins-transfer-amount" class="form-control" name="amount" type="number">
|
||||||
|
<button class="btn btn-primary mt-3" onclick="transferCoins()">Gift</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% elif v and v.id == u.id %}
|
{% elif v and v.id == u.id %}
|
||||||
<a href="/settings/profile" class="btn btn-secondary">Edit profile</a>
|
<a href="/settings/profile" class="btn btn-secondary">Edit profile</a>
|
||||||
<a href="/views" class="btn btn-secondary">Profile views</a>
|
<a href="/views" class="btn btn-secondary">Profile views</a>
|
||||||
|
@ -567,4 +607,4 @@
|
||||||
{% include "emoji_modal.html" %}
|
{% include "emoji_modal.html" %}
|
||||||
{% include "gif_modal.html" %}
|
{% include "gif_modal.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue