1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Converting api:chat

This commit is contained in:
spl0k 2014-04-05 17:03:15 +02:00
parent 595b65606b
commit fd8a99e362

View File

@ -19,8 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from flask import request from flask import request
from web import app from web import app, store
from db import ChatMessage, session from db import ChatMessage
@app.route('/rest/getChatMessages.view', methods = [ 'GET', 'POST' ]) @app.route('/rest/getChatMessages.view', methods = [ 'GET', 'POST' ])
def get_chat(): def get_chat():
@ -30,9 +30,9 @@ def get_chat():
except: except:
return request.error_formatter(0, 'Invalid parameter') return request.error_formatter(0, 'Invalid parameter')
query = ChatMessage.query.order_by(ChatMessage.time) query = store.find(ChatMessage).order_by(ChatMessage.time)
if since: if since:
query = query.filter(ChatMessage.time > since) query = query.find(ChatMessage.time > since)
return request.formatter({ 'chatMessages': { 'chatMessage': [ msg.responsize() for msg in query ] }}) return request.formatter({ 'chatMessages': { 'chatMessage': [ msg.responsize() for msg in query ] }})
@ -42,7 +42,10 @@ def add_chat_message():
if not msg: if not msg:
return request.error_formatter(10, 'Missing message') return request.error_formatter(10, 'Missing message')
session.add(ChatMessage(user = request.user, message = msg)) chat = ChatMessage()
session.commit() chat.user_id = request.user.id
chat.message = msg
store.add(chat)
store.commit()
return request.formatter({}) return request.formatter({})