fixed room history
This commit is contained in:
parent
e1755b3a82
commit
5aacc82904
@ -38,6 +38,5 @@ public class FeedApiFilter
|
|||||||
public Guid Author { get; set; }
|
public Guid Author { get; set; }
|
||||||
public string[] SearchKeys { get; set; }
|
public string[] SearchKeys { get; set; }
|
||||||
public bool OnlyNew { get; set; }
|
public bool OnlyNew { get; set; }
|
||||||
public bool WithoutMe { get; set; }
|
public bool History { get; set; }
|
||||||
public bool WithRelated { get; set; }
|
|
||||||
}
|
}
|
@ -202,23 +202,58 @@ public class FeedAggregateDataProvider
|
|||||||
var q = feedDbContext.FeedAggregates.AsNoTracking()
|
var q = feedDbContext.FeedAggregates.AsNoTracking()
|
||||||
.Where(r => r.Tenant == _tenantManager.GetCurrentTenant().Id);
|
.Where(r => r.Tenant == _tenantManager.GetCurrentTenant().Id);
|
||||||
|
|
||||||
var exp = GetIdSearchExpression(filter.Id, filter.Module, filter.WithRelated);
|
var feeds = filter.History ? GetFeedsAsHistoryQuery(q, filter) : GetFeedsDefaultQuery(feedDbContext, q, filter);
|
||||||
|
|
||||||
if (exp != null)
|
return _mapper.Map<IEnumerable<FeedAggregate>, List<FeedResultItem>>(feeds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IQueryable<FeedAggregate> GetFeedsAsHistoryQuery(IQueryable<FeedAggregate> query, FeedApiFilter filter)
|
||||||
|
{
|
||||||
|
Expression<Func<FeedAggregate, bool>> exp = null;
|
||||||
|
|
||||||
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(filter.Id);
|
||||||
|
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(filter.Module);
|
||||||
|
|
||||||
|
switch (filter.Module)
|
||||||
{
|
{
|
||||||
q = q.Where(exp);
|
case Constants.RoomsModule:
|
||||||
|
{
|
||||||
|
var roomId = $"{Constants.RoomItem}_{filter.Id}";
|
||||||
|
|
||||||
|
exp = f => f.Id == roomId || (f.Id.StartsWith(Constants.SharedRoomItem) && f.ContextId == roomId);
|
||||||
|
|
||||||
|
if (filter.History)
|
||||||
|
{
|
||||||
|
exp = f => f.Id == roomId || f.ContextId == roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Constants.FilesModule:
|
||||||
|
exp = f => f.Id.StartsWith($"{Constants.FileItem}_{filter.Id}") || f.Id.StartsWith($"{Constants.SharedFileItem}_{filter.Id}");
|
||||||
|
break;
|
||||||
|
case Constants.FoldersModule:
|
||||||
|
exp = f => f.Id == $"{Constants.FolderItem}_{filter.Id}" || f.Id.StartsWith($"{Constants.SharedFolderItem}_{filter.Id}");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var q1 = q.Join(feedDbContext.FeedUsers, a => a.Id, b => b.FeedId, (aggregates, users) => new { aggregates, users })
|
if (exp == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.Where(exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IQueryable<FeedAggregate> GetFeedsDefaultQuery(FeedDbContext feedDbContext, IQueryable<FeedAggregate> query, FeedApiFilter filter)
|
||||||
|
{
|
||||||
|
var q1 = query.Join(feedDbContext.FeedUsers, a => a.Id, b => b.FeedId, (aggregates, users) => new { aggregates, users })
|
||||||
.OrderByDescending(r => r.aggregates.ModifiedDate)
|
.OrderByDescending(r => r.aggregates.ModifiedDate)
|
||||||
.Skip(filter.Offset)
|
.Skip(filter.Offset)
|
||||||
.Take(filter.Max);
|
.Take(filter.Max);
|
||||||
|
|
||||||
if (exp == null)
|
q1 = q1.Where(r => r.aggregates.ModifiedBy != _authContext.CurrentAccount.ID).
|
||||||
{
|
Where(r => r.users.UserId == _authContext.CurrentAccount.ID);
|
||||||
q1 = q1.Where(r => r.aggregates.ModifiedBy != _authContext.CurrentAccount.ID).
|
|
||||||
Where(r => r.users.UserId == _authContext.CurrentAccount.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.OnlyNew)
|
if (filter.OnlyNew)
|
||||||
{
|
{
|
||||||
@ -249,16 +284,14 @@ public class FeedAggregateDataProvider
|
|||||||
if (filter.SearchKeys != null && filter.SearchKeys.Length > 0)
|
if (filter.SearchKeys != null && filter.SearchKeys.Length > 0)
|
||||||
{
|
{
|
||||||
var keys = filter.SearchKeys
|
var keys = filter.SearchKeys
|
||||||
.Where(s => !string.IsNullOrEmpty(s))
|
.Where(s => !string.IsNullOrEmpty(s))
|
||||||
.Select(s => s.Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_"))
|
.Select(s => s.Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_"))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
q1 = q1.Where(r => keys.Any(k => r.aggregates.Keywords.StartsWith(k)));
|
q1 = q1.Where(r => keys.Any(k => r.aggregates.Keywords.StartsWith(k)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var news = q1.Select(r => r.aggregates).Distinct().AsEnumerable();
|
return q1.Select(r => r.aggregates).Distinct();
|
||||||
|
|
||||||
return _mapper.Map<IEnumerable<FeedAggregate>, List<FeedResultItem>>(news);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetNewFeedsCount(DateTime lastReadedTime)
|
public int GetNewFeedsCount(DateTime lastReadedTime)
|
||||||
|
@ -82,38 +82,20 @@ public abstract class FeedModule : IFeedModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string GetGroupId(string item, Guid author, string rootId = null, int action = -1)
|
protected string GetGroupId(string item, Guid author, DateTime date, string rootId = null, int action = -1)
|
||||||
{
|
{
|
||||||
const int interval = 2;
|
var time = date.ToString("g");
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
|
||||||
var hours = now.Hour;
|
|
||||||
var groupIdHours = hours - (hours % interval);
|
|
||||||
|
|
||||||
if (rootId == null)
|
if (rootId == null)
|
||||||
{
|
{
|
||||||
// groupId = {item}_{author}_{date}
|
return $"{item}_{author}_{time}";
|
||||||
return string.Format("{0}_{1}_{2}",
|
|
||||||
item,
|
|
||||||
author,
|
|
||||||
now.ToString("yyyy.MM.dd.") + groupIdHours);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == -1)
|
if (action == -1)
|
||||||
{
|
{
|
||||||
// groupId = {item}_{author}_{date}_{rootId}_{action}
|
return $"{item}_{author}_{time}_{rootId}";
|
||||||
return string.Format("{0}_{1}_{2}_{3}",
|
|
||||||
item,
|
|
||||||
author,
|
|
||||||
now.ToString("yyyy.MM.dd.") + groupIdHours,
|
|
||||||
rootId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// groupId = {item}_{author}_{date}_{rootId}_{action}
|
return $"{item}_{author}_{time}_{rootId}_{action}";
|
||||||
return string.Format("{0}_{1}_{2}_{3}_{4}",
|
|
||||||
item,
|
|
||||||
author,
|
|
||||||
now.ToString("yyyy.MM.dd.") + groupIdHours,
|
|
||||||
rootId,
|
|
||||||
action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ public class FilesModule : FeedModule
|
|||||||
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
||||||
Keywords = file.Title,
|
Keywords = file.Title,
|
||||||
Target = shareRecord.Subject,
|
Target = shareRecord.Subject,
|
||||||
GroupId = GetGroupId(SharedFileItem, shareRecord.Owner, file.ParentId.ToString()),
|
GroupId = GetGroupId(SharedFileItem, shareRecord.Owner, shareRecord.TimeStamp, file.ParentId.ToString()),
|
||||||
ContextId = contextId
|
ContextId = contextId
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ public class FilesModule : FeedModule
|
|||||||
AdditionalInfo = file.ContentLengthString,
|
AdditionalInfo = file.ContentLengthString,
|
||||||
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
||||||
Keywords = file.Title,
|
Keywords = file.Title,
|
||||||
GroupId = GetGroupId(FileItem, file.ModifiedBy, file.ParentId.ToString(), updated ? 1 : 0),
|
GroupId = GetGroupId(FileItem, file.ModifiedBy, file.ModifiedOn, file.ParentId.ToString(), updated ? 1 : 0),
|
||||||
ContextId = contextId
|
ContextId = contextId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class FoldersModule : FeedModule
|
|||||||
var feed = new Feed.Aggregator.Feed(shareRecord.Owner, shareRecord.TimeStamp, true)
|
var feed = new Feed.Aggregator.Feed(shareRecord.Owner, shareRecord.TimeStamp, true)
|
||||||
{
|
{
|
||||||
Item = SharedFolderItem,
|
Item = SharedFolderItem,
|
||||||
ItemId = string.Format("{0}_{1}", folder.Id, shareRecord.Subject),
|
ItemId = $"{folder.Id}_{shareRecord.Subject}",
|
||||||
Product = Product,
|
Product = Product,
|
||||||
Module = Name,
|
Module = Name,
|
||||||
Title = folder.Title,
|
Title = folder.Title,
|
||||||
@ -130,7 +130,7 @@ public class FoldersModule : FeedModule
|
|||||||
ExtraLocation = folder.ParentId.ToString(),
|
ExtraLocation = folder.ParentId.ToString(),
|
||||||
Keywords = folder.Title,
|
Keywords = folder.Title,
|
||||||
Target = shareRecord.Subject,
|
Target = shareRecord.Subject,
|
||||||
GroupId = GetGroupId(SharedFolderItem, shareRecord.Owner, folder.ParentId.ToString()),
|
GroupId = GetGroupId(SharedFolderItem, shareRecord.Owner, shareRecord.TimeStamp, folder.ParentId.ToString()),
|
||||||
ContextId = contextId
|
ContextId = contextId
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class FoldersModule : FeedModule
|
|||||||
ExtraLocationTitle = parentFolder.Title,
|
ExtraLocationTitle = parentFolder.Title,
|
||||||
ExtraLocation = folder.ParentId.ToString(),
|
ExtraLocation = folder.ParentId.ToString(),
|
||||||
Keywords = folder.Title,
|
Keywords = folder.Title,
|
||||||
GroupId = GetGroupId(FolderItem, folder.CreateBy, folder.ParentId.ToString()),
|
GroupId = GetGroupId(FolderItem, folder.CreateBy, folder.CreateOn, folder.ParentId.ToString()),
|
||||||
ContextId = contextId
|
ContextId = contextId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,14 @@ public class RoomsModule : FeedModule
|
|||||||
Keywords = room.Title,
|
Keywords = room.Title,
|
||||||
AdditionalInfo = ((int)room.FolderType).ToString(),
|
AdditionalInfo = ((int)room.FolderType).ToString(),
|
||||||
AdditionalInfo4 = room.Private ? "private" : null,
|
AdditionalInfo4 = room.Private ? "private" : null,
|
||||||
GroupId = GetGroupId(RoomItem, room.CreateBy, room.ParentId.ToString())
|
GroupId = GetGroupId(RoomItem, room.CreateBy, room.CreateOn, room.ParentId.ToString())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var feed = new Feed.Aggregator.Feed(shareRecord.Owner, shareRecord.TimeStamp)
|
var feed = new Feed.Aggregator.Feed(shareRecord.Owner, shareRecord.TimeStamp)
|
||||||
{
|
{
|
||||||
Item = SharedRoomItem,
|
Item = SharedRoomItem,
|
||||||
ItemId = $"{shareRecord.Subject}_{shareRecord.TimeStamp.Ticks}",
|
ItemId = $"{shareRecord.Subject}_{Guid.NewGuid()}",
|
||||||
Product = Product,
|
Product = Product,
|
||||||
Module = Name,
|
Module = Name,
|
||||||
Title = room.Title,
|
Title = room.Title,
|
||||||
@ -142,7 +142,7 @@ public class RoomsModule : FeedModule
|
|||||||
AdditionalInfo3 = ((int)shareRecord.SubjectType).ToString(),
|
AdditionalInfo3 = ((int)shareRecord.SubjectType).ToString(),
|
||||||
AdditionalInfo4 = room.Private ? "private" : null,
|
AdditionalInfo4 = room.Private ? "private" : null,
|
||||||
Target = shareRecord.Subject,
|
Target = shareRecord.Subject,
|
||||||
GroupId = GetGroupId(SharedRoomItem, shareRecord.Owner, room.ParentId.ToString()),
|
GroupId = GetGroupId(SharedRoomItem, shareRecord.Owner, shareRecord.TimeStamp, room.ParentId.ToString()),
|
||||||
ContextId = $"{RoomItem}_{room.Id}"
|
ContextId = $"{RoomItem}_{room.Id}"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ public class FeedController : ControllerBase
|
|||||||
Author = author ?? Guid.Empty,
|
Author = author ?? Guid.Empty,
|
||||||
SearchKeys = _apiContext.FilterValues,
|
SearchKeys = _apiContext.FilterValues,
|
||||||
OnlyNew = onlyNew.HasValue && onlyNew.Value,
|
OnlyNew = onlyNew.HasValue && onlyNew.Value,
|
||||||
WithRelated = withRelated.HasValue && withRelated.Value,
|
History = withRelated.HasValue && withRelated.Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (from != null && to != null)
|
if (from != null && to != null)
|
||||||
@ -156,6 +156,7 @@ public class FeedController : ControllerBase
|
|||||||
firstFeed.GroupedFeeds = group.Skip(1);
|
firstFeed.GroupedFeeds = group.Skip(1);
|
||||||
return firstFeed;
|
return firstFeed;
|
||||||
})
|
})
|
||||||
|
.OrderByDescending(f => f.ModifiedDate)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return new { feeds, readedDate };
|
return new { feeds, readedDate };
|
||||||
|
Loading…
Reference in New Issue
Block a user