def new_message_cb(self, conversation, msg): sender_addr = msg.get_sender_addr() # safe == False because messages sent by me also go through this path sender = user_from_addr(self.community, sender_addr, safe=False) if sender: sender_nick = sender.get('nick') if get_debug_mode() and sender.get('hops') != None: sender_nick += ':%d' % sender.get('hops') else: sender_nick = TP_NICK_DEFAULT if not self.has_storebutton(conversation): store, button = self.new_storebutton(conversation) if conversation.is_community(): notificationmsg = 'Chat activity on %s community' % conversation.tag() self.notification.notify(notificationmsg) else: self.notification.user_notify(sender, 'has spoken to you') else: store, button = self.get_storebutton(conversation) ctime = int(msg.get_ctime()[0]) tstr = iso_date_time(t=ctime, dispdate=False, dispsecs=False) msgid = msg.get_msgid() children = conversation.get_children(msgid, []) # NOTE: first column is of type gobject.TYPE_PYOBJECT because # glib strings are not binary safe icon = None if msg.error: icon = self.warning_icon row_data = [msgid, tstr, '<' + sender_nick + '> ', msg.get_msg(), icon] # if message has children it is sorted to the list such # that it is inserted before all its children if children: row = None for row in store: if row[self.COL_MSGID] in children: break store.insert_before(row.iter, row_data) else: riter = store.append(row_data) if self.active_conversation == conversation and self.atbottom: self.chat_tw.scroll_to_cell(store.get_path(riter)) # announce activity on conversation return self.activity(conversation)
def announce_user(self, user): """ Report a new user to plugins and subsystems """ if user == self.myself: self.notify.notify('Announce bug, not announcing myself') return self.activeusers[user] = None if get_debug_mode() or user.get('friend'): appearsmsg = 'appears' hops = user.get('hops') if hops != None: appearsmsg += ' at %d hops distance' % hops self.notify.user_notify(user, appearsmsg) if self.community_gui != None: self.community_gui.user_appears(user) for plugin in get_plugins(): plugin.user_appears(user)
def construct_profile_info_str(self): def heading(s): # Returns a heading string s formatted with pango markup and # a new-line return '<span color="slategray" weight="bold" size="large">%s</span>\n' % pango_escape(s) def field(s): value = self.com.get(s) if value != None: return '%s: %s\n' % (field_descriptions[s], pango_escape(str(value))) else: return '' def join_list(l): out = [] for s in l: value = self.com.get(s) if value != None: out.append(pango_escape(str(value))) if len(out) > 0: return ', '.join(out) + '\n' else: return '' s = heading(self.com.get('name')) s += field('location') s += field('www') s += field('description') if get_debug_mode(): s += heading('Debug information') s += field('v') s += field('iconversion') s += field('myiconversion') return s
def denounce_user(self, user): try: self.activeusers.pop(user) except KeyError: # we got a false bye-bye message return if not user.is_present(): return if get_debug_mode(): self.notify.user_notify(user, 'disappears') user.set('ip', None) user.set('port', None) self.depart_user(user) if self.community_gui != None: self.community_gui.user_disappears(user) for plugin in get_plugins(): plugin.user_disappears(user) if user.dirty: self.save_user(user)
def construct_profile_info_str(self): def heading(s): # Returns a heading string s formatted with pango markup and # a new-line return '<span color="slategray" weight="bold" size="large">%s</span>\n' % pango_escape(s) def field(s): value = self.user.get(s) if value != None: return '<b>%s:</b> %s\n' % (field_descriptions[s], pango_escape(str(value))) else: return '' def join_list(l): out = [] for s in l: value = self.user.get(s) if value != None: out.append(pango_escape(str(value))) if len(out) > 0: return ', '.join(out) + '\n' else: return '' s = heading(self.user.get('nick')) s += field('name') s += join_list(('age', 'gender')) s += field('birth_date') s += join_list(('city', 'state', 'country')) s += field('phone_numbers') s += field('email') s += field('www') s += field('occupation') s += field('languages') s += field('description') s += heading('Last contact') l = [] for (t, location) in self.user.log(): ss = t if len(location) > 0: ss += '\n(at %s)' %(location) l.append(ss) if len(l) == 0: l = ['never'] s += pango_escape('\n'.join(l)) + '\n' if get_debug_mode(): s += heading('Debug information') s += field('uid') s += field('ip') s += field('port') s += field('hops') s += field('status_icon') s += field('v') s += field('faceversion') s += field('myfaceversion') return s