Jelajahi Sumber

알림 기능 추가

https://github.com/openNAMU/openNAMU/issues/1901
잉여개발기 (SPDV) 2 tahun lalu
induk
melakukan
8e5b417cf6
6 mengubah file dengan 50 tambahan dan 11 penghapusan
  1. 1 0
      app.py
  2. 24 4
      route/tool/func.py
  3. 16 2
      route/user_alarm.py
  4. 6 2
      route/user_alarm_delete.py
  5. 1 1
      route/user_info.py
  6. 2 2
      version.json

+ 1 - 0
app.py

@@ -473,6 +473,7 @@ app.route('/count/<name>')(user_count)
 
 app.route('/alarm')(user_alarm)
 app.route('/alarm/delete')(user_alarm_delete)
+app.route('/alarm/delete/<int:id>')(user_alarm_delete)
 
 app.route('/watch_list', defaults = { 'tool' : 'watch_list' })(user_watch_list)
 app.route('/watch_list/<everything:name>', defaults = { 'tool' : 'watch_list' })(user_watch_list_name)

+ 24 - 4
route/tool/func.py

@@ -333,10 +333,10 @@ def get_db_table_list():
     create_data['re_admin'] = ['who', 'what', 'time']
 
     # 개편 예정 (user_notice와 user_agent로 변경)
-    create_data['alarm'] = ['name', 'data', 'date']
     create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
 
     create_data['user_set'] = ['name', 'id', 'data']
+    create_data['user_notice'] = ['id', 'name', 'data', 'date', 'read']
 
     create_data['bbs_set'] = ['set_name', 'set_code', 'set_id', 'set_data']
     create_data['bbs_data'] = ['set_name', 'set_code', 'set_id', 'set_data']
@@ -655,6 +655,20 @@ def update(ver_num, set_data):
         if ver_num < 3500365:
             curs.execute(db_change("update back set data = '' where data is null"))
 
+        if ver_num < 3500370:
+            user_alarm_count = {}
+
+            curs.execute(db_change("select name, data, date, read from alarm"))
+            for db_data in curs.fetchall():
+                if db_data[0] in user_alarm_count:
+                    user_alarm_count[db_data[0]] += 1
+                else:
+                    user_alarm_count[db_data[0]] = 1
+
+                curs.execute(db_change(
+                    'insert into user_notice (id, name, data, date, read) values (?, ?, ?, ?, ?)'
+                ), [str(user_alarm_count[db_data[0]]), db_data[0], db_data[1], db_data[2], db_data[3]])
+
         conn.commit()
 
         print('Update completed')
@@ -1253,7 +1267,7 @@ def wiki_custom():
                 user_admin = '0'
                 user_acl_list = '0'
 
-            curs.execute(db_change("select count(*) from alarm where name = ?"), [ip])
+            curs.execute(db_change("select count(*) from user_notice where name = ? and read = ''"), [ip])
             count = curs.fetchall()
             user_notice = str(count[0][0]) if count else '0'
         else:
@@ -2397,9 +2411,15 @@ def add_alarm(to_user, from_user, context):
         if to_user != from_user:
             context = from_user + ' | ' + context
 
+            count = '1'
+            curs.execute(db_change("select id from user_notice where name = ? order by id + 0 desc"), [to_user])
+            db_data = curs.fetchall()
+            if db_data:
+                count = str(int(db_data[0][0]) + 1)
+
             curs.execute(db_change(
-                'insert into alarm (name, data, date) values (?, ?, ?)'
-            ), [to_user, context, get_time()])
+                'insert into user_notice (id, name, data, date, read) values (?, ?, ?, ?, "")'
+            ), [count, to_user, context, get_time()])
     
 def add_user(user_name, user_pw, user_email = '', user_encode = ''):
     with get_db_connect() as conn:

+ 16 - 2
route/user_alarm.py

@@ -8,8 +8,10 @@ def user_alarm():
         sql_num = (num * 50 - 50) if num * 50 > 0 else 0
     
         data = '<ul class="opennamu_ul">'
+
+        ip = ip_check()
     
-        curs.execute(db_change("select data, date from alarm where name = ? order by date desc limit ?, 50"), [ip_check(), sql_num])
+        curs.execute(db_change("select data, date, read, id from user_notice where name = ? order by date desc limit ?, 50"), [ip, sql_num])
         data_list = curs.fetchall()
         if data_list:
             data = '' + \
@@ -20,8 +22,20 @@ def user_alarm():
     
             for data_one in data_list:
                 data_split = data_one[0].split(' | ')
+                data_style = ''
+                if data_one[2] == '1':
+                    data_style = 'opacity: 0.75;'
                 
-                data += '<li>' + ip_pas(data_split[0]) + (' | ' + ' | '.join(data_split[1:]) if len(data_split) > 1 else '') + ' (' + data_one[1] + ')</li>'
+                data += '' + \
+                    '<li style="' + data_style + '">' + \
+                        ip_pas(data_split[0]) + (' | ' + ' | '.join(data_split[1:]) if len(data_split) > 1 else '') + \
+                        ' | ' + data_one[1] + \
+                        ' <a href="/alarm/delete/' + url_pas(data_one[3]) + '">(' + load_lang('delete') + ')</a>' + \
+                    '</li>' + \
+                ''
+
+        curs.execute(db_change("update user_notice set read = '1' where name = ?"), [ip])
+        conn.commit()
     
         data += '' + \
             '</ul>' + \

+ 6 - 2
route/user_alarm_delete.py

@@ -1,10 +1,14 @@
 from .tool.func import *
 
-def user_alarm_delete():
+def user_alarm_delete(id = ''):
     with get_db_connect() as conn:
         curs = conn.cursor()
     
-        curs.execute(db_change("delete from alarm where name = ?"), [ip_check()])
+        if id != '':
+            curs.execute(db_change("delete from user_notice where name = ? and id = ?"), [ip_check(), str(id)])
+        else:
+            curs.execute(db_change("delete from user_notice where name = ?"), [ip_check()])
+        
         conn.commit()
 
         return redirect('/alarm')

+ 1 - 1
route/user_info.py

@@ -13,7 +13,7 @@ def user_info(name = ''):
         tool_menu = ''
         
         if name == '':
-            curs.execute(db_change("select count(*) from alarm where name = ?"), [ip])
+            curs.execute(db_change("select count(*) from user_notice where name = ? and read = ''"), [ip])
             count = curs.fetchall()
             if count and count[0][0] != 0:
                 tool_menu += '<li><a class="opennamu_not_exist_link" href="/alarm">' + load_lang('alarm') + ' (' + str(count[0][0]) + ')</a></li>'

+ 2 - 2
version.json

@@ -1,7 +1,7 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC4.3-dev233",
-        "c_ver" : "3500365",
+        "r_ver" : "v3.4.6-RC5-dev1",
+        "c_ver" : "3500370",
         "s_ver" : "3500111"
     }
 }