Showing OPML backup exports and imports in activity popover. Closes #1646.

This commit is contained in:
Samuel Clay 2022-03-14 11:06:01 -04:00
parent 5d25d6d75e
commit 9912f3ad8e
7 changed files with 64 additions and 4 deletions

View file

@ -2,6 +2,7 @@ from newsblur_web.celeryapp import app
from django.contrib.auth.models import User
from apps.feed_import.models import UploadedOPML, OPMLImporter
from apps.reader.models import UserSubscription
from apps.social.models import MActivity
from utils import log as logging
@ -18,5 +19,7 @@ def ProcessOPML(user_id):
user.profile.send_upload_opml_finished_email(feed_count)
logging.user(user, "~FR~SBOPML upload (task): ~SK%s~SN~SB~FR feeds" % (feed_count))
MActivity.new_opml_import(user_id=user.pk, count=feed_count)
UserSubscription.queue_new_feeds(user)
UserSubscription.refresh_stale_feeds(user, exclude_new=True)

View file

@ -63,6 +63,8 @@ def opml_upload(request):
feeds = UserSubscription.objects.filter(user=request.user).values()
payload = dict(folders=folders, feeds=feeds)
logging.user(request, "~FR~SBOPML Upload: ~SK%s~SN~SB~FR feeds" % (len(feeds)))
from apps.social.models import MActivity
MActivity.new_opml_import(user_id=request.user.pk, count=len(feeds))
UserSubscription.queue_new_feeds(request.user)
UserSubscription.refresh_stale_feeds(request.user, exclude_new=True)
else:
@ -80,6 +82,9 @@ def opml_export(request):
exporter = OPMLExporter(user)
opml = exporter.process()
from apps.social.models import MActivity
MActivity.new_opml_export(user_id=user.pk)
response = HttpResponse(opml, content_type='text/xml; charset=utf-8')
response['Content-Disposition'] = 'attachment; filename=NewsBlur-%s-%s.opml' % (
user.username,

View file

@ -758,6 +758,9 @@ class Profile(models.Model):
msg.attach(filename, opml, 'text/xml')
msg.send(fail_silently=True)
from apps.social.models import MActivity
MActivity.new_opml_export(user_id=self.user.pk, automated=True)
logging.user(self.user, "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)
def send_first_share_to_blurblog_email(self, force=False):

View file

@ -3157,7 +3157,7 @@ class MActivity(mongo.Document):
if categories:
activities_db = activities_db.filter(category__in=categories)
if public:
activities_db = activities_db.filter(category__nin=['star', 'feedsub'])
activities_db = activities_db.filter(category__nin=['star', 'feedsub', 'opml_import', 'opml_export'])
activities_db = activities_db[offset:offset+limit+1]
has_next_page = len(activities_db) > limit
@ -3219,6 +3219,28 @@ class MActivity(mongo.Document):
for dupe in dupes[1:]:
dupe.delete()
@classmethod
def new_opml_import(cls, user_id, count):
if count <= 0:
return
params = {
"user_id": user_id,
"category": 'opml_import',
'content': f"You imported an OPML file with {count} sites"
}
cls.objects.create(**params)
@classmethod
def new_opml_export(cls, user_id, automated=False):
params = {
"user_id": user_id,
"category": 'opml_export',
'content': "You exported an OPML backup of your subscriptions"
}
if automated:
params['content'] = "An automatic OPML backup was emailed to you"
cls.objects.create(**params)
@classmethod
def new_follow(cls, follower_user_id, followee_user_id):

View file

@ -6932,6 +6932,23 @@
self.close_social_profile();
self.open_feed(feed_id);
});
$.targetIs(e, { tagSelector: '.NB-activity-opml_import' }, function($t, $p){
e.preventDefault();
self.close_interactions_popover();
self.close_social_profile();
NEWSBLUR.reader.open_intro_modal({
'page_number': 2,
'force_import': true
});
});
$.targetIs(e, { tagSelector: '.NB-activity-opml_export' }, function($t, $p){
e.preventDefault();
self.close_interactions_popover();
self.close_social_profile();
self.open_account_modal();
});
// = One-offs =====================================================

View file

@ -113,7 +113,7 @@ NEWSBLUR.InteractionsPopover = NEWSBLUR.ReaderPopover.extend({
// load_interactions_page or load_activities_page
this.model['load_'+this.options.tab+'_page'](this.page, _.bind(function(resp, type) {
console.log(["type", type, this.options.tab]);
// console.log(["type", type, this.options.tab]);
if (type != this.options.tab) return;
this.fetching = false;
this.hide_loading();

View file

@ -90,6 +90,16 @@
</div>
{% endif %}
{% if activity.category == 'opml_import' or activity.category == 'opml_export' %}
<img class="NB-interaction-photo" src="{{ MEDIA_URL }}img/icons/circular/g_icn_folder_rss.png">
<div class="NB-interaction-title">
{{ activity.content }}
</div>
<div class="NB-interaction-date">
{{ activity.time_since }} ago
</div>
{% endif %}
</li>
{% endfor %}
</ul>