Skip to content

Commit

Permalink
Closes #797
Browse files Browse the repository at this point in the history
  • Loading branch information
borrrden committed Jan 12, 2017
1 parent 7dd9734 commit 1b5dd44
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions src/Couchbase.Lite.Shared/Documents/DocumentChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,57 +53,28 @@ namespace Couchbase.Lite {
/// </summary>
public class DocumentChange
{
internal RevisionInternal AddedRevision { get; private set; }

// Used by plugins
internal DocumentChange(RevisionInternal addedRevision, RevisionID winningRevisionId, bool isConflict, Uri sourceUrl)
{
AddedRevision = addedRevision;
WinningRevisionId = winningRevisionId;
IsConflict = isConflict;
SourceUrl = sourceUrl;
}

#region Instance Members
#region Properties

//Properties
/// <summary>
/// Gets the Id of the <see cref="Couchbase.Lite.Document"/> that changed.
/// </summary>
/// <value>The Id of the <see cref="Couchbase.Lite.Document"/> that changed.</value>
public string DocumentId { get { return AddedRevision.DocID; } }
public string DocumentId { get { return AddedRevision?.DocID; } }

/// <summary>
/// Gets the Id of the new Revision.
/// </summary>
/// <value>The Id of the new Revision.</value>
public string RevisionId { get { return AddedRevision.RevID.ToString(); } }
public string RevisionId { get { return AddedRevision?.RevID?.ToString(); } }

/// <summary>
/// Gets a value indicating whether this instance is current revision.
/// </summary>
/// <value><c>true</c> if this instance is current revision; otherwise, <c>false</c>.</value>
public bool IsCurrentRevision { get { return WinningRevisionId != null && WinningRevisionId.Equals(AddedRevision.RevID.ToString()); } }

internal RevisionID WinningRevisionId { get; private set; }

/// <summary>
/// Gets the winning revision.
/// </summary>
/// <value>The winning revision.</value>
internal RevisionInternal WinningRevisionIfKnown
{
get
{
return IsCurrentRevision ? AddedRevision : null;
public bool IsCurrentRevision {
get {
return WinningRevisionId != null && WinningRevisionId.Equals(AddedRevision?.RevID?.ToString());
}
}

internal void ReduceMemoryUsage()
{
AddedRevision = AddedRevision.CopyWithoutBody();
}

/// <summary>
/// Gets a value indicating whether this instance is conflict.
/// </summary>
Expand All @@ -115,12 +86,55 @@ internal void ReduceMemoryUsage()
/// </summary>
public bool IsExpiration { get; internal set; }

/// <summary>
/// Gets whether or not this change is a deletion
/// </summary>
public bool IsDeletion {
get {
return AddedRevision?.Deleted == true;
}
}

/// <summary>
/// Gets the remote URL of the source Database from which this change was replicated.
/// </summary>
/// <value>The remote URL of the source Database from which this change was replicated.</value>
public Uri SourceUrl { get; private set; }

internal RevisionInternal AddedRevision { get; private set; }

internal RevisionID WinningRevisionId { get; }

internal RevisionInternal WinningRevisionIfKnown {
get {
return IsCurrentRevision ? AddedRevision : null;
}
}

#endregion

#region Constructors

// Used by plugins
internal DocumentChange(RevisionInternal addedRevision, RevisionID winningRevisionId, bool isConflict, Uri sourceUrl)
{
AddedRevision = addedRevision;
WinningRevisionId = winningRevisionId;
IsConflict = isConflict;
SourceUrl = sourceUrl;
}

#endregion

#region Internal Methods

internal void ReduceMemoryUsage()
{
AddedRevision = AddedRevision.CopyWithoutBody();
}



#endregion

#region Overrides
Expand Down Expand Up @@ -152,5 +166,4 @@ public override string ToString()
#endregion

}

}

0 comments on commit 1b5dd44

Please sign in to comment.