Пример #1
0
def getOnlineStatus(session_id, members_infos):
    sender = getUserForSession(session_id)
    
    if not members_infos: return 'error:invalid_receiver_list'    
    members_infos = livewire_util.stringToList(members_infos)
    
    members_online_status = {}
    try:
        live_data_lock.acquireRead()
        for member_info in members_infos:
            username, relationship = livewire_util.stringToList(member_info)
            visible_status = 'offline'
            if username == sender:
                visible_status = 'online'
            elif username in live_sessions.values():
                is_online = False
                usr_data = users[username]
                if (datetime.datetime.utcnow() - usr_data.updated_at).seconds > 60:                    
                    usr_data.last_ping_time = getUserLastPingTime(getSessionIdForUsername(username))
                    usr_data.updated_at = datetime.datetime.utcnow()
                is_online = {  'everyone':lambda x: True,
                                'recruitersnfriends':lambda x: (x == 'friend' or x == 'recruiter'),
                                'friends':lambda x: (x == 'friend'),
                                'nobody':False}[usr_data.online_visibility](relationship)
                if is_online:
                    if (datetime.datetime.utcnow() - usr_data.last_ping_time).seconds > 300:
                        visible_status = 'away'
                    else:
                        visible_status = 'online'
            members_online_status[username] = visible_status
    finally:
        live_data_lock.release()
        
    return cPickle.dumps(members_online_status)    
Пример #2
0
def getInvitableUsers(sender, receivers_infos):
    actual_receivers = []
    try:
        live_data_lock.acquireRead()
        for rcvr_info in receivers_infos:
            username, relationship = livewire_util.stringToList(rcvr_info)
            if username == sender:  continue

            usr_data = None
            can_invite = True
            if users.has_key(username):
                usr_data = users[username]
            else:
                usr_data = getUserDataFromDb(username)
                if usr_data:
                    updateUserData(usr_data)
            if usr_data:
                ignore_list = usr_data.ignore_list.split(',')
                if sender in ignore_list:   continue
                
                can_invite = {  'everyone':lambda x: True,
                                'recruitersnfriends':lambda x: (x == 'friend' or x == 'recruiter'),
                                'friends':lambda x: (x == 'friend'),
                                'nobody':lambda x: False}[usr_data.invite_preference](relationship)
            if can_invite:
                actual_receivers.append(username)
    finally:
        live_data_lock.release()
    return actual_receivers
Пример #3
0
def getChatId(session_id, receiver_info, type='private'):
    sender = getUserForSession(session_id)
    if not sender:  return 'error:not_logged_in'
    
    chat_id = None
    is_public = (type == 'public')
    receiver = None
    if receiver_info:
        rcvr_info_list = livewire_util.stringToList(receiver_info)
        receiver = rcvr_info_list[0]
        chat_id = getLivePrivateChatSessionId(sender, receiver)        
        if not chat_id:
            rcvrs = getInvitableUsers(sender, [receiver_info])
            if not rcvrs:   return 'error:receiver_privacy'
    
    if not chat_id:
        chat_id = livewire_util.getUniqueId(20)
        chat_session = chatterbox.Chat(chat_id, sender, is_public)        
        try:
            chats_lock.acquireWrite()
            live_chats[chat_id] = chat_session
            if receiver:
                chat_session.addUser(receiver)
                
            for username in chat_session.members:
                if user_chat_sessions.has_key(username):
                    user_chat_sessions[username].add(chat_id)
                else:
                    user_chat_sessions[username] = set([chat_id])
        finally:
            chats_lock.release()
       
    return chat_id
Пример #4
0
def inviteUsersToChat(session_id, chat_id, receivers_infos, text):
    invited_by = getUserForSession(session_id)
    if not invited_by:  return 'error:not_logged_in'
    
    if not receivers_infos: return
    
    chat_session = getUserChat(chat_id, invited_by)
    if not chat_session:    return 'error:invalid_chat_id'

    receivers = getInvitableUsers(invited_by, livewire_util.stringToList(receivers_infos))
    if receivers:
        success, error_code, invitations = chat_session.inviteUsers(invited_by, receivers, text)
        if success:
            for invitation in invitations:
                addChatInvitation(invitation)
            str_receivers = string.join(receivers, ', ')
            chat_session.addMessage('__temp__', 'System', getDisplayName(invited_by) + ' has invited ' + string.join([getDisplayName(rcvr) for rcvr in receivers], ',') + ' to the chat.')
            chat_session.addMessage(invited_by, getDisplayName(invited_by), text, str_receivers)
        else:
            return 'error:' + error_code
Пример #5
0
def processData(data):
    if (not data.startswith('*password#')) or (not data.endswith(cmd_terminator)):
        return 'error:invalid_command_or_query'
    
    args = livewire_util.stringToList(data)
    print args
    
    if args[1] == 'query':
        query_name = args[2]
        try:
            if query_name == 'getChatId':
                return 'data:' + getChatId(args[3], args[4], args[5])
            elif query_name == 'getCurrentChatsSummary':
                return 'data:' + getCurrentChatsSummary(args[3])
            elif query_name == 'getChatMessages':
                return 'data:' + getChatMessages(args[3], args[4], args[5])
            elif query_name == 'getChatHistory':
                return 'data:' + getChatHistory(args[3], args[4])
            elif query_name == 'getChatHistory':
                return 'data:' + getChatHistory(args[3], args[4])
            elif query_name == 'getChatInfo':
                return 'data:' + getChatInfo(args[3], args[4])
            elif query_name == 'getOnlineStatus':
                return 'data:' + getOnlineStatus(args[3], args[4])
            elif query_name == 'getChatMembers':
                return 'data:' + getChatMembers(args[3])
            elif query_name == 'getAllChatIds':
                return 'data:' + getAllChatIds()
            elif query_name == 'addFile':
                return 'data:' + addFile(args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10])
            elif query_name == 'getSharedFilesInfo':
                return 'data:' + getSharedFilesInfo(args[3], args[4])
        except:
            print 'failed processing: ', data, '\n', sys.exc_info()[0], sys.exc_info()[1]
            return 'error:failed'
    
    elif args[1] == 'command':
        command_name = args[2]
        try:
            if command_name == 'updateUserSession':
                result = updateUserSession(args[3], UserData(args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12]))
            elif command_name == 'clearSession':
                result = clearSession(args[3])
            elif command_name == 'sendMessage':
                result = sendMessage(args[3], args[4], args[5], args[6])
            elif command_name == 'addUser':
                result = addUserToChat(args[3], args[4])
            elif command_name == 'addGuest':
                result = addGuestToChat(args[3], args[4], args[5], args[6], args[7], args[8], args[9])
            elif command_name == 'inviteUsers':
                result = inviteUsersToChat(args[3], args[4], args[5], args[6])
            elif command_name == 'leaveChat':
                result = leaveChat(args[3], args[4])
            elif command_name == 'fileUploadStart':
                result = fileUploadStart(args[3], args[4], args[5])
            elif command_name == 'inviteByEmail':
                result = inviteByEmail(args[3], args[4], args[5], args[6])
            elif command_name == 'buzzUser':
                result = buzzUser(args[3], args[4], args[5])
            
            if result and result.startswith('error:'):
                return 'status:' + result
            else:
                return 'status:success'
        except:
            print 'failed processing: ', data, '\n', sys.exc_info()[0], sys.exc_info()[1]
            return 'status:failed'
                
    return 'error:invalid_command_or_query'