Example #1
0
def window_for_sms(convo):
    '''
    For a conversation with an SMS number, looks up contact infos for a buddy
    that matches and returns a conversation with that buddy.
    '''
    log.info('window_for_sms: %r', convo)
    thread_check()

    buddy_sms = smsize(convo.buddy.name)

    keys = []

    # 'aim_dotsyntax1': {'alias': '',
    #                    'sms': [u'4567891000', u'17248406085']},
    for infokey, infodict in profile.blist.info.iteritems():
        try:
            sms_numbers = infodict['sms']
        except KeyError:
            pass
        else:
            for s in list(sms_numbers):
                try:
                    sms = smsize(s)
                except ValueError:
                    log.critical("invalid SMS number in infodict[%r]['sms']: %r", infokey, s)
                    sms_numbers.remove(s)
                else:
                    if buddy_sms == sms:
                        keys += [infokey]
    if not keys:
        log.info('no matching sms numbers found')
        return convo

    conn = convo.protocol

    for key in keys:
        if key.startswith('Metacontact #'):
            continue #TODO: metacontact-sms association

        buddyname, proto  = info_key_tuple(key)

        #TODO: use something SERVICE_MAP in buddyliststore.py to make sure
        # digsby/jabber and aim/icq work correctly.
        if conn.protocol == proto and conn.has_buddy(buddyname):
            return conn.convo_for(conn.get_buddy(buddyname))

    return convo
Example #2
0
def search_for_buddy(metas, convo, sms):
    for win in ImWinPanel.all():
        with traceguard:
            c = win.Conversation

            # already talking to this buddy?
            if c is convo:
                LOG('direct conversation object match: win: %r, convo: %r', win, convo)
                return win

            # is this an SMS message?
            if validate_sms(convo.buddy.name):
                for num in win.SMS:
                    if validate_sms(num):
                        if smsize(num) == smsize(convo.buddy.name):
                            return win

            # chat messages will go only to windows with matching conversation objects.
            if convo.ischat != win.convo.ischat:
                continue

            # is there a window already open talking to another contact in this
            # contact's metacontact?
            winbud = win.Buddy
            if winbud is None:
                continue

            for meta in metas:
                for contact in meta:
                    if winbud == contact:
                        LOG('matched %r with %r', winbud, contact)
                        return win

                # a looser match--one that might not match "From:" but only "To:"
                for contact in meta:
                    if winbud.name == contact.name and winbud.protocol.name == contact.protocol.name:
                        LOG('loosely matched %r with %r', winbud, contact)
                        return win

            if winbud.info_key == convo.buddy.info_key:
                return win