forked from MarseyWorld/MarseyWorld
add chat mention notifs
parent
4da8250ad2
commit
e3f6f44718
|
@ -36,6 +36,7 @@ class ChatMembership(Base):
|
||||||
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||||
chat_id = Column(Integer, ForeignKey("chats.id"), primary_key=True)
|
chat_id = Column(Integer, ForeignKey("chats.id"), primary_key=True)
|
||||||
notification = Column(Boolean, default=False)
|
notification = Column(Boolean, default=False)
|
||||||
|
mentions = Column(Integer, default=0)
|
||||||
created_utc = Column(Integer)
|
created_utc = Column(Integer)
|
||||||
|
|
||||||
user = relationship("User")
|
user = relationship("User")
|
||||||
|
|
|
@ -815,13 +815,14 @@ class User(Base):
|
||||||
Comment.deleted_utc == 0,
|
Comment.deleted_utc == 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
return notifs.count() + self.chats_notifications_count + self.modmail_notifications_count + self.post_notifications_count + self.modaction_notifications_count + self.offsite_notifications_count
|
return notifs.count() + self.chat_mentions_notifications_count + self.chats_notifications_count + self.modmail_notifications_count + self.post_notifications_count + self.modaction_notifications_count + self.offsite_notifications_count
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def normal_notifications_count(self):
|
def normal_notifications_count(self):
|
||||||
return self.notifications_count \
|
return self.notifications_count \
|
||||||
- self.message_notifications_count \
|
- self.message_notifications_count \
|
||||||
|
- self.chat_mentions_notifications_count \
|
||||||
- self.chats_notifications_count \
|
- self.chats_notifications_count \
|
||||||
- self.modmail_notifications_count \
|
- self.modmail_notifications_count \
|
||||||
- self.post_notifications_count \
|
- self.post_notifications_count \
|
||||||
|
@ -844,6 +845,11 @@ class User(Base):
|
||||||
|
|
||||||
return notifs.count()
|
return notifs.count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def chat_mentions_notifications_count(self):
|
||||||
|
return g.db.query(func.sum(ChatMembership.mentions)).filter_by(user_id=self.id).one()[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def chats_notifications_count(self):
|
def chats_notifications_count(self):
|
||||||
|
@ -943,6 +949,8 @@ class User(Base):
|
||||||
return ''
|
return ''
|
||||||
elif self.message_notifications_count > 0:
|
elif self.message_notifications_count > 0:
|
||||||
return 'messages'
|
return 'messages'
|
||||||
|
elif self.chat_mentions_notifications_count > 0:
|
||||||
|
return 'chat_mentions'
|
||||||
elif self.chats_notifications_count > 0:
|
elif self.chats_notifications_count > 0:
|
||||||
return 'chats'
|
return 'chats'
|
||||||
elif self.modmail_notifications_count > 0:
|
elif self.modmail_notifications_count > 0:
|
||||||
|
@ -961,6 +969,7 @@ class User(Base):
|
||||||
colors = {
|
colors = {
|
||||||
'': '#dc3545',
|
'': '#dc3545',
|
||||||
'messages': '#d8910d',
|
'messages': '#d8910d',
|
||||||
|
'chat_mentions': '#dd1ae0',
|
||||||
'chats': '#008080',
|
'chats': '#008080',
|
||||||
'modmail': '#f15387',
|
'modmail': '#f15387',
|
||||||
'posts': '#0000ff',
|
'posts': '#0000ff',
|
||||||
|
|
|
@ -146,7 +146,7 @@ def speak(data, v):
|
||||||
g.db.delete(existing)
|
g.db.delete(existing)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
alrdy_here = list(online[request.referrer].keys())
|
alrdy_here = set(online[request.referrer].keys())
|
||||||
memberships = g.db.query(ChatMembership).options(load_only(ChatMembership.user_id)).filter(
|
memberships = g.db.query(ChatMembership).options(load_only(ChatMembership.user_id)).filter(
|
||||||
ChatMembership.chat_id == chat_id,
|
ChatMembership.chat_id == chat_id,
|
||||||
ChatMembership.user_id.notin_(alrdy_here),
|
ChatMembership.user_id.notin_(alrdy_here),
|
||||||
|
@ -162,6 +162,18 @@ def speak(data, v):
|
||||||
url = f'{SITE_FULL}/chat/{chat.id}'
|
url = f'{SITE_FULL}/chat/{chat.id}'
|
||||||
push_notif(uids, title, body, url)
|
push_notif(uids, title, body, url)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
notify_users = NOTIFY_USERS(chat_message.text, v) - alrdy_here
|
||||||
|
memberships = g.db.query(ChatMembership).options(load_only(ChatMembership.user_id)).filter(
|
||||||
|
ChatMembership.chat_id == chat_id,
|
||||||
|
ChatMembership.user_id.in_(notify_users),
|
||||||
|
)
|
||||||
|
for membership in memberships:
|
||||||
|
membership.mentions += 1
|
||||||
|
g.db.add(membership)
|
||||||
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"id": chat_message.id,
|
"id": chat_message.id,
|
||||||
"quotes": chat_message.quotes,
|
"quotes": chat_message.quotes,
|
||||||
|
|
|
@ -88,6 +88,7 @@ def chat(v, chat_id):
|
||||||
else:
|
else:
|
||||||
if not session.get("GLOBAL") and membership:
|
if not session.get("GLOBAL") and membership:
|
||||||
membership.notification = False
|
membership.notification = False
|
||||||
|
membership.mentions = 0
|
||||||
g.db.add(membership)
|
g.db.add(membership)
|
||||||
g.db.commit() #to clear notif count
|
g.db.commit() #to clear notif count
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ def clear(v):
|
||||||
chat_memberships = g.db.query(ChatMembership).filter_by(user_id=v.id, notification=True)
|
chat_memberships = g.db.query(ChatMembership).filter_by(user_id=v.id, notification=True)
|
||||||
for membership in chat_memberships:
|
for membership in chat_memberships:
|
||||||
membership.notification = False
|
membership.notification = False
|
||||||
|
membership.mentions = 0
|
||||||
g.db.add(membership)
|
g.db.add(membership)
|
||||||
|
|
||||||
v.last_viewed_modmail_notifs = int(time.time())
|
v.last_viewed_modmail_notifs = int(time.time())
|
||||||
|
@ -143,7 +144,7 @@ def notifications_messages(v):
|
||||||
def notifications_chats(v):
|
def notifications_chats(v):
|
||||||
sq = g.db.query(ChatMessage.created_utc, ChatMessage.chat_id).distinct(ChatMessage.chat_id).order_by(ChatMessage.chat_id, ChatMessage.created_utc.desc()).subquery()
|
sq = g.db.query(ChatMessage.created_utc, ChatMessage.chat_id).distinct(ChatMessage.chat_id).order_by(ChatMessage.chat_id, ChatMessage.created_utc.desc()).subquery()
|
||||||
|
|
||||||
chats = g.db.query(Chat, ChatMembership.notification) \
|
chats = g.db.query(Chat, ChatMembership.notification, ChatMembership.mentions) \
|
||||||
.join(ChatMembership, and_(Chat.id == ChatMembership.chat_id, ChatMembership.user_id == v.id)) \
|
.join(ChatMembership, and_(Chat.id == ChatMembership.chat_id, ChatMembership.user_id == v.id)) \
|
||||||
.join(sq, Chat.id == sq.c.chat_id) \
|
.join(sq, Chat.id == sq.c.chat_id) \
|
||||||
.order_by(sq.c.created_utc.desc()).all()
|
.order_by(sq.c.created_utc.desc()).all()
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-3{% if request.path == '/notifications/chats' %} active{% endif %}" href="/notifications/chats">
|
<a class="nav-link py-3{% if request.path == '/notifications/chats' %} active{% endif %}" href="/notifications/chats">
|
||||||
Chats {% if v.chats_notifications_count %}<span class="font-weight-bold" style="color:#008080">({{v.chats_notifications_count}})</span>{% endif %}
|
Chats {% if v.chat_mentions_notifications_count %}<span class="font-weight-bold" style="color:#dd1ae0">({{v.chat_mentions_notifications_count}})</span>{% endif %} {% if v.chats_notifications_count %}<span class="font-weight-bold" style="color:#008080">({{v.chats_notifications_count}})</span>{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if v.admin_level >= PERMS['VIEW_MODMAIL'] %}
|
{% if v.admin_level >= PERMS['VIEW_MODMAIL'] %}
|
||||||
|
@ -64,11 +64,14 @@
|
||||||
{% if request.path == '/notifications/chats' %}
|
{% if request.path == '/notifications/chats' %}
|
||||||
<table class="mt-4 ml-md-3" style="max-width:1000px">
|
<table class="mt-4 ml-md-3" style="max-width:1000px">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for chat, notification in notifications %}
|
{% for chat, notification, mentions in notifications %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="/chat/{{chat.id}}">
|
<a href="/chat/{{chat.id}}">
|
||||||
{{chat.name}}
|
{{chat.name}}
|
||||||
|
{% if mentions %}
|
||||||
|
<span class="notif-chats notif-count ml-1" style="padding-left:4.5px;background:#dd1ae0">{{mentions}}</span>
|
||||||
|
{% endif %}
|
||||||
{% if notification %}
|
{% if notification %}
|
||||||
<i class="fas fa-circle ml-2 text-small" style="color:#008080"></i>
|
<i class="fas fa-circle ml-2 text-small" style="color:#008080"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table chat_memberships add column mentions int not null default 0;
|
||||||
|
alter table chat_memberships alter column mentions drop default;
|
Loading…
Reference in New Issue