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 string[] SearchKeys { get; set; }
|
||||
public bool OnlyNew { get; set; }
|
||||
public bool WithoutMe { get; set; }
|
||||
public bool WithRelated { get; set; }
|
||||
public bool History { get; set; }
|
||||
}
|
@ -202,23 +202,58 @@ public class FeedAggregateDataProvider
|
||||
var q = feedDbContext.FeedAggregates.AsNoTracking()
|
||||
.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)
|
||||
.Skip(filter.Offset)
|
||||
.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)
|
||||
{
|
||||
@ -249,16 +284,14 @@ public class FeedAggregateDataProvider
|
||||
if (filter.SearchKeys != null && filter.SearchKeys.Length > 0)
|
||||
{
|
||||
var keys = filter.SearchKeys
|
||||
.Where(s => !string.IsNullOrEmpty(s))
|
||||
.Select(s => s.Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_"))
|
||||
.ToList();
|
||||
.Where(s => !string.IsNullOrEmpty(s))
|
||||
.Select(s => s.Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_"))
|
||||
.ToList();
|
||||
|
||||
q1 = q1.Where(r => keys.Any(k => r.aggregates.Keywords.StartsWith(k)));
|
||||
}
|
||||
|
||||
var news = q1.Select(r => r.aggregates).Distinct().AsEnumerable();
|
||||
|
||||
return _mapper.Map<IEnumerable<FeedAggregate>, List<FeedResultItem>>(news);
|
||||
return q1.Select(r => r.aggregates).Distinct();
|
||||
}
|
||||
|
||||
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 now = DateTime.UtcNow;
|
||||
var hours = now.Hour;
|
||||
var groupIdHours = hours - (hours % interval);
|
||||
var time = date.ToString("g");
|
||||
|
||||
if (rootId == null)
|
||||
{
|
||||
// groupId = {item}_{author}_{date}
|
||||
return string.Format("{0}_{1}_{2}",
|
||||
item,
|
||||
author,
|
||||
now.ToString("yyyy.MM.dd.") + groupIdHours);
|
||||
return $"{item}_{author}_{time}";
|
||||
}
|
||||
|
||||
if (action == -1)
|
||||
{
|
||||
// groupId = {item}_{author}_{date}_{rootId}_{action}
|
||||
return string.Format("{0}_{1}_{2}_{3}",
|
||||
item,
|
||||
author,
|
||||
now.ToString("yyyy.MM.dd.") + groupIdHours,
|
||||
rootId);
|
||||
return $"{item}_{author}_{time}_{rootId}";
|
||||
}
|
||||
|
||||
// groupId = {item}_{author}_{date}_{rootId}_{action}
|
||||
return string.Format("{0}_{1}_{2}_{3}_{4}",
|
||||
item,
|
||||
author,
|
||||
now.ToString("yyyy.MM.dd.") + groupIdHours,
|
||||
rootId,
|
||||
action);
|
||||
|
||||
return $"{item}_{author}_{time}_{rootId}_{action}";
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public class FilesModule : FeedModule
|
||||
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
||||
Keywords = file.Title,
|
||||
Target = shareRecord.Subject,
|
||||
GroupId = GetGroupId(SharedFileItem, shareRecord.Owner, file.ParentId.ToString()),
|
||||
GroupId = GetGroupId(SharedFileItem, shareRecord.Owner, shareRecord.TimeStamp, file.ParentId.ToString()),
|
||||
ContextId = contextId
|
||||
};
|
||||
|
||||
@ -194,7 +194,7 @@ public class FilesModule : FeedModule
|
||||
AdditionalInfo = file.ContentLengthString,
|
||||
AdditionalInfo2 = file.Encrypted ? "Encrypted" : string.Empty,
|
||||
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
|
||||
};
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class FoldersModule : FeedModule
|
||||
var feed = new Feed.Aggregator.Feed(shareRecord.Owner, shareRecord.TimeStamp, true)
|
||||
{
|
||||
Item = SharedFolderItem,
|
||||
ItemId = string.Format("{0}_{1}", folder.Id, shareRecord.Subject),
|
||||
ItemId = $"{folder.Id}_{shareRecord.Subject}",
|
||||
Product = Product,
|
||||
Module = Name,
|
||||
Title = folder.Title,
|
||||
@ -130,7 +130,7 @@ public class FoldersModule : FeedModule
|
||||
ExtraLocation = folder.ParentId.ToString(),
|
||||
Keywords = folder.Title,
|
||||
Target = shareRecord.Subject,
|
||||
GroupId = GetGroupId(SharedFolderItem, shareRecord.Owner, folder.ParentId.ToString()),
|
||||
GroupId = GetGroupId(SharedFolderItem, shareRecord.Owner, shareRecord.TimeStamp, folder.ParentId.ToString()),
|
||||
ContextId = contextId
|
||||
};
|
||||
|
||||
@ -147,7 +147,7 @@ public class FoldersModule : FeedModule
|
||||
ExtraLocationTitle = parentFolder.Title,
|
||||
ExtraLocation = folder.ParentId.ToString(),
|
||||
Keywords = folder.Title,
|
||||
GroupId = GetGroupId(FolderItem, folder.CreateBy, folder.ParentId.ToString()),
|
||||
GroupId = GetGroupId(FolderItem, folder.CreateBy, folder.CreateOn, folder.ParentId.ToString()),
|
||||
ContextId = contextId
|
||||
};
|
||||
}
|
||||
|
@ -123,14 +123,14 @@ public class RoomsModule : FeedModule
|
||||
Keywords = room.Title,
|
||||
AdditionalInfo = ((int)room.FolderType).ToString(),
|
||||
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)
|
||||
{
|
||||
Item = SharedRoomItem,
|
||||
ItemId = $"{shareRecord.Subject}_{shareRecord.TimeStamp.Ticks}",
|
||||
ItemId = $"{shareRecord.Subject}_{Guid.NewGuid()}",
|
||||
Product = Product,
|
||||
Module = Name,
|
||||
Title = room.Title,
|
||||
@ -142,7 +142,7 @@ public class RoomsModule : FeedModule
|
||||
AdditionalInfo3 = ((int)shareRecord.SubjectType).ToString(),
|
||||
AdditionalInfo4 = room.Private ? "private" : null,
|
||||
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}"
|
||||
};
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class FeedController : ControllerBase
|
||||
Author = author ?? Guid.Empty,
|
||||
SearchKeys = _apiContext.FilterValues,
|
||||
OnlyNew = onlyNew.HasValue && onlyNew.Value,
|
||||
WithRelated = withRelated.HasValue && withRelated.Value,
|
||||
History = withRelated.HasValue && withRelated.Value,
|
||||
};
|
||||
|
||||
if (from != null && to != null)
|
||||
@ -156,6 +156,7 @@ public class FeedController : ControllerBase
|
||||
firstFeed.GroupedFeeds = group.Skip(1);
|
||||
return firstFeed;
|
||||
})
|
||||
.OrderByDescending(f => f.ModifiedDate)
|
||||
.ToList();
|
||||
|
||||
return new { feeds, readedDate };
|
||||
|
Loading…
Reference in New Issue
Block a user