def sendTypingNotify(self, type, dest): from tlib.oscar import MTN_FINISH, MTN_IDLE, MTN_BEGIN from glue import jid2icq try: username = jid2icq(dest) LogEvent(INFO, self.session.jabberID) if type == "begin": self.bos.sendTypingNotification(username, MTN_BEGIN) elif type == "idle": self.bos.sendTypingNotification(username, MTN_IDLE) elif type == "finish": self.bos.sendTypingNotification(username, MTN_FINISH) except AttributeError: self.alertUser(lang.get("sessionnotactive", config.jid))
def sendMessage(self, target, resource, message, noerror, xhtml, autoResponse=0): LogEvent(INFO, self.session.jabberID) from glue import jid2icq try: self.session.pytrans.serviceplugins['Statistics'].stats['OutgoingMessages'] += 1 self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID, 'OutgoingMessages', 1) uin = jid2icq(target) wantIcon = 0 if self.bos.requesticon.has_key(uin): LogEvent(INFO, self.session.jabberID, "Going to ask for target's icon.") wantIcon = 1 del self.bos.requesticon[uin] offline = 1 try: if self.legacyList.ssicontacts[uin]['presence'] != "unavailable": offline = 0 except: # well then they're online in some way pass iconSum = None iconLen = None iconStamp = None if hasattr(self, "myavatar"): iconSum = oscar.getIconSum(self.myavatar) iconLen = len(self.myavatar) iconStamp = time.time() LogEvent(INFO, self.session.jabberID, "Going to send info about our icon, length %d, cksum %d" % (iconLen, iconSum)) LogEvent(INFO, self.session.jabberID) if uin[0].isdigit(): encoding = config.encoding charset = "iso-8859-1" if self.legacyList.hasCapability(uin, "unicode"): encoding = "utf-16be" charset = "unicode" LogEvent(INFO, self.session.jabberID, "Encoding %r" % encoding) self.bos.sendMessage(uin, [[message,charset]], offline=offline, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp) self.session.sendArchive(target, self.session.jabberID, message) else: if xhtml and not config.disableXHTML: xhtml = utils.xhtml_to_aimhtml(xhtml) self.bos.sendMessage(uin, xhtml, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp) self.session.sendArchive(target, self.session.jabberID, message) else: htmlized = oscar.html(message) self.bos.sendMessage(uin, htmlized, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp) self.session.sendArchive(target, self.session.jabberID, message) except AttributeError: self.alertUser(lang.get("sessionnotactive", config.jid))
def chatStateNotification(self, dest, resource, state, withmessage=False): LogEvent(INFO, self.session.jabberID) from glue import jid2icq user = jid2icq(dest) prev_legacy_state = self.getUserVarValue(user, 'last_chatstate_event') if prev_legacy_state not in ('begin', 'idle', 'finish'): prev_legacy_state = 'finish' legacy_state = None if state == 'composing' and prev_legacy_state in ('finish', 'idle'): legacy_state = 'begin' elif state in ('paused', 'inactive') and prev_legacy_state == 'begin': legacy_state = 'idle' elif (state == 'gone' or withmessage) and prev_legacy_state in ('begin', 'idle'): legacy_state = 'finish' if legacy_state: self.sendTypingNotify(legacy_state, dest) uvars = dict([]) uvars['last_chatstate_event'] = legacy_state self.legacyList.setUserVars(user, uvars)
def sendMessage(self, target, resource, message, noerror, xhtml, autoResponse=0, jabber_mid=None): LogEvent(INFO, self.session.jabberID) from glue import jid2icq try: self.session.pytrans.serviceplugins[ 'Statistics'].stats['OutgoingMessages'] += 1 self.session.pytrans.serviceplugins['Statistics'].sessionUpdate( self.session.jabberID, 'OutgoingMessages', 1) uin = jid2icq(target) wantIcon = 0 if self.bos.requesticon.has_key(uin): LogEvent( INFO, self.session.jabberID, "Going to ask for target's icon.") wantIcon = 1 del self.bos.requesticon[uin] offline = 1 try: if self.legacyList.ssicontacts[uin]['presence'] != "unavailable": offline = 0 except: # well then they're online in some way pass iconSum = None iconLen = None iconStamp = None if hasattr(self, "myavatar"): iconSum = oscar.getIconSum(self.myavatar) iconLen = len(self.myavatar) iconStamp = time.time() LogEvent(INFO, self.session.jabberID, "Going to send info about our icon, length %d, cksum %d" % ( iconLen, iconSum)) LogEvent(INFO, self.session.jabberID) if uin[0].isdigit(): # ICQ users if jabber_mid and int(self.bos.selfSettings['msgconfirm_recvmode']) == 1 and self.legacyList.hasCapability(uin, 'serv_rel'): cookie = ''.join( [chr(random.randrange(0, 127)) for i in xrange(8)]) # cookie c_time = int(time.time()) uvars = {} msg_query = self.getUserVarValue( uin, 'wait_for_confirm_msg_query') if len(msg_query) == 0: msg_query = dict([]) elif len(msg_query) > 4: # query already too long del_msg_query = dict([]) for every in msg_query: e_id, e_res, e_time = msg_query[every] # sent more than 60 second ago and receiving not # confirmed if int(c_time) > int(e_time) + 60: # message was lost del_msg_query[every] = msg_query[every] if len(del_msg_query): for every in del_msg_query: del msg_query[every] msg_query[cookie] = (jabber_mid, resource, c_time) # update query uvars['wait_for_confirm_msg_query'] = msg_query self.legacyList.setUserVars(uin, uvars) log.msg('Waiting for confirmations msg query: %s' % msg_query) else: cookie = None # if contact uses utf-8 via serv_rel and necessary see on it # or if contact has unicode & serl_rel caps and utf-8 via # serv_rel preferred if (str(self.getUserVarValue(uin, 'utf8_msg_using')) == '1' and int(self.bos.selfSettings['utf8_messages_sendmode']) == 1) or (self.legacyList.hasCapability(uin, 'serv_rel') and self.legacyList.hasCapability(uin, 'unicode') and int(self.bos.selfSettings['utf8_messages_sendmode']) == 2 and not offline): # send as type-2 message self.bos.sendMessageType2(uin, message, cookie=cookie) else: # send as usual message, choose encoding # Unicode for offline messages if offline and int(self.bos.settingsOptionValue('offline_messages_sendenc')) == 0: charset = 'unicode' # utf-16be # local encoding for offline messages elif offline and int(self.bos.settingsOptionValue('offline_messages_sendenc')) == 1: charset = 'custom' # single-byte encoding else: # autodetect (both for offline and online messages) # contact has unicode cap if self.legacyList.hasCapability(uin, 'unicode'): charset = 'unicode' # utf-16be else: charset = 'custom' # single-byte encoding self.bos.sendMessage(uin, [[message, charset]], offline=offline, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp, cookie=cookie) self.session.sendArchive( target, self.session.jabberID, message) else: # AIM users if xhtml and not config.disableXHTML: xhtml = utils.xhtml_to_aimhtml(xhtml) self.bos.sendMessage( uin, xhtml, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp) self.session.sendArchive( target, self.session.jabberID, message) else: htmlized = oscar.html(message) self.bos.sendMessage( uin, htmlized, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp) self.session.sendArchive( target, self.session.jabberID, message) except AttributeError: self.alertUser(lang.get("sessionnotactive", config.jid))