~ubuntu-branches/debian/stretch/geary/stretch

« back to all changes in this revision

Viewing changes to src/client/conversation-list/formatted-conversation-data.vala

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng
  • Date: 2015-04-29 02:55:37 UTC
  • mfrom: (3.1.13)
  • Revision ID: package-import@ubuntu.com-20150429025537-6o00z6549l6c70qz
Tags: 0.10.0-1
New upstream release. (Closes: #782594)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2011-2014 Yorba Foundation
 
1
/* Copyright 2011-2015 Yorba Foundation
2
2
 *
3
3
 * This software is licensed under the GNU Lesser General Public License
4
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
20
20
    private const int FONT_SIZE_PREVIEW = 8;
21
21
    
22
22
    private class ParticipantDisplay : Geary.BaseObject, Gee.Hashable<ParticipantDisplay> {
23
 
        public string key;
24
23
        public Geary.RFC822.MailboxAddress address;
25
24
        public bool is_unread;
26
25
        
27
26
        public ParticipantDisplay(Geary.RFC822.MailboxAddress address, bool is_unread) {
28
 
            key = address.as_key();
29
27
            this.address = address;
30
28
            this.is_unread = is_unread;
31
29
        }
32
30
        
33
 
        public string get_full_markup(string normalized_account_key) {
34
 
            return get_as_markup((key == normalized_account_key) ? ME : address.get_short_address());
 
31
        public string get_full_markup(Gee.List<Geary.RFC822.MailboxAddress> account_mailboxes) {
 
32
            return get_as_markup((address in account_mailboxes) ? ME : address.get_short_address());
35
33
        }
36
34
        
37
 
        public string get_short_markup(string normalized_account_key) {
38
 
            if (key == normalized_account_key)
 
35
        public string get_short_markup(Gee.List<Geary.RFC822.MailboxAddress> account_mailboxes) {
 
36
            if (address in account_mailboxes)
39
37
                return get_as_markup(ME);
40
38
            
41
39
            string short_address = address.get_short_address().strip();
45
43
                string[] tokens = short_address.split(", ", 2);
46
44
                short_address = tokens[1].strip();
47
45
                if (Geary.String.is_empty(short_address))
48
 
                    return get_full_markup(normalized_account_key);
 
46
                    return get_full_markup(account_mailboxes);
49
47
            }
50
48
            
51
49
            // use first name as delimited by a space
52
50
            string[] tokens = short_address.split(" ", 2);
53
51
            if (tokens.length < 1)
54
 
                return get_full_markup(normalized_account_key);
 
52
                return get_full_markup(account_mailboxes);
55
53
            
56
54
            string first_name = tokens[0].strip();
57
55
            if (Geary.String.is_empty_or_whitespace(first_name))
58
 
                return get_full_markup(normalized_account_key);
 
56
                return get_full_markup(account_mailboxes);
59
57
            
60
58
            return get_as_markup(first_name);
61
59
        }
66
64
        }
67
65
        
68
66
        public bool equal_to(ParticipantDisplay other) {
69
 
            if (this == other)
70
 
                return true;
71
 
            
72
 
            return key == other.key;
 
67
            return address.equal_to(other.address);
73
68
        }
74
69
        
75
70
        public uint hash() {
76
 
            return key.hash();
 
71
            return address.hash();
77
72
        }
78
73
    }
79
74
    
89
84
    public Geary.Email? preview { get; private set; default = null; }
90
85
    
91
86
    private Geary.App.Conversation? conversation = null;
92
 
    private string? account_owner_email = null;
 
87
    private Gee.List<Geary.RFC822.MailboxAddress>? account_owner_emails = null;
93
88
    private bool use_to = true;
94
89
    private CountBadge count_badge = new CountBadge(2);
95
90
    
96
91
    // Creates a formatted message data from an e-mail.
97
92
    public FormattedConversationData(Geary.App.Conversation conversation, Geary.Email preview,
98
 
        Geary.Folder folder, string account_owner_email) {
 
93
        Geary.Folder folder, Gee.List<Geary.RFC822.MailboxAddress> account_owner_emails) {
99
94
        assert(preview.fields.fulfills(ConversationListStore.REQUIRED_FIELDS));
100
95
        
101
96
        this.conversation = conversation;
102
 
        this.account_owner_email = account_owner_email;
 
97
        this.account_owner_emails = account_owner_emails;
103
98
        use_to = (folder != null) && folder.special_folder_type.is_outgoing();
104
99
        
105
100
        // Load preview-related data.
116
111
    
117
112
    public bool update_date_string() {
118
113
        // get latest email *in folder* for the conversation's date, fall back on out-of-folder
119
 
        Geary.Email? latest = conversation.get_latest_email(Geary.App.Conversation.Location.IN_FOLDER_OUT_OF_FOLDER);
 
114
        Geary.Email? latest = conversation.get_latest_recv_email(Geary.App.Conversation.Location.IN_FOLDER_OUT_OF_FOLDER);
120
115
        if (latest == null || latest.properties == null)
121
116
            return false;
122
117
        
173
168
    }
174
169
    
175
170
    private string get_participants_markup(Gtk.Widget widget, bool selected) {
176
 
        if (conversation == null || account_owner_email == null)
 
171
        if (conversation == null || account_owner_emails == null || account_owner_emails.size == 0)
177
172
            return "";
178
173
        
179
 
        string normalized_account_owner_email = account_owner_email.normalize().casefold();
180
 
        
181
174
        // Build chronological list of AuthorDisplay records, setting to unread if any message by
182
175
        // that author is unread
183
176
        Gee.ArrayList<ParticipantDisplay> list = new Gee.ArrayList<ParticipantDisplay>();
184
 
        foreach (Geary.Email message in conversation.get_emails(Geary.App.Conversation.Ordering.DATE_ASCENDING)) {
 
177
        foreach (Geary.Email message in conversation.get_emails(Geary.App.Conversation.Ordering.RECV_DATE_ASCENDING)) {
185
178
            // only display if something to display
186
179
            Geary.RFC822.MailboxAddresses? addresses = use_to ? message.to : message.from;
187
180
            if (addresses == null || addresses.size < 1)
210
203
            rgba_to_markup(get_foreground_rgba(widget, selected))));
211
204
        if (list.size == 1) {
212
205
            // if only one participant, use full name
213
 
            builder.append(list[0].get_full_markup(normalized_account_owner_email));
 
206
            builder.append(list[0].get_full_markup(account_owner_emails));
214
207
        } else {
215
208
            bool first = true;
216
209
            foreach (ParticipantDisplay participant in list) {
217
210
                if (!first)
218
211
                    builder.append(", ");
219
212
                
220
 
                builder.append(participant.get_short_markup(normalized_account_owner_email));
 
213
                builder.append(participant.get_short_markup(account_owner_emails));
221
214
                first = false;
222
215
            }
223
216
        }