mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
Notify group message reply
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from signals import *
|
from signals import *
|
||||||
from handlers import *
|
from handlers import *
|
||||||
from models import GroupMessage
|
from models import GroupMessage, MessageReply
|
||||||
|
|
||||||
grpmsg_added.connect(grpmsg_added_cb, sender=GroupMessage)
|
grpmsg_added.connect(grpmsg_added_cb, sender=GroupMessage)
|
||||||
|
grpmsg_reply_added.connect(grpmsg_reply_added_cb, sender=MessageReply)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
from seaserv import ccnet_threaded_rpc
|
from seaserv import ccnet_threaded_rpc
|
||||||
|
|
||||||
from signals import grpmsg_added
|
from signals import grpmsg_added
|
||||||
|
from models import GroupMessage
|
||||||
from seahub.notifications.models import UserNotification
|
from seahub.notifications.models import UserNotification
|
||||||
|
|
||||||
def grpmsg_added_cb(sender, **kwargs):
|
def grpmsg_added_cb(sender, **kwargs):
|
||||||
@@ -18,3 +19,24 @@ def grpmsg_added_cb(sender, **kwargs):
|
|||||||
n = UserNotification(to_user=m.user_name, msg_type='group_msg',
|
n = UserNotification(to_user=m.user_name, msg_type='group_msg',
|
||||||
detail=group_id)
|
detail=group_id)
|
||||||
n.save()
|
n.save()
|
||||||
|
|
||||||
|
def grpmsg_reply_added_cb(sender, **kwargs):
|
||||||
|
msg_id = kwargs['msg_id']
|
||||||
|
reply_from_email = kwargs['from_email'] # this value may be used in future
|
||||||
|
try:
|
||||||
|
group_msg = GroupMessage.objects.get(id=msg_id)
|
||||||
|
except GroupMessage.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
UserNotification.objects.get(to_user=group_msg.from_email,
|
||||||
|
msg_type='grpmsg_reply',
|
||||||
|
detail=msg_id)
|
||||||
|
except UserNotification.DoesNotExist:
|
||||||
|
n = UserNotification(to_user=group_msg.from_email,
|
||||||
|
msg_type='grpmsg_reply',
|
||||||
|
detail=msg_id)
|
||||||
|
n.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
import django.dispatch
|
import django.dispatch
|
||||||
|
|
||||||
grpmsg_added = django.dispatch.Signal(providing_args=["group_id", "from_email"])
|
grpmsg_added = django.dispatch.Signal(providing_args=["group_id", "from_email"])
|
||||||
|
grpmsg_reply_added = django.dispatch.Signal(providing_args=["msg_id", "from_email"])
|
||||||
|
216
group/templates/group/new_msg_reply.html
Normal file
216
group/templates/group/new_msg_reply.html
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
{% extends "myhome_base.html" %}
|
||||||
|
{% load seahub_tags avatar_tags %}
|
||||||
|
|
||||||
|
{% block nav_group_class %}class="cur"{% endblock %}
|
||||||
|
|
||||||
|
{% block main_panel %}
|
||||||
|
<h2>新回复</h2>
|
||||||
|
|
||||||
|
<div class="main fleft">
|
||||||
|
<div id="group-reply">
|
||||||
|
{% if group_msgs %}
|
||||||
|
<ul class="msg-list">
|
||||||
|
{% for msg in group_msgs %}
|
||||||
|
<li class="msg w100 ovhd">
|
||||||
|
<div class="pic fleft">
|
||||||
|
<a href="{{ SITE_ROOT }}profile/{{ msg.from_email }}/">{% avatar msg.from_email 48 %}</a>
|
||||||
|
</div>
|
||||||
|
<div class="txt fright">
|
||||||
|
<div class="msg-hd">
|
||||||
|
<span class="time">{{ msg.timestamp|date:"Y-m-d H:i" }}</span>
|
||||||
|
<a href="{{ SITE_ROOT }}profile/{{ msg.from_email }}/">{{ msg.from_email|email2nickname }}</a>
|
||||||
|
</div>
|
||||||
|
<div class="msg-bd">
|
||||||
|
<p>{{ msg.message }}</p>
|
||||||
|
{% if msg.reply_cnt == 0 %}
|
||||||
|
<a class="reply op" href="#" data="{{ msg.id }}">回复</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="reply op hide" href="#" data="{{ msg.id }}">{{ msg.reply_cnt }} 回复</a>
|
||||||
|
{% endif %}
|
||||||
|
<a class="replyclose op" href="#">收起回复</a>
|
||||||
|
<ul class="reply-list">
|
||||||
|
{% if msg.reply_list %}
|
||||||
|
{% for reply in msg.reply_list %}
|
||||||
|
<li>{{ reply.message }} -- <a href="{{ SITE_ROOT }}profile/{{ reply.from_email }}/">{{ reply.nickname }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
<form class="reply-form" method="post" action="">
|
||||||
|
<input type="hidden" name="msg_id" value="{{ msg.id }}" />
|
||||||
|
<input type="text" name="message" class="text-input" />
|
||||||
|
<input type="submit" class="submit" value="回复" />
|
||||||
|
<p class="error hide">输入不能为空且应少于150个字符。</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>暂无</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_script %}
|
||||||
|
<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery-jtemplates.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
addConfirmTo($('#quit-group'), '确定要退出?');
|
||||||
|
addConfirmTo($('.cancel-share'), '确定要取消共享该目录?');
|
||||||
|
|
||||||
|
$("table tr:gt(0)").hover(
|
||||||
|
function() {
|
||||||
|
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).find('img').addClass('vh');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$('.download').click(function() {
|
||||||
|
window.open($(this).attr('data'));
|
||||||
|
});
|
||||||
|
|
||||||
|
//show profile when mouse over
|
||||||
|
var Hide_profile = '';
|
||||||
|
$('.group-member').hover(
|
||||||
|
function() {
|
||||||
|
var this_top = $(this).offset().top - $('#main').offset().top;
|
||||||
|
$(this).css('background', '#eee');
|
||||||
|
var avatar_url = $(this).children('.avatar').attr('src'),
|
||||||
|
avatar_url_array = avatar_url.split('/');
|
||||||
|
if (avatar_url_array[avatar_url_array.length-2] == 16) {//not default avatar
|
||||||
|
avatar_url_array[avatar_url_array.length-2] = 80;//choose avatar size
|
||||||
|
avatar_url = avatar_url_array.join('/');
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: $(this).children('.group-member-name').attr('href') + 'get/',
|
||||||
|
dataType: 'json',
|
||||||
|
cache: false,
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
success: function(data) {
|
||||||
|
$('#user-profile').setTemplateElement('jtemplate').processTemplate(data);
|
||||||
|
$('#user-profile .avatar').attr('src', avatar_url);
|
||||||
|
$('#user-profile').removeClass('hide');
|
||||||
|
$('#main').css('position', 'relative');
|
||||||
|
$('#add-as-contact').click(function() {
|
||||||
|
$('#add-as-contact-form').modal({appendTo: '#main'});
|
||||||
|
});
|
||||||
|
if (this_top + $('#user-profile').height() < $('#main').height()) {
|
||||||
|
$('#user-profile').css('top', this_top - 10);
|
||||||
|
} else {
|
||||||
|
$('#user-profile').css('top', $('#main').height() - $('#user-profile').height() - 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clearTimeout(Hide_profile);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).css('background', '#fff');
|
||||||
|
Hide_profile = setTimeout(function() { $('#user-profile').addClass('hide'); }, 1000);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$('#user-profile').hover(
|
||||||
|
function() {
|
||||||
|
clearTimeout(Hide_profile);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).addClass('hide');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$('.reply').click(function() {
|
||||||
|
var msg_id = $(this).attr('data'),
|
||||||
|
msg_bd = $(this).parent();
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ SITE_ROOT }}group/reply/' + msg_id + '/',
|
||||||
|
dataType: 'json',
|
||||||
|
cache: false,
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
success: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
var str = '';
|
||||||
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
|
str += '<li>' + data[i]['message'] + ' -- ' + '<a href="{{ SITE_ROOT }}profile/' + data[i]['from_email'] + '/">' + data[i]['nickname'] + '</a></li>';
|
||||||
|
}
|
||||||
|
msg_bd.children('.reply-list').html(str).removeClass('hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
msg_bd.children('.reply-form').removeClass('hide');
|
||||||
|
$(this).addClass('hide');
|
||||||
|
msg_bd.children('.replyclose').removeClass('hide');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.replyclose').click(function() {
|
||||||
|
var msg_bd = $(this).parent();
|
||||||
|
msg_bd.children('.reply-list').addClass('hide');
|
||||||
|
msg_bd.children('.reply-form').addClass('hide');
|
||||||
|
$(this).addClass('hide');
|
||||||
|
msg_bd.children('.reply').removeClass('hide');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.reply-form').each(function(){
|
||||||
|
$(this).submit(function(event) {
|
||||||
|
// prepare django csrf token
|
||||||
|
$.ajaxSetup({
|
||||||
|
beforeSend: function(xhr, settings) {
|
||||||
|
function getCookie(name) {
|
||||||
|
var cookieValue = null;
|
||||||
|
if (document.cookie && document.cookie != '') {
|
||||||
|
var cookies = document.cookie.split(';');
|
||||||
|
for (var i = 0; i < cookies.length; i++) {
|
||||||
|
var cookie = jQuery.trim(cookies[i]);
|
||||||
|
// Does this cookie string begin with the name we want?
|
||||||
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||||
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cookieValue;
|
||||||
|
}
|
||||||
|
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
||||||
|
// Only send the token to relative URLs i.e. locally.
|
||||||
|
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var form = $(this),
|
||||||
|
m_id = form.children('input[name="msg_id"]').val(),
|
||||||
|
m = $.trim(form.children('input[name="message"]').val()),
|
||||||
|
msg_bd = form.parent();
|
||||||
|
if (m && m.length <= 150) {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "{{ SITE_ROOT }}group/reply/"+m_id+"/",
|
||||||
|
dataType: 'json',
|
||||||
|
cache: false,
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
data: "message="+m,
|
||||||
|
success: function(data) {
|
||||||
|
var str = '';
|
||||||
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
|
str += '<li>' + data[i]['message'] + ' -- ' + '<a href="{{ SITE_ROOT }}profile/' + data[i]['from_email'] + '/">' + data[i]['nickname'] + '</a></li>';
|
||||||
|
}
|
||||||
|
msg_bd.children('.reply-list').html(str).attr('class', 'reply-list');
|
||||||
|
form.children('input[name="message"]').val('');
|
||||||
|
form.children('.error').attr('Class' , 'error hide');
|
||||||
|
msg_bd.children('.reply').html(data.length + ' 回复');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
form.children('.error').removeClass('hide');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
@@ -1,11 +1,12 @@
|
|||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
from views import group_list, group_info, group_member_operations, \
|
from views import group_list, group_info, group_member_operations, \
|
||||||
group_members, msg_reply
|
group_members, msg_reply, msg_reply_new
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^(?P<group_id>[\d]+)/$', group_info, name='group_info'),
|
url(r'^(?P<group_id>[\d]+)/$', group_info, name='group_info'),
|
||||||
url(r'^reply/(?P<msg_id>[\d]+)/$', msg_reply, name='msg_reply'),
|
url(r'^reply/(?P<msg_id>[\d]+)/$', msg_reply, name='msg_reply'),
|
||||||
|
url(r'^reply/new/$', msg_reply_new, name='msg_reply_new'),
|
||||||
url(r'^(?P<group_id>[\d]+)/members/$', group_members, name='group_members'),
|
url(r'^(?P<group_id>[\d]+)/members/$', group_members, name='group_members'),
|
||||||
(r'^(?P<group_id>[\d]+)/member/(?P<user_name>[^/]+)/$', group_member_operations),
|
(r'^(?P<group_id>[\d]+)/member/(?P<user_name>[^/]+)/$', group_member_operations),
|
||||||
)
|
)
|
||||||
|
@@ -12,7 +12,7 @@ from pysearpc import SearpcError
|
|||||||
|
|
||||||
from models import GroupMessage, MessageReply
|
from models import GroupMessage, MessageReply
|
||||||
from forms import MessageForm, MessageReplyForm
|
from forms import MessageForm, MessageReplyForm
|
||||||
from signals import grpmsg_added
|
from signals import grpmsg_added, grpmsg_reply_added
|
||||||
from seahub.contacts.models import Contact
|
from seahub.contacts.models import Contact
|
||||||
from seahub.notifications.models import UserNotification
|
from seahub.notifications.models import UserNotification
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
@@ -206,6 +206,13 @@ def msg_reply(request, msg_id):
|
|||||||
msg_reply.message = msg
|
msg_reply.message = msg
|
||||||
msg_reply.save()
|
msg_reply.save()
|
||||||
|
|
||||||
|
# send signal if reply other's message
|
||||||
|
if group_msg.from_email != request.user.username:
|
||||||
|
grpmsg_reply_added.send(sender=MessageReply,
|
||||||
|
msg_id=msg_id,
|
||||||
|
from_email=request.user.username)
|
||||||
|
|
||||||
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
content_type = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -232,6 +239,41 @@ def msg_reply(request, msg_id):
|
|||||||
else:
|
else:
|
||||||
return HttpResponse(status=400)
|
return HttpResponse(status=400)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def msg_reply_new(request):
|
||||||
|
grpmsg_reply_list = []
|
||||||
|
notes = UserNotification.objects.filter(to_user=request.user.username)
|
||||||
|
for n in notes:
|
||||||
|
if n.msg_type == 'grpmsg_reply':
|
||||||
|
grpmsg_reply_list.append(n.detail)
|
||||||
|
|
||||||
|
group_msgs = []
|
||||||
|
for msg_id in grpmsg_reply_list:
|
||||||
|
try:
|
||||||
|
m = GroupMessage.objects.get(id=msg_id)
|
||||||
|
# get message replies
|
||||||
|
reply_list = MessageReply.objects.filter(reply_to=m)
|
||||||
|
# get nickname
|
||||||
|
for reply in reply_list:
|
||||||
|
try:
|
||||||
|
p = Profile.objects.get(user=reply.from_email)
|
||||||
|
reply.nickname = p.nickname
|
||||||
|
except Profile.DoesNotExist:
|
||||||
|
reply.nickname = reply.from_email
|
||||||
|
|
||||||
|
m.reply_list = reply_list
|
||||||
|
group_msgs.append(m)
|
||||||
|
except GroupMessage.DoesNotExist:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# remove new group msg reply notification
|
||||||
|
UserNotification.objects.filter(to_user=request.user.username,
|
||||||
|
msg_type='grpmsg_reply').delete()
|
||||||
|
|
||||||
|
return render_to_response("group/new_msg_reply.html", {
|
||||||
|
'group_msgs': group_msgs,
|
||||||
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def group_info(request, group_id):
|
def group_info(request, group_id):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@@ -56,6 +56,14 @@
|
|||||||
<p>暂无</p>
|
<p>暂无</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<h3>留言回复</h3>
|
||||||
|
{% if has_grpmsg_reply %}
|
||||||
|
<a class="op" href="{{ SITE_ROOT }}group/reply/new/">新回复</a>
|
||||||
|
{% else %}
|
||||||
|
</p>暂无</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
10
views.py
10
views.py
@@ -546,18 +546,21 @@ def myhome(request):
|
|||||||
contacts = Contact.objects.filter(user_email=email)
|
contacts = Contact.objects.filter(user_email=email)
|
||||||
|
|
||||||
# user notifications
|
# user notifications
|
||||||
l = []
|
grpmsg_list = []
|
||||||
|
has_grpmsg_reply = False
|
||||||
notes = UserNotification.objects.filter(to_user=request.user.username)
|
notes = UserNotification.objects.filter(to_user=request.user.username)
|
||||||
for n in notes:
|
for n in notes:
|
||||||
if n.msg_type == 'group_msg':
|
if n.msg_type == 'group_msg':
|
||||||
l.append(n.detail)
|
grpmsg_list.append(n.detail)
|
||||||
|
elif n.msg_type == 'grpmsg_reply':
|
||||||
|
has_grpmsg_reply = True
|
||||||
|
|
||||||
# my groups
|
# my groups
|
||||||
groups = ccnet_threaded_rpc.get_groups(email)
|
groups = ccnet_threaded_rpc.get_groups(email)
|
||||||
groups_manage = []
|
groups_manage = []
|
||||||
groups_join = []
|
groups_join = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if str(group.id) in l:
|
if str(group.id) in grpmsg_list:
|
||||||
group.new_msg = True
|
group.new_msg = True
|
||||||
else:
|
else:
|
||||||
group.new_msg = False
|
group.new_msg = False
|
||||||
@@ -581,6 +584,7 @@ def myhome(request):
|
|||||||
"in_repos": in_repos,
|
"in_repos": in_repos,
|
||||||
"contacts": contacts,
|
"contacts": contacts,
|
||||||
"groups": groups,
|
"groups": groups,
|
||||||
|
"has_grpmsg_reply": has_grpmsg_reply,
|
||||||
"groups_manage": groups_manage,
|
"groups_manage": groups_manage,
|
||||||
"groups_join": groups_join,
|
"groups_join": groups_join,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
Reference in New Issue
Block a user