From bcd11de6f4bbf1418bd11e66f1fb0fc3d8ccb203 Mon Sep 17 00:00:00 2001 From: Miguel Angel G Date: Sat, 25 Jan 2020 06:24:11 -0600 Subject: [PATCH 01/13] Add UI and interaction to setup tips on comments --- app/app/settings.py | 5 +++ app/assets/v2/js/activity.js | 2 +- app/assets/v2/js/status.js | 36 +++++++++++++++++-- .../templates/profiles/status_box.html | 26 ++++++++++++++ app/retail/templates/shared/activity.html | 7 +++- app/retail/views.py | 11 ++++++ app/townsquare/views.py | 2 ++ 7 files changed, 85 insertions(+), 4 deletions(-) diff --git a/app/app/settings.py b/app/app/settings.py index d619cd88211..2b09eacd692 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -754,3 +754,8 @@ RE_MARKET_LIMIT = env.int('RE_MARKET_LIMIT', default=2) MINUTES_BETWEEN_RE_MARKETING = env.int('MINUTES_BETWEEN_RE_MARKETING', default=60) + +TOKENS = [ + {'name': 'DAI', 'symbol': 'DAI'}, + {'name': 'Ethereum', 'symbol': 'ETH'} +] \ No newline at end of file diff --git a/app/assets/v2/js/activity.js b/app/assets/v2/js/activity.js index 3885826159e..2330b521b33 100644 --- a/app/assets/v2/js/activity.js +++ b/app/assets/v2/js/activity.js @@ -218,7 +218,7 @@ $(document).ready(function() { for (var i = 0; i < response['comments'].length; i++) { var comment = sanitizeAPIResults(response['comments'])[i]; var timeAgo = timedifferenceCvrt(new Date(comment['created_on'])); - var html = '
  • ' + comment['profile_handle'] + ', ' + timeAgo + ': ' + comment['comment'] + '
  • '; + var html = '
  • ' + comment['profile_handle'] + ', ' + timeAgo + ': ' + comment['comment'] + '
  • '; $target.append(html); } diff --git a/app/assets/v2/js/status.js b/app/assets/v2/js/status.js index d88af922aa7..e0ffdbef524 100644 --- a/app/assets/v2/js/status.js +++ b/app/assets/v2/js/status.js @@ -19,7 +19,6 @@ $(document).ready(function() { return; } }); - // dropdown for usernames when @ is detected in the post $('#textarea').on('input', function(e) { const lastWord = e.target.value.split(' ').pop(); @@ -141,6 +140,12 @@ $(document).ready(function() { } }); + $('#btn_attach').on('click', function() { + const el = $('#attach-dropdown'); + + el.toggle(); + }); + function submitStatusUpdate() { const data = new FormData(); const message = $('#textarea'); @@ -160,6 +165,33 @@ $(document).ready(function() { data.append('resourceProvider', 'youtube'); data.append('resourceId', last_video); } + + const attach = $('#attach-dropdown')[0].style.display; + const attachAmount = $('#attachAmount').val(); + const attachToken = $('#attachToken').val(); + + if (attach !== 'none' && !isNaN(attachAmount)) { + data.append('attachToken', attachToken); + data.append('attachAmount', attachAmount); + /* + sendTip( + email, + github_url, + from_name, + username, + amountInEth, + comments_public, + comments_priv, + from_email, + accept_tos, + tokenAddress, + expires, + success_callback, + failure_callback, + false + ); + */ + } fetch('/api/v0.1/activity', { method: 'post', @@ -192,4 +224,4 @@ $(document).ready(function() { }) .catch(err => console.log('Error ', err)); } -}); +}); \ No newline at end of file diff --git a/app/dashboard/templates/profiles/status_box.html b/app/dashboard/templates/profiles/status_box.html index 660acf44c82..2d639d7f5b2 100644 --- a/app/dashboard/templates/profiles/status_box.html +++ b/app/dashboard/templates/profiles/status_box.html @@ -20,10 +20,36 @@ {% endfor %} {% endif %} + + + diff --git a/app/retail/views.py b/app/retail/views.py index ee88fd5ce50..e9454471c98 100644 --- a/app/retail/views.py +++ b/app/retail/views.py @@ -1205,7 +1205,7 @@ def activity(request): 'page': page, 'target': f'/activity?what={what}&trending_only={trending_only}&page={next_page}', 'title': _('Activity Feed'), - 'TOKENS': request.user.profile.token_approvals.all(), + 'TOKENS': request.user.profile.token_approvals.all() if request.user.is_authenticated else [], } context["activities"] = [a.view_props_for(request.user) for a in page] @@ -1224,6 +1224,7 @@ def create_status_update(request): resource_id = request.POST.get('resourceId', '') attach_token = request.POST.get('attachToken', '') attach_amount = request.POST.get('attachAmount', '') + attach_token_name = request.POST.get('attachTokenName', '') tx_id = request.POST.get('attachTxId', '') kwargs = { @@ -1244,7 +1245,8 @@ def create_status_update(request): amount = float(attach_amount) kwargs['metadata']['attach'] = { 'amount': amount, - 'token': attach_token + 'token': attach_token, + 'token_name': attach_token_name, } if resource == 'content': diff --git a/app/townsquare/views.py b/app/townsquare/views.py index 3a8fd69822a..a00ba71c9a6 100644 --- a/app/townsquare/views.py +++ b/app/townsquare/views.py @@ -9,9 +9,9 @@ from django.utils import timezone from app.utils import get_profile -from dashboard.models import Activity, HackathonEvent, get_my_earnings_counter_profiles, get_my_grants +from dashboard.models import Activity, HackathonEvent, get_my_earnings_counter_profiles, get_my_grants, Profile from kudos.models import Token -from marketing.mails import comment_email, mention_email, new_action_request +from marketing.mails import comment_email, mention_email, new_action_request, tip_comment_awarded_email from ratelimit.decorators import ratelimit from .models import Announcement, Comment, Flag, Like, Offer, OfferAction @@ -202,7 +202,7 @@ def town_square(request): 'announcements': announcements, 'is_subscribed': is_subscribed, 'offers_by_category': offers_by_category, - 'TOKENS': request.user.profile.token_approvals.all(), + 'TOKENS': request.user.profile.token_approvals.all() if request.user.is_authenticated else [], } response = TemplateResponse(request, 'townsquare/index.html', context) if request.GET.get('tab'): @@ -262,18 +262,15 @@ def api(request, activity_id): # award request elif request.POST.get('method') == 'award': - print('==== Award') comment = get_object_or_404(Comment, id=int(request.POST['comment'])) - print('=== Has comment') if request.user.profile.id == activity.profile.id and comment.activity_id == activity.id: recipient_profile = comment.profile activity.tip.username = recipient_profile.username activity.tip.recipient_profile = recipient_profile activity.tip.save() - print('+==== Has recipient ') comment.tip = activity.tip comment.save() - print('Associate tip with comment') + tip_comment_awarded_email(comment, [recipient_profile.email]) # flag request elif request.POST.get('method') == 'flag': @@ -297,7 +294,7 @@ def api(request, activity_id): comment_email(comment, to_emails) username_pattern = re.compile(r'@(\S+)') - mentioned_usernames = re.findall(username_pattern, title) + mentioned_usernames = re.findall(username_pattern, comment.comment) mentioned_emails = set(Profile.objects.filter(handle__in=mentioned_usernames).values_list('email', flat=True)) # Don't send emails again to users who already received a comment email deduped_emails = mentioned_emails.difference(to_emails) @@ -305,7 +302,9 @@ def api(request, activity_id): elif request.GET.get('method') == 'comment': comments = activity.comments.order_by('created_on') - profile = request.user.profile + if has_perms: + profile = request.user.profile + comments = [{ 'activity': comment.activity_id, 'comment': comment.comment, @@ -314,7 +313,7 @@ def api(request, activity_id): 'modified_on': comment.modified_on, 'profile': comment.profile_id, 'profile_handle': comment.profile_handle, - 'redeem_link': comment.redeem_link if comment.tip and comment.tip.recipient_profile_id == profile.id else '', + 'redeem_link': comment.redeem_link if has_perms and comment.tip and comment.tip.recipient_profile_id == profile.id else '', 'tip': bool(comment.tip) } for comment in comments] response['has_tip'] = False From 194a1ccdb1da7032db6dd52d1aed5da6d05b680a Mon Sep 17 00:00:00 2001 From: Miguel Angel G Date: Tue, 25 Feb 2020 01:28:57 -0600 Subject: [PATCH 04/13] Fix error on migrations --- app/assets/v2/js/activity.js | 19 +++---------------- .../migrations/0013_merge_20200225_0709.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 app/townsquare/migrations/0013_merge_20200225_0709.py diff --git a/app/assets/v2/js/activity.js b/app/assets/v2/js/activity.js index 42751d32cc7..23ab18968fb 100644 --- a/app/assets/v2/js/activity.js +++ b/app/assets/v2/js/activity.js @@ -519,27 +519,14 @@ $(document).ready(function() {
    ${the_comment}
    - ${can_award && `
    + ${can_award && ` `} - ${comment['redeem_link'] && `
    + ` || ''} + ${comment['redeem_link'] && ` Redeem tip`} - - - ${is_comment_owner ? - `| ` - : ''} - ${show_tip ? ` - | - ${Math.round(1000 * comment['tip_count_eth']) / 1000} - - ` : ''} - diff --git a/app/townsquare/migrations/0013_merge_20200225_0709.py b/app/townsquare/migrations/0013_merge_20200225_0709.py new file mode 100644 index 00000000000..b8fbdd45741 --- /dev/null +++ b/app/townsquare/migrations/0013_merge_20200225_0709.py @@ -0,0 +1,14 @@ +# Generated by Django 2.2.4 on 2020-02-25 07:09 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('townsquare', '0012_matchranking_match_curve'), + ('townsquare', '0011_merge_20200218_0637'), + ] + + operations = [ + ] From 8d64f048d7108e96bc82792d7f4657f754fe4379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Angel=20Gordi=C3=A1n?= Date: Thu, 5 Mar 2020 03:50:06 -0600 Subject: [PATCH 05/13] Update shareactivity.html --- app/townsquare/templates/townsquare/shared/shareactivity.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/townsquare/templates/townsquare/shared/shareactivity.html b/app/townsquare/templates/townsquare/shared/shareactivity.html index cb607110919..dad459b149a 100644 --- a/app/townsquare/templates/townsquare/shared/shareactivity.html +++ b/app/townsquare/templates/townsquare/shared/shareactivity.html @@ -58,7 +58,7 @@ - +
    From fcea83f3114d83ce73322cfbef6f4ddcc4c55b57 Mon Sep 17 00:00:00 2001 From: Miguel Angel G Date: Wed, 20 May 2020 15:14:45 -0500 Subject: [PATCH 12/13] Update migration --- ...0019_comment_tip.py => 0020_auto_20200520_2014.py} | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) rename app/townsquare/migrations/{0019_comment_tip.py => 0020_auto_20200520_2014.py} (52%) diff --git a/app/townsquare/migrations/0019_comment_tip.py b/app/townsquare/migrations/0020_auto_20200520_2014.py similarity index 52% rename from app/townsquare/migrations/0019_comment_tip.py rename to app/townsquare/migrations/0020_auto_20200520_2014.py index 745be20112c..75d333fa83e 100644 --- a/app/townsquare/migrations/0019_comment_tip.py +++ b/app/townsquare/migrations/0020_auto_20200520_2014.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.4 on 2020-04-29 07:10 +# Generated by Django 2.2.4 on 2020-05-20 20:14 from django.db import migrations, models import django.db.models.deletion @@ -7,8 +7,8 @@ class Migration(migrations.Migration): dependencies = [ - ('dashboard', '0102_auto_20200422_1452'), - ('townsquare', '0018_comment_is_edited'), + ('dashboard', '0112_auto_20200520_1454'), + ('townsquare', '0019_pinnedpost'), ] operations = [ @@ -17,4 +17,9 @@ class Migration(migrations.Migration): name='tip', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='awards', to='dashboard.Tip'), ), + migrations.AlterField( + model_name='pinnedpost', + name='activity', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pin', to='dashboard.Activity'), + ), ] From 2d3ea3225ce5d977a51b499a94aa6c27070b67e9 Mon Sep 17 00:00:00 2001 From: Miguel Angel G Date: Tue, 26 May 2020 09:29:45 -0500 Subject: [PATCH 13/13] Fix migration erros --- ...0020_auto_20200520_2014.py => 0021_comment_tip.py} | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) rename app/townsquare/migrations/{0020_auto_20200520_2014.py => 0021_comment_tip.py} (52%) diff --git a/app/townsquare/migrations/0020_auto_20200520_2014.py b/app/townsquare/migrations/0021_comment_tip.py similarity index 52% rename from app/townsquare/migrations/0020_auto_20200520_2014.py rename to app/townsquare/migrations/0021_comment_tip.py index 75d333fa83e..3f30a5bd580 100644 --- a/app/townsquare/migrations/0020_auto_20200520_2014.py +++ b/app/townsquare/migrations/0021_comment_tip.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.4 on 2020-05-20 20:14 +# Generated by Django 2.2.4 on 2020-05-26 14:29 from django.db import migrations, models import django.db.models.deletion @@ -7,8 +7,8 @@ class Migration(migrations.Migration): dependencies = [ - ('dashboard', '0112_auto_20200520_1454'), - ('townsquare', '0019_pinnedpost'), + ('dashboard', '0114_auto_20200522_0730'), + ('townsquare', '0020_auto_20200521_1020'), ] operations = [ @@ -17,9 +17,4 @@ class Migration(migrations.Migration): name='tip', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='awards', to='dashboard.Tip'), ), - migrations.AlterField( - model_name='pinnedpost', - name='activity', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pin', to='dashboard.Activity'), - ), ]