def getChatHistory(request, session_id): try: chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '') if not chat_id: return ajaxian.getFailureResp('error:invalid_chatId') data = livewire_client.query('getChatHistory', [session_id, chat_id]) if data.startswith('error:'): return ajaxian.getFailureResp(data) messages = cPickle.loads(data) return ajaxian.getSuccessResp(messages) except: return ajaxian.getFailureResp('error:unknown')
def getSharedFolder(request, session_id): try: chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '') if not chat_id: return ajaxian.getFailureResp('error:invalid_chatId') data = livewire_client.query('getSharedFilesInfo', [session_id, chat_id]) if data.startswith('error:'): return ajaxian.getFailureResp(data) file_infos = cPickle.loads(data) return ajaxian.getSuccessResp(file_infos) except: return ajaxian.getFailureResp('error:unknown')
def getChatId(request, session_id): try: receiver = dataplus.dictGetVal(request.REQUEST, 'receiver', '') receiver_info = '' if receiver: receiver_infos = getRelationships(request, [receiver]) receiver_info = receiver_infos[0] data = livewire_client.query('getChatId', [session_id, receiver_info, 'private']) if data: return ajaxian.getSuccessResp(data) else: return ajaxian.getFailureResp('error:connection_error') except: return ajaxian.getFailureResp('error:unknown')
def getOnlineStatus(request, usernames, relationship='', session_id=None): try: if not session_id: session_id = dataplus.dictGetVal(request.COOKIES, 'session_id', '') member_infos = [] if relationship: member_infos = [dataplus.listToString([username,relationship]) for username in usernames] else: member_infos = getRelationships(request, usernames) members_online_status = livewire_client.query('getOnlineStatus', [session_id, dataplus.listToString(member_infos)]) members_online_status = cPickle.loads(members_online_status) return members_online_status except: dict = {} for username in usernames: dict[username] = False return dict
def handle(request): if request.method == 'POST': upload_id = dataplus.dictGetVal(request.REQUEST, 'uploadId') if not upload_id: return getRenderedResponse('', False, 'invalid_upload_id') chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId') if not chat_id: return getRenderedResponse(upload_id, False, 'invalid_chat_id') success, error_code, filename, file_url, file_type, size, thumbnail_url = saveFile(request, chat_id, 'uploadFile') if success: session_id = request.COOKIES['session_id'] result = livewire_client.query('addFile', [session_id, chat_id, filename, file_url, file_type, size, thumbnail_url, '']) if result.startswith('error:'): return getRenderedResponse(upload_id, False, result[6:]) return getRenderedResponse(upload_id, True, '') else: return getRenderedResponse(upload_id, False, error_code)
def sendMessage(request, session_id): try: chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '') text = dataplus.dictGetSafeVal(request.REQUEST, 'text', '') receivers = dataplus.dictGetVal(request.REQUEST, 'receivers', '') last_message_id = dataplus.dictGetVal(request.REQUEST, 'lastMessageId','0') if not chat_id: return ajaxian.getFailureResp('error:invalid_chatId') if receivers: receivers = dataplus.listToString(receivers.split(',')) data = livewire_client.query('getChatMessages', [session_id, chat_id, last_message_id]) if data.startswith('error:'): return ajaxian.getFailureResp(data) data = cPickle.loads(data) result = livewire_client.command('sendMessage',[session_id, chat_id, text, receivers]) if result.startswith('error:'): return ajaxian.getFailureResp(result) return ajaxian.getSuccessResp(data) except: return ajaxian.getFailureResp('error:unknown')
def handle(request): chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId') if not chat_id: return siteaction.render_to_response('404.html') result = livewire_client.query('getChatMembers', [chat_id]) if result.startswith('error:'): return siteaction.render_to_response('404.html') chat_members = cPickle.loads(result) if chat_members: html = '<table style="width:460px">\r\n' for member_info in chat_members: member_data = member_info.split(':') if member_data[0].startswith('#'): html += '<tr>\r\n<td style="text-align:center;width:160px;vertical-align:top">' + \ '<img src="' + dataplus.getStaticUrl(config.chat_guest_img_72) + '" alt="guest" />' + \ '<br />' + member_data[1] + '</td>' + \ '<td style="width:300px;"><span class="small-text" style="text-align:justify">' + \ 'Guest</span></td>\r\n</tr>\r\n' else: account = models.Account.objects.get(username=member_data[0]) image_url = '' small_desc = '' if account.account_type == 'U': user = models.User.objects.get(account=account) image_url = dataplus.getStaticUrl(user.image_size2_file_path) small_desc = dataplus.getPreviewText(user.hilite,200) elif account_type == 'A': pass html += '<tr>\r\n<td style="text-align:center;width:160px;vertical-align:top">' + \ '<a href="/profiles/' + account.username + '" >' + \ '<img src="' + image_url + '" alt="' + account.name + '" /></a><br />' + \ '<a href="/profiles/' + account.username + '" >' + account.name + '</a></td>' + \ '<td style="width:300px;"><span class="small-text" style="text-align:justify">' + \ small_desc + '</span></td>\r\n</tr>\r\n' html += '</table>\r\n' return siteaction.render_to_response('chat/startchat.htm', {'chat_id':chat_id, 'chat_members_html':html})
def getCurrentChatsSummary(request, session_id): try: chat_summary = cPickle.loads(livewire_client.query('getCurrentChatsSummary',[session_id])) return ajaxian.getSuccessResp(chat_summary) except: return ajaxian.getFailureResp('error:unknown')
def startConf(request, session_id): try: chat_id = livewire_client.query('getChatId', [session_id, '', 'public']) return ajaxian.getSuccessResp(chat_id) except: return ajaxian.getFailureResp('error:unknown')
def handle(request): try: chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '') if not chat_id: return ajaxian.getFailureResp('error:invalid_chatId') new_user = dataplus.dictGetVal(request.REQUEST, 'newUser') new_guest = dataplus.dictGetVal(request.REQUEST, 'newGuest') session_id = '' if new_user or new_guest: result = '' if new_user: session_id = request.COOKIES['session_id'] result = livewire_client.command('addUser', [chat_id, new_user]) elif new_guest: session_id = '#' + dataplus.getUniqueId(19) result = livewire_client.command('addGuest',[chat_id,session_id, new_guest, 'Invited Guest.', dataplus.getStaticUrl(config.chat_guest_img_50), dataplus.getStaticUrl(config.chat_guest_img_72), dataplus.getStaticUrl(config.chat_guest_img_128)]) if(result != 'success'): if result == 'error:max_users_exceeded': return HttpResponse('Failed to join chat. The chat session has exceeded the maximum number of users.') elif result == 'error:invalid_chat_id': return siteaction.render_to_response('500.html') else: return HttpResponse('Failed to join chat.') else: session_id = request.COOKIES['session_id'] data = livewire_client.query('getChatInfo', [session_id, chat_id]) if data == 'error:invalid_chat_id': return HttpResponse('This chat does not exist.') chat_info = cPickle.loads(data) is_member = False friends_select_html = '' self = chat_info['self'] current_username = self['username'] current_name = self['name'] current_user_online_status = self['online_visibility'] if not current_username.startswith('#'): try: account = models.Account.objects.get(username=current_username) is_member = True if account.account_type == 'U': friends = models.User.objects.filter(friends__username=account.username).order_by('name') friends_select_html = hotmetal.elemSelect([('Select', '')], friends, lambda x:x.name, lambda x:x.username, '', 'name="friends_select" id="friends_select" style="width:160px"') except: pass response = siteaction.render_to_response('chat/chatbox.htm', { 'current_chat_id':chat_id, 'current_username':current_username, 'current_name':current_name, 'current_user_online_status':current_user_online_status, 'is_member':is_member, 'friends_select_html':friends_select_html}) expiry_time = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(days=90), "%a, %d-%b-%Y %H:%M:%S GMT") response.set_cookie('session_id', session_id, expires=expiry_time) return response except: return HttpResponse('Invalid Chat.')