Hey,

my SMTP is up again :-)

I see some clear problems in my current proposal, but am not really keen
on fixing them, if I have not heard anything from you, yet. I would like
to get constant feedback.
Anyway, I have some new ideas and questions as well.


New ideas:
- No need for a groupchat to be a contact. We can simply change the
roster_window not to believe it is a contact. We can hardcode at GUI
level that all groupchats go to "Groupchats" group.
- Allow contacts to be actors: contact.unsubscribe()

Questions:
- Bct, do "sessions" fit into the proposal? 
- When is the Plugin branch expected to be merged?
- When is the BOSH branch expected to be merged?

Recently, I have talked to bct and transferred some our ideas into code.
Like the class diagrams, also the code is just a 15 minutes job.


Best Regards,
steve-e

------------------------------------------
Example Coding:
------------------------------------------

class XMPPEntity(object):

        TYPE_GC = 'GROUPCHAT'
        TYPE_GC_CONTACT = 'GC_CONTACT'
        TYPE_CONTACT = 'CONTACT'
        TYPE_META_CONTACT = 'META_CONTACT'
        TYPE_TRANSPORT = 'TRANSPORT'

        def __init__(self, jid, account, entity_type, resource):
                self.jid = jid  
                self.account = account
                self.entity_type = entity_type
                self.resource = resource

        def is_groupchat(self):
                return self.entity_type == self.TYPE_GC

        def is_transport(self):
                return self.entity_type == self.TYPE_TRANSPORT

        def is_groupchat_contact(self):
                return self.entity_type == self.TYPE_GC_CONTACT

        def is_meta_contact(self):
                return self.entity_type == self.TYPE_GC

        def is_contact(self):
                return self.entity_type == self.TYPE_CONTACT


class CommonContact(XMPPEntity):

        def __init__(self, jid, account, entity_type, resource=None):
                
                XMPPEntity.__init__(self, jid=jid, account=account,
                entity_type=entity_type, resource=resource)               

                self.caps_node = None
                self.caps_hash_method = None
                self.caps_hash = None

                self.mood = {}
                self.tune = {}
                self.activity = {}

                self.show = ''
                self.status = ''
        
                self.composing_xep = None
                self.chatstate = None # chatstate of the contact
                self.our_chatstate = None

                self._nick = '' # defined by the contact itself

        def _get_name(self):
                return self._nick or self.jid.split('@')[0]

        def _get_full_jid(self):
                if self.resource:
                        return self.jid + '/' + self.resource
                return self.jid 
                
        name = property(fget=_get_name)
        full_jid = property(fget=_get_full_jid)


class Contact(CommonContact):

        def __init__(self, jid, account, resource, basement_contact):
                
                CommonContact.__init__(self, jid=jid, account=account, 
                        entity_type=self.TYPE_CONTACT, resource=resource)

                self._basement = basement_contact
                self.priority = 0

        def _get_name(self):
                return self._name or CommonContact._get_name(self)

        def __getattr__(self, name):
                return getattr(self._basement, name)


class ContactBasement:
        
        def __init__(self):
                self._given_name = '' # how we named him
                self._online_groups = []

                self.keyID = ''
                
                self.sub = ''
                self.ask = ''

        def is_observer(self):
                # XEP-0162
                is_observer = False
                #if self.sub == 'from' and not self.is_transport()\
                #and self.is_hidden_from_roster():
        #               is_observer = True
                return is_observer

        def _get_groups(self):
                if self.is_observer():
                        return [_('Observers')]
                elif not self._online_groups:
                        return [_('General')]
                return self._online_groups


class GroupchatContact(CommonContact):

        def __init__(self, groupchat, full_jid, account):

                CommonContact.__init__(self, jid=full_jid, account=account, 
                        entity_type=self.TYPE_CONTACT)

                self.groupchat = groupchat # room_jid

                self.affiliation = ''
                self.role = ''


class Groupchat(XMPPEntity):

        def __init__(self, room_jid, account):

                XMPPEntity.__init__(self, jid=room_jid, account=account,
resource=None,
                        entity_type=self.TYPE_GC)


On Mo, 2008-11-24 at 21:25 +0100, Yann Leboulanger wrote:
> Hey,
> 
> as my train got stuck in the first real winter night here, I thought it
> was the right time to make my mind about what could be improved in
> Gajim's handling of accounts and contacts.
> 
> You can see this as a first outbreak that I would like to share with you
> as soon as possible. Comments and ideas are welcome.  :-)
> 
> See "1. accounts.png"
> 
> I'd like to centralize information in account classes instead of
> spreading it over several dictionaries (most of them in
> common/gajim.py).
> 
> Furthermore I'd really like to pull out functionality from
> roster_window. At the moment new roster_data (on connect, received by
> xmpp) will be directed to roster_window that is responsible for
> creating contact instances and placing those in common/contacts.py.
> 
> Last but not least XMPPEntity is meant to simplify a lot of coding. We
> don't need to pass plain jids around any longer. We will always know the
> account of a jid and what type it is (e.g "groupchat contact" or "a
> normal jid with resource")
> 
> To understand more about XMPPEntity, just read on.
> 
> See "2. contacts.py"
> 
> The class diagram is looking more complicated than it really is. You can
> understand ContactRosterInterface and ContactChatInterface as everything
> that is required to add a "Contact" (as currently defined in
> common/Contacts.py) to roster_window or to start a chat with a contact.
> 
> The rest was designed to simplify coding that has to run on several
> "Contacts" (e.g assigning a nick to a contact that is online with 5
> resources or to move a metacontact to a new group).
> 
> 
> I see working on this as a good starting point for several reasons.
> On the one hand we can keep 95% of our code in place as it will be just
> backward compatible. The rest can be easily ported to the new API. One
> by one we can migrate and simplify components by letting them use the
> newly defined interfaces.
> On the other hand I see this as a good basis for writing regression
> tests. That way, contacts and accounts should be much easier to test and
> even to mock.
> 
> What do you think?
> 
> Best Regards,
> steve-e
> _______________________________________________
> Gajim-devel mailing list
> Gajim-devel@gajim.org
> http://lists.gajim.org/cgi-bin/listinfo/gajim-devel
_______________________________________________
Gajim-devel mailing list
Gajim-devel@gajim.org
http://lists.gajim.org/cgi-bin/listinfo/gajim-devel

Reply via email to