imap-engine-replay-append.vala 2.38 KB
Newer Older
1
/* Copyright 2012-2013 Yorba Foundation
2 3
 *
 * This software is licensed under the GNU Lesser General Public License
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
5 6
 */

7
private class Geary.ImapEngine.ReplayAppend : Geary.ImapEngine.ReplayOperation {
8
    public GenericFolder owner;
9
    public int remote_count;
10
    public Gee.List<Imap.SequenceNumber> positions;
11
    
12
    public ReplayAppend(GenericFolder owner, int remote_count, Gee.List<Imap.SequenceNumber> positions) {
13
        base ("Append", Scope.REMOTE_ONLY);
14 15
        
        this.owner = owner;
16
        this.remote_count = remote_count;
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        this.positions = positions;
    }
    
    public override void notify_remote_removed_position(Imap.SequenceNumber removed) {
        Gee.List<Imap.SequenceNumber> new_positions = new Gee.ArrayList<Imap.SequenceNumber>();
        foreach (Imap.SequenceNumber? position in positions) {
            Imap.SequenceNumber old_position = position;
            
            // adjust depending on relation to removed message
            position = position.shift_for_removed(removed);
            if (position != null)
                new_positions.add(position);
            
            debug("%s: ReplayAppend remote unsolicited remove: %s -> %s", owner.to_string(),
                old_position.to_string(), (position != null) ? position.to_string() : "(null)");
        }
        
        positions = new_positions;
35 36 37
        
        // DON'T update remote_count, it is intended to report the remote count at the time the
        // appended messages arrived
38 39 40
    }
    
    public override void notify_remote_removed_ids(Gee.Collection<ImapDB.EmailIdentifier> ids) {
41 42
    }
    
43 44 45
    public override void get_ids_to_be_remote_removed(Gee.Collection<ImapDB.EmailIdentifier> ids) {
    }
    
46 47 48 49 50 51 52 53
    public override async ReplayOperation.Status replay_local_async() throws Error {
        return ReplayOperation.Status.CONTINUE;
    }
    
    public override async void backout_local_async() throws Error {
    }
    
    public override async ReplayOperation.Status replay_remote_async() {
54
        if (positions.size > 0)
55
            yield owner.do_replay_appended_messages(remote_count, positions);
56 57 58 59 60
        
        return ReplayOperation.Status.COMPLETED;
    }
    
    public override string describe_state() {
61
        return "remote_count=%d positions.size=%d".printf(remote_count, positions.size);
62 63 64
    }
}