mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-21 03:15:25 +00:00
feat(mail): filter messages by tags (labels)
Fixes #3323 Fixes #3835 Fixes #5338
This commit is contained in:
@@ -172,6 +172,9 @@
|
||||
/* Filter option in messages list */
|
||||
"Show flagged messages only" = "Show flagged messages only";
|
||||
|
||||
/* Aria label for icon of labels */
|
||||
"Filtered by label" = "Filtered by label";
|
||||
|
||||
/* Tree */
|
||||
"SentFolderName" = "Sent";
|
||||
"TrashFolderName" = "Trash";
|
||||
|
||||
@@ -424,29 +424,29 @@
|
||||
EOQualifier *qualifier, *notDeleted, *searchQualifier;
|
||||
WORequest *request;
|
||||
NSDictionary *sortingAttributes, *content, *filter;
|
||||
NSArray *filters;
|
||||
NSString *searchBy, *searchInput, *searchString, *match;
|
||||
NSMutableArray *qualifiers, *searchArray;
|
||||
NSArray *filters, *labels;
|
||||
NSString *searchBy, *searchInput, *searchString, *match, *label;
|
||||
NSMutableArray *qualifiers, *searchArray, *labelQualifiers;
|
||||
BOOL unseenOnly, flaggedOnly;
|
||||
int nbFilters, i;
|
||||
int max, i;
|
||||
|
||||
request = [context request];
|
||||
content = [[request contentAsString] objectFromJSONString];
|
||||
notDeleted = [EOQualifier qualifierWithQualifierFormat: @"(not (flags = %@))", @"deleted"];
|
||||
qualifier = nil;
|
||||
qualifiers = [NSMutableArray arrayWithObject: notDeleted];
|
||||
searchString = nil;
|
||||
match = nil;
|
||||
filters = [content objectForKey: @"filters"];
|
||||
labels = [content objectForKey: @"labels"];
|
||||
unseenOnly = [[content objectForKey: @"unseenOnly"] boolValue];
|
||||
flaggedOnly = [[content objectForKey: @"flaggedOnly"] boolValue];
|
||||
|
||||
if (filters)
|
||||
{
|
||||
nbFilters = [filters count];
|
||||
if (nbFilters > 0) {
|
||||
searchArray = [NSMutableArray arrayWithCapacity: nbFilters];
|
||||
for (i = 0; i < nbFilters; i++)
|
||||
max = [filters count];
|
||||
if (max > 0) {
|
||||
searchArray = [NSMutableArray arrayWithCapacity: max];
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
filter = [filters objectAtIndex:i];
|
||||
searchBy = [filter objectForKey: @"searchBy"];
|
||||
@@ -489,6 +489,26 @@
|
||||
searchQualifier = [EOQualifier qualifierWithQualifierFormat: @"(flags = %@)", @"flagged"];
|
||||
[qualifiers addObject: searchQualifier];
|
||||
}
|
||||
if (labels)
|
||||
{
|
||||
max = [labels count];
|
||||
if (max > 0)
|
||||
{
|
||||
labelQualifiers = [NSMutableArray arrayWithCapacity: max];
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
label = [labels objectAtIndex: i];
|
||||
qualifier = [EOQualifier qualifierWithQualifierFormat: @"(flags = %@)", label];
|
||||
[labelQualifiers addObject: qualifier];
|
||||
}
|
||||
if (max > 1)
|
||||
{
|
||||
qualifier = [[EOOrQualifier alloc] initWithQualifierArray: labelQualifiers];
|
||||
[qualifier autorelease];
|
||||
}
|
||||
[qualifiers addObject: qualifier];
|
||||
}
|
||||
}
|
||||
|
||||
if ([qualifiers count] > 1)
|
||||
{
|
||||
|
||||
@@ -93,6 +93,20 @@
|
||||
sg-true-value="1"
|
||||
sg-false-value="0"> <var:string label:value="Show flagged messages only"/></sg-checkmark>
|
||||
</md-menu-item>
|
||||
<md-menu-divider> <!-- divider --></md-menu-divider>
|
||||
<md-menu-item ng-repeat="label in ::mailbox.selectedFolder.$labels track by label.imapName">
|
||||
<sg-checkmark
|
||||
ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
|
||||
ng-model="mailbox.selectedFolder.$filteredLabels[label.imapName]"
|
||||
sg-true-value="1"
|
||||
sg-false-value="0">
|
||||
<div layout="row" layout-align="start center">
|
||||
<div class="sg-color-chip"
|
||||
ng-style="{ backgroundColor: label.color || '#333' }"><!-- color --></div>
|
||||
{{ label.name || label.imapName }}
|
||||
</div>
|
||||
</sg-checkmark>
|
||||
</md-menu-item>
|
||||
</md-menu-content>
|
||||
</md-menu>
|
||||
<md-menu>
|
||||
@@ -302,6 +316,7 @@
|
||||
<span ng-switch-default="true"><span ng-bind="mailbox.service.selectedFolder.getLength()"><!-- count --></span> <var:string label:value="messages"/></span>
|
||||
</div>
|
||||
<div class="md-truncate">
|
||||
<md-icon label:aria-label="Filtered by label" ng-show="mailbox.selectedFolder.filteredByLabel()">label_outline</md-icon>
|
||||
<span ng-show="mailbox.selectedFolder.$unseenOnly"><var:string label:value="Unread"/></span>
|
||||
<span ng-show="mailbox.selectedFolder.$flaggedOnly"><var:string label:value="Flagged"/></span>
|
||||
<md-icon ng-class="{ 'md-flip': mailbox.ascending() }">sort</md-icon>
|
||||
|
||||
@@ -400,6 +400,12 @@
|
||||
if (this.$flaggedOnly)
|
||||
options.flaggedOnly = 1;
|
||||
|
||||
var labels = _.filter(_.keys(this.$filteredLabels), function (k) {
|
||||
return !!_this.$filteredLabels[k];
|
||||
});
|
||||
if (labels.length)
|
||||
options.labels = labels;
|
||||
|
||||
// Restart the refresh timer, if needed
|
||||
if (!Mailbox.$virtualMode) {
|
||||
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
|
||||
@@ -675,6 +681,29 @@
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getLabels
|
||||
* @memberof Mailbox.prototype
|
||||
* @desc Fetch the list of labels associated to the mailbox. Use the cached value if available.
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Mailbox.prototype.getLabels = function() {
|
||||
var _this = this;
|
||||
|
||||
if (this.$labels)
|
||||
return this.$labels;
|
||||
|
||||
this.$filteredLabels = {};
|
||||
return Mailbox.$$resource.fetch(this.id, 'labels').then(function(data) {
|
||||
_this.$labels = data;
|
||||
return _this.$labels;
|
||||
});
|
||||
};
|
||||
|
||||
Mailbox.prototype.filteredByLabel = function() {
|
||||
return _.includes(this.$filteredLabels, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function $flagMessages
|
||||
* @memberof Mailbox.prototype
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
this.messageDialog = null; // also access from Message controller
|
||||
this.mode = { search: false, multiple: 0 };
|
||||
|
||||
if (!Mailbox.$virtualMode)
|
||||
this.selectedFolder.getLabels(); // fetch labels from server
|
||||
|
||||
_registerHotkeys(hotkeys);
|
||||
|
||||
// Expunge mailbox when leaving the Mail module
|
||||
|
||||
Reference in New Issue
Block a user