mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-98] Added exclusions for configured and GAB folders to reminders query
This commit is contained in:
parent
05d6d715a0
commit
4b868456b0
@ -88,7 +88,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
private bool CanManageFolder(MenuItem<IFolder> b, IFolder folder)
|
private bool CanManageFolder(MenuItem<IFolder> b, IFolder folder)
|
||||||
{
|
{
|
||||||
return folder.SyncId?.IsShared == true;
|
return folder.SyncId?.IsCustom == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ManageFolder(IFolder folder)
|
private void ManageFolder(IFolder folder)
|
||||||
@ -151,7 +151,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
// Check that we can get the id
|
// Check that we can get the id
|
||||||
SyncId folderId = folder.SyncId;
|
SyncId folderId = folder.SyncId;
|
||||||
Logger.Instance.Trace(this, "GetSharedFolder1: {0}", folderId);
|
Logger.Instance.Trace(this, "GetSharedFolder1: {0}", folderId);
|
||||||
if (folderId == null || !folderId.IsShared)
|
if (folderId == null || !folderId.IsCustom)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Get the ZPush account
|
// Get the ZPush account
|
||||||
@ -310,7 +310,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
public override bool IsApplicable(IFolder folder)
|
public override bool IsApplicable(IFolder folder)
|
||||||
{
|
{
|
||||||
if (folder.SyncId != null && folder.SyncId.IsShared)
|
if (folder.SyncId != null && folder.SyncId.IsCustom)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
using (IFolder parent = folder.Parent)
|
using (IFolder parent = folder.Parent)
|
||||||
@ -354,7 +354,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
private void OnSharedFolderDiscovered(IFolder folder)
|
private void OnSharedFolderDiscovered(IFolder folder)
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Shared folder discovered: {0} - {1}", folder.Name, folder.SyncId);
|
Logger.Instance.Trace(this, "Shared folder discovered: {0} - {1}", folder.Name, folder.SyncId);
|
||||||
if (folder.SyncId == null || !folder.SyncId.IsShared)
|
if (folder.SyncId == null || !folder.SyncId.IsCustom)
|
||||||
{
|
{
|
||||||
Logger.Instance.Warning(this, "Local folder created in shared folder, deleting: {0} - {1}", folder.Name, folder.SyncId);
|
Logger.Instance.Warning(this, "Local folder created in shared folder, deleting: {0} - {1}", folder.Name, folder.SyncId);
|
||||||
// This is a new, locally created folder. Warn and remove
|
// This is a new, locally created folder. Warn and remove
|
||||||
@ -376,7 +376,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel)
|
private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel)
|
||||||
{
|
{
|
||||||
if (src.SyncId?.IsShared == true || moveTo.SyncId?.IsShared == true)
|
if (src.SyncId?.IsCustom == true || moveTo.SyncId?.IsCustom == true)
|
||||||
{
|
{
|
||||||
// Suppress any move of or into a shared folder
|
// Suppress any move of or into a shared folder
|
||||||
Logger.Instance.Warning(this, "Shared folder move: {0} - {1}", src.Name, moveTo.Name);
|
Logger.Instance.Warning(this, "Shared folder move: {0} - {1}", src.Name, moveTo.Name);
|
||||||
@ -399,7 +399,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
private void CheckSharedFolderRename(IFolder folder)
|
private void CheckSharedFolderRename(IFolder folder)
|
||||||
{
|
{
|
||||||
if (folder.SyncId != null && folder.SyncId.IsShared)
|
if (folder.SyncId != null && folder.SyncId.IsCustom)
|
||||||
{
|
{
|
||||||
string originalName = (string)folder.GetProperty(OutlookConstants.PR_ZPUSH_NAME);
|
string originalName = (string)folder.GetProperty(OutlookConstants.PR_ZPUSH_NAME);
|
||||||
// The folder.name property is sometimes cached, check against the MAPI property
|
// The folder.name property is sometimes cached, check against the MAPI property
|
||||||
|
@ -17,7 +17,8 @@ namespace Acacia.Features.SharedFolders
|
|||||||
private readonly FeatureSharedFolders _feature;
|
private readonly FeatureSharedFolders _feature;
|
||||||
private readonly IFolder _folder;
|
private readonly IFolder _folder;
|
||||||
private SearchQuery _queryRoot;
|
private SearchQuery _queryRoot;
|
||||||
private SearchQuery.Or _queryCustom;
|
private SearchQuery.Or _queryCustomShared;
|
||||||
|
private SearchQuery.Or _queryCustomConfigured;
|
||||||
private bool _queryCustomModified;
|
private bool _queryCustomModified;
|
||||||
|
|
||||||
public RemindersQuery(FeatureSharedFolders feature, IStore store)
|
public RemindersQuery(FeatureSharedFolders feature, IStore store)
|
||||||
@ -28,7 +29,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
public bool Open()
|
public bool Open()
|
||||||
{
|
{
|
||||||
if (_queryCustom != null)
|
if (_queryCustomShared != null && _queryCustomConfigured != null)
|
||||||
return true;
|
return true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -39,30 +40,34 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
SearchQuery.And root = (SearchQuery.And)_queryRoot;
|
SearchQuery.And root = (SearchQuery.And)_queryRoot;
|
||||||
// TODO: more strict checking of query
|
// TODO: more strict checking of query
|
||||||
if (root.Operands.Count == 3)
|
if (root.Operands.Count == 5)
|
||||||
{
|
{
|
||||||
this._queryCustom = root.Operands.ElementAt(2) as SearchQuery.Or;
|
this._queryCustomShared = root.Operands.ElementAt(2) as SearchQuery.Or;
|
||||||
if (this._queryCustom != null)
|
this._queryCustomConfigured = root.Operands.ElementAt(3) as SearchQuery.Or;
|
||||||
|
if (this._queryCustomShared != null)
|
||||||
{
|
{
|
||||||
// TODO: check property test
|
// TODO: check property test
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (root.Operands.Count == 3)
|
||||||
|
{
|
||||||
|
// KOE-98 introduced also checking of G and C prefixes, which are not yet present
|
||||||
|
_queryCustomShared = root.Operands.ElementAt(2) as SearchQuery.Or;
|
||||||
|
}
|
||||||
|
|
||||||
// We have the root, but not the custom query. Create it.
|
// We have the root, but not the custom query. Create it.
|
||||||
Logger.Instance.Debug(this, "Creating custom query");
|
Logger.Instance.Debug(this, "Creating custom query");
|
||||||
_queryCustom = new SearchQuery.Or();
|
if (_queryCustomShared == null)
|
||||||
|
_queryCustomShared = AddCustomQuery(root, "S");
|
||||||
// Add the prefix exclusion for shared folders
|
_queryCustomConfigured = AddCustomQuery(root, "C");
|
||||||
_queryCustom.Add(
|
// Add the G (GAB) exclusion. Folders will never have a flag with this prefix, so it's simpler
|
||||||
new SearchQuery.Not(
|
root.Operands.Add(new SearchQuery.Not(
|
||||||
new SearchQuery.PropertyContent(
|
new SearchQuery.PropertyContent(
|
||||||
PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, "S"
|
PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, "G"
|
||||||
)
|
)
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
root.Operands.Add(_queryCustom);
|
|
||||||
Logger.Instance.Debug(this, "Modified query:\n{0}", root.ToString());
|
Logger.Instance.Debug(this, "Modified query:\n{0}", root.ToString());
|
||||||
// Store it
|
// Store it
|
||||||
FolderQuery = root;
|
FolderQuery = root;
|
||||||
@ -72,7 +77,24 @@ namespace Acacia.Features.SharedFolders
|
|||||||
{
|
{
|
||||||
Logger.Instance.Error(this, "Exception in Open: {0}", e);
|
Logger.Instance.Error(this, "Exception in Open: {0}", e);
|
||||||
}
|
}
|
||||||
return _queryCustom != null;
|
return _queryCustomShared != null && _queryCustomConfigured != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SearchQuery.Or AddCustomQuery(SearchQuery.And root, string prefix)
|
||||||
|
{
|
||||||
|
SearchQuery.Or custom = new SearchQuery.Or();
|
||||||
|
|
||||||
|
// Add the prefix exclusion
|
||||||
|
custom.Add(
|
||||||
|
new SearchQuery.Not(
|
||||||
|
new SearchQuery.PropertyContent(
|
||||||
|
PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, prefix
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
root.Operands.Add(custom);
|
||||||
|
return custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string LogContextId
|
public string LogContextId
|
||||||
@ -117,15 +139,28 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
public void UpdateReminders(SyncId folderId, bool wantReminders)
|
public void UpdateReminders(SyncId folderId, bool wantReminders)
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Setting reminders for folder {0}: {1}", wantReminders, folderId);
|
Logger.Instance.Trace(this, "Setting reminders for folder {0}: {1} ({2})", wantReminders, folderId, folderId?.Kind);
|
||||||
|
switch(folderId.Kind)
|
||||||
|
{
|
||||||
|
case SyncKind.Configured:
|
||||||
|
UpdateReminders(_queryCustomConfigured, folderId, wantReminders);
|
||||||
|
break;
|
||||||
|
case SyncKind.Shared:
|
||||||
|
UpdateReminders(_queryCustomShared, folderId, wantReminders);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateReminders(SearchQuery.Or query, SyncId folderId, bool wantReminders)
|
||||||
|
{
|
||||||
string prefix = MakeFolderPrefix(folderId);
|
string prefix = MakeFolderPrefix(folderId);
|
||||||
if (prefix == null)
|
if (prefix == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Find existing
|
// Find existing
|
||||||
for (int i = 0; i < _queryCustom.Operands.Count;)
|
for (int i = 0; i < query.Operands.Count;)
|
||||||
{
|
{
|
||||||
SearchQuery.PropertyContent element = _queryCustom.Operands[i] as SearchQuery.PropertyContent;
|
SearchQuery.PropertyContent element = query.Operands[i] as SearchQuery.PropertyContent;
|
||||||
if (element != null && prefix == (string)element.Content)
|
if (element != null && prefix == (string)element.Content)
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Found at {0}: {1}", i, folderId);
|
Logger.Instance.Trace(this, "Found at {0}: {1}", i, folderId);
|
||||||
@ -134,7 +169,8 @@ namespace Acacia.Features.SharedFolders
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise remove it. Still continue looking for others, just in case of duplicates
|
// Otherwise remove it. Still continue looking for others, just in case of duplicates
|
||||||
_queryCustom.Operands.RemoveAt(i);
|
query.Operands.RemoveAt(i);
|
||||||
|
_queryCustomModified = true;
|
||||||
}
|
}
|
||||||
else ++i;
|
else ++i;
|
||||||
}
|
}
|
||||||
@ -143,7 +179,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
if (wantReminders)
|
if (wantReminders)
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Adding reminders for {0}", folderId);
|
Logger.Instance.Trace(this, "Adding reminders for {0}", folderId);
|
||||||
_queryCustom.Operands.Add(new SearchQuery.PropertyContent(
|
query.Operands.Add(new SearchQuery.PropertyContent(
|
||||||
PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, prefix
|
PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, prefix
|
||||||
));
|
));
|
||||||
_queryCustomModified = true;
|
_queryCustomModified = true;
|
||||||
@ -152,19 +188,37 @@ namespace Acacia.Features.SharedFolders
|
|||||||
|
|
||||||
public void RemoveStaleReminders(IEnumerable<SyncId> wanted)
|
public void RemoveStaleReminders(IEnumerable<SyncId> wanted)
|
||||||
{
|
{
|
||||||
// Collect the valid prefixes
|
// Group the valid prefixes on type
|
||||||
HashSet<string> prefixes = new HashSet<string>();
|
HashSet<string> prefixesS = new HashSet<string>();
|
||||||
|
HashSet<string> prefixesC = new HashSet<string>();
|
||||||
foreach (SyncId id in wanted)
|
foreach (SyncId id in wanted)
|
||||||
{
|
{
|
||||||
string prefix = MakeFolderPrefix(id);
|
string prefix = MakeFolderPrefix(id);
|
||||||
if (prefix != null)
|
if (prefix != null)
|
||||||
prefixes.Add(prefix);
|
{
|
||||||
|
switch (id.Kind)
|
||||||
|
{
|
||||||
|
case SyncKind.Configured:
|
||||||
|
prefixesC.Add(prefix);
|
||||||
|
break;
|
||||||
|
case SyncKind.Shared:
|
||||||
|
prefixesS.Add(prefix);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all operands for which we do not want the prefix
|
// Update the queries
|
||||||
for (int i = 0; i < _queryCustom.Operands.Count;)
|
RemoveStaleReminders(prefixesS, _queryCustomShared);
|
||||||
|
RemoveStaleReminders(prefixesC, _queryCustomConfigured);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveStaleReminders(ISet<string> prefixes, SearchQuery.Or query)
|
||||||
{
|
{
|
||||||
SearchQuery.PropertyContent element = _queryCustom.Operands[i] as SearchQuery.PropertyContent;
|
// Remove all operands for which we do not want the prefix
|
||||||
|
for (int i = 0; i < query.Operands.Count;)
|
||||||
|
{
|
||||||
|
SearchQuery.PropertyContent element = query.Operands[i] as SearchQuery.PropertyContent;
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
string prefix = (string)element.Content;
|
string prefix = (string)element.Content;
|
||||||
@ -175,7 +229,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.Instance.Trace(this, "Unwanted prefix at {0}: {1}", i, prefix);
|
Logger.Instance.Trace(this, "Unwanted prefix at {0}: {1}", i, prefix);
|
||||||
_queryCustom.Operands.RemoveAt(i);
|
query.Operands.RemoveAt(i);
|
||||||
_queryCustomModified = true;
|
_queryCustomModified = true;
|
||||||
}
|
}
|
||||||
else ++i;
|
else ++i;
|
||||||
@ -186,7 +240,7 @@ namespace Acacia.Features.SharedFolders
|
|||||||
{
|
{
|
||||||
// Sanity check. The check for shared folders also excludes any weird ids; e.g. if permissions are wrong,
|
// Sanity check. The check for shared folders also excludes any weird ids; e.g. if permissions are wrong,
|
||||||
// this will not be a sync id, but a backend id.
|
// this will not be a sync id, but a backend id.
|
||||||
if (folderId == null || !folderId.IsShared)
|
if (folderId == null || !folderId.IsCustom)
|
||||||
return null;
|
return null;
|
||||||
return folderId.ToString() + ":";
|
return folderId.ToString() + ":";
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,14 @@ namespace Acacia.ZPush
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum SyncKind
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
Shared,
|
||||||
|
Configured,
|
||||||
|
GAB
|
||||||
|
}
|
||||||
|
|
||||||
public class SyncId : ZPushId
|
public class SyncId : ZPushId
|
||||||
{
|
{
|
||||||
public static readonly SyncId NONE = new SyncId("0");
|
public static readonly SyncId NONE = new SyncId("0");
|
||||||
@ -76,10 +84,24 @@ namespace Acacia.ZPush
|
|||||||
public SyncId(string id) : base(id) { }
|
public SyncId(string id) : base(id) { }
|
||||||
public SyncId(int id) : base(id) { }
|
public SyncId(int id) : base(id) { }
|
||||||
|
|
||||||
|
|
||||||
|
public SyncKind Kind
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_id.StartsWith("S"))
|
||||||
|
return SyncKind.Shared;
|
||||||
|
if (_id.StartsWith("C"))
|
||||||
|
return SyncKind.Configured;
|
||||||
|
if (_id.StartsWith("G"))
|
||||||
|
return SyncKind.GAB;
|
||||||
|
return SyncKind.Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if this is a SyncId for a shared folders
|
/// Checks if this is a SyncId for a shared folders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsShared { get { return _id.StartsWith("S") || _id.StartsWith("C") || _id.StartsWith("G"); } }
|
public bool IsCustom { get { return Kind != SyncKind.Normal; } }
|
||||||
|
|
||||||
#region Standard overrides
|
#region Standard overrides
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user