~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/model.py

  • Committer: William Grant
  • Date: 2012-01-22 12:46:24 UTC
  • Revision ID: william.grant@canonical.com-20120122124624-of899x94i30q946p
Do backward correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
            'message-id': message.get('message-id'),
117
117
            }
118
118
 
119
 
    def get_messages(self, archive_uuid, order, count, memo):
 
119
    def _trim(self, sequence, end):
 
120
        if end:
 
121
            return sequence[:-1]
 
122
        else:
 
123
            return sequence[1:]
 
124
 
 
125
    def get_messages(self, archive_uuid, order, count, memo, backward=False):
120
126
        if order in ("date", "-date"):
121
127
            reversed = order[0] == '-'
122
128
        else:
126
132
        # Get up to n+1 messages from the memo: the last item of the
127
133
        # previous batch (because that's where the memo starts) + this
128
134
        # batch.
 
135
        if backward:
 
136
            start = ''
 
137
            finish = memo
 
138
        else:
 
139
            start = memo
 
140
            finish = ''
129
141
        pairs = self.archive_messages.get(
130
 
            archive_uuid, column_count=count + 1,
131
 
            column_start=memo, column_reversed=reversed).items()
132
 
 
 
142
            archive_uuid, column_count=count + 1, column_start=start,
 
143
            column_finish=finish, column_reversed=reversed).items()
133
144
        if memo and len(pairs) and pairs[0][0] <= memo:
134
 
            pairs = pairs[1:]
 
145
            pairs = self._trim(pairs, False ^ backward)
135
146
        elif len(pairs) > count:
136
 
            pairs = pairs[:-1]
 
147
            pairs = self._trim(pairs, True ^ backward)
137
148
 
138
149
        if len(pairs) == 0:
139
150
            return (None, [], None)