blob: 6ca2817f13f17b4d0329420b1b4824aa2c081ca1 [file] [log] [blame]
Rushabh Mehtafdea9662012-02-27 18:03:54 +05301import webnotes
2
3@webnotes.whitelist()
4def get_list(arg=None):
5 """get list of messages"""
6 webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
7 webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
8 webnotes.form_dict['user'] = webnotes.session['user']
9
10 if webnotes.form_dict['contact'] == webnotes.session['user']:
Rushabh Mehta07a36a42012-02-27 18:17:57 +053011 # set all messages as read
12 webnotes.conn.sql("""UPDATE `tabComment Widget Record`
13 set docstatus = 1 where comment_doctype in ('My Company', 'Message')
14 and comment_docname = %s
15 """, webnotes.user.name)
16
17 # return messages
Rushabh Mehtafdea9662012-02-27 18:03:54 +053018 return webnotes.conn.sql("""select * from `tabComment Widget Record`
19 where (owner=%(contact)s or comment_docname=%(user)s)
20 and comment_doctype in ('My Company', 'Message')
21 order by creation desc
22 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
23 else:
24 return webnotes.conn.sql("""select * from `tabComment Widget Record`
25 where (owner=%(contact)s and comment_docname=%(user)s)
26 or (owner=%(user)s and comment_docname=%(contact)s)
27 and comment_doctype in ('My Company', 'Message')
28 order by creation desc
29 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
30
31
32@webnotes.whitelist()
33def get_active_users(arg=None):
34 return webnotes.conn.sql("""select name from tabProfile
35 where enabled=1 and
36 name not in ('Administrator', 'Guest')
37 order by first_name""", as_dict=1)
38
39@webnotes.whitelist()
40def post(arg=None):
41 """post message"""
42 import json
43 arg = json.loads(arg)
44 from webnotes.model.doc import Document
45 d = Document('Comment Widget Record')
46 d.comment = arg['txt']
47 d.comment_docname = arg['contact']
48 d.comment_doctype = 'Message'
49 d.save()
50