src/com/closedcircles/client/model/Circle.java
// updates are downloaded continuously, so old messages should be removed
updates are downloaded continuously, so old messages should be removed
updates are downloaded continuously so old messages should be removed
private void removeOldThreads(){
        ArrayList<Thread> threads = new ArrayList<Thread>();
        for (Entry<Long, Thread> entry: mThreads.entrySet()) {
            threads.add(entry.getValue());
        }
        Collections.sort(threads, new Comparator<Thread>() {
            @Override
            public int compare(Thread t1, Thread t2) {
                long id1 = Circle.this.getMessage(t1.getLast()).getId();
                long id2 = Circle.this.getMessage(t2.getLast()).getId();
                return (int)(id2-id1);
            }
        });
        boolean wasRemoved = false;
        TreeSet<Integer> to_remove = new TreeSet<Integer>();
        for ( int i=WebConnectionManager.HISTORY_LENGTH;i<threads.size();++i){
            Thread t = threads.get(i);
            for ( int j=0;j<t.size();++j){
                to_remove.add(t.get(j));
                wasRemoved = true;
            }
        }
        Circle.this.removeMessages(to_remove);
        if ( wasRemoved ) {
            Map<Long, Thread> mapThreads = new HashMap<Long, Thread>();
            mapThreads.putAll(mThreads);
            mThreads.clear();
            mMsgMap.clear();
            ArrayList<Message> messages = new ArrayList<Message>();
            messages.addAll(mMessages);
            mMessages.clear();
            for (int i = 0; i < messages.size(); ++i)
                Circle.this.add(messages.get(i));
            for ( Entry<Long, Thread> e: mapThreads.entrySet() ){
                int firstUnread = e.getValue().getFirstUread();
                if( mThreads.get(e.getKey()) != null )
                    mThreads.get(e.getKey()).setFirstUnread(firstUnread);
            }
        }
    }
private void removeOldThreads ( ) { ArrayList < Thread > threads = new ArrayList < Thread > ( ) ; for ( Entry < Long , Thread > entry : mThreads . entrySet ( ) ) { threads . add ( entry . getValue ( ) ) ; } Collections . sort ( threads , new Comparator < Thread > ( ) { @ Override public int compare ( Thread t1 , Thread t2 ) { long id1 = Circle . this . getMessage ( t1 . getLast ( ) ) . getId ( ) ; long id2 = Circle . this . getMessage ( t2 . getLast ( ) ) . getId ( ) ; return ( int ) ( id2 - id1 ) ; } } ) ; boolean wasRemoved = false ; TreeSet < Integer > to_remove = new TreeSet < Integer > ( ) ; for ( int i = WebConnectionManager . HISTORY_LENGTH ; i < threads . size ( ) ; ++ i ) { Thread t = threads . get ( i ) ; for ( int j = 0 ; j < t . size ( ) ; ++ j ) { to_remove . add ( t . get ( j ) ) ; wasRemoved = true ; } } Circle . this . removeMessages ( to_remove ) ; if ( wasRemoved ) { Map < Long , Thread > mapThreads = new HashMap < Long , Thread > ( ) ; mapThreads . putAll ( mThreads ) ; mThreads . clear ( ) ; mMsgMap . clear ( ) ; ArrayList < Message > messages = new ArrayList < Message > ( ) ; messages . addAll ( mMessages ) ; mMessages . clear ( ) ; for ( int i = 0 ; i < messages . size ( ) ; ++ i ) Circle . this . add ( messages . get ( i ) ) ; for ( Entry < Long , Thread > e : mapThreads . entrySet ( ) ) { int firstUnread = e . getValue ( ) . getFirstUread ( ) ; if ( mThreads . get ( e . getKey ( ) ) != null ) mThreads . get ( e . getKey ( ) ) . setFirstUnread ( firstUnread ) ; } } }
updates are downloaded continuously, so old messages should be removed
updates are downloaded continuously so old messages should be removed
// refill threads one more time // TODO: think how to avoid second pass // apply read markers