|
@@ -3,7 +3,8 @@ from django.http import Http404
|
|
|
from django.utils.translation import ugettext as _
|
|
|
from misago.apps.threadtype.list import ThreadsListBaseView, ThreadsListModeration
|
|
|
from misago.conf import settings
|
|
|
-from misago.models import Forum, Thread
|
|
|
+from misago import messages
|
|
|
+from misago.models import Forum, Thread, User
|
|
|
from misago.readstrackers import ThreadsTracker
|
|
|
from misago.utils.pagination import make_pagination
|
|
|
from misago.apps.privatethreads.mixins import TypeMixin
|
|
@@ -37,3 +38,31 @@ class ThreadsListView(ThreadsListBaseView, ThreadsListModeration, TypeMixin):
|
|
|
for thread in qs_threads[self.pagination['start']:self.pagination['stop']]:
|
|
|
thread.is_read = tracker_forum.is_read(thread)
|
|
|
self.threads.append(thread)
|
|
|
+
|
|
|
+ def threads_actions(self):
|
|
|
+ return (('leave', _("Leave threads")),)
|
|
|
+
|
|
|
+ def action_leave(self, ids):
|
|
|
+ left = 0
|
|
|
+ for thread in self.threads:
|
|
|
+ if thread.pk in ids:
|
|
|
+ try:
|
|
|
+ user = thread.participants.get(id=self.request.user.pk)
|
|
|
+ thread.participants.remove(user)
|
|
|
+ thread.threadread_set.filter(id=user.pk).delete()
|
|
|
+ thread.watchedthread_set.filter(id=user.pk).delete()
|
|
|
+ user.sync_pds = True
|
|
|
+ user.save(force_update=True)
|
|
|
+ left +=1
|
|
|
+ # If there are no more participants in thread, remove it
|
|
|
+ if thread.participants.count() == 0:
|
|
|
+ thread.delete()
|
|
|
+ # Nope, see if we removed ourselves
|
|
|
+ else:
|
|
|
+ self.thread.set_checkpoint(self.request, 'left')
|
|
|
+ except User.DoesNotExist:
|
|
|
+ pass
|
|
|
+ if left:
|
|
|
+ messages.success(self.request, _('You have left selected private threads.'), 'threads')
|
|
|
+ else:
|
|
|
+ messages.info(self.request, _('You have left no private threads.'), 'threads')
|