From 8563855be11144e48b7398113288a791c216db07 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 6 Sep 2017 01:13:53 +0200 Subject: [PATCH] Add edited_at property to entities with a text property --- docs/_entities/comment.md | 23 ++++++++------- docs/_entities/message.md | 20 ++++++++----- docs/_entities/photo.md | 29 ++++++++++--------- docs/_entities/status_message.md | 29 ++++++++++--------- lib/diaspora_federation/entities/comment.rb | 5 ++++ lib/diaspora_federation/entities/message.rb | 5 ++++ lib/diaspora_federation/entities/photo.rb | 5 ++++ .../entities/status_message.rb | 5 ++++ lib/diaspora_federation/test/factories.rb | 5 ++++ .../entities/comment_spec.rb | 10 ++++--- .../entities/message_spec.rb | 1 + .../entities/photo_spec.rb | 2 ++ .../entities/status_message_spec.rb | 6 ++++ 13 files changed, 95 insertions(+), 50 deletions(-) diff --git a/docs/_entities/comment.md b/docs/_entities/comment.md index 27e8891..b07f3b6 100644 --- a/docs/_entities/comment.md +++ b/docs/_entities/comment.md @@ -9,20 +9,21 @@ See also: [Relayable][relayable] ## Properties -| Property | Type (Length) | Description | -| ------------------------- | ---------------------------- | ----------------------------------------------- | -| `author` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the author of the comment. | -| `guid` | [GUID][guid] | The GUID of the comment. | -| `parent_guid` | [GUID][guid] | The GUID of the parent entity. | -| `text` | [Markdown][markdown] (65535) | The comment text. | -| `created_at` | [Timestamp][timestamp] | The create timestamp of the comment. | -| `author_signature` | [Signature][signature] | The signature from the author of the comment. | +| Property | Type (Length) | Editable | Description | +| ------------------------- | ---------------------------- |:--------:| ----------------------------------------------- | +| `author` | [diaspora\* ID][diaspora-id] | ✘ | The diaspora\* ID of the author of the comment. | +| `guid` | [GUID][guid] | ✘ | The GUID of the comment. | +| `parent_guid` | [GUID][guid] | ✘ | The GUID of the parent entity. | +| `text` | [Markdown][markdown] (65535) | ✔ | The comment text. | +| `created_at` | [Timestamp][timestamp] | ✘ | The create timestamp of the comment. | +| `author_signature` | [Signature][signature] | ✔ | The signature from the author of the comment. | ## Optional Properties -| Property | Type (Length) | Description | -| -------------------- | ------------- | --------------------------------------------- | -| `thread_parent_guid` | [GUID][guid] | The GUID of the parent comment in the thread. | +| Property | Type (Length) | Editable | Description | +| -------------------- | ---------------------- |:--------:| --------------------------------------------- | +| `edited_at` | [Timestamp][timestamp] | ✔ | The timestamp when the comment was edited. | +| `thread_parent_guid` | [GUID][guid] | ✘ | The GUID of the parent comment in the thread. | ## Examples diff --git a/docs/_entities/message.md b/docs/_entities/message.md index 15afa47..c1cf46b 100644 --- a/docs/_entities/message.md +++ b/docs/_entities/message.md @@ -7,13 +7,19 @@ This entity represents a private message exchanged in private conversation. It c ## Properties -| Property | Type (Length) | Description | -| ------------------- | ---------------------------- | ----------------------------------------------- | -| `author` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the author of the message. | -| `guid` | [GUID][guid] | The GUID of the message. | -| `conversation_guid` | [GUID][guid] | The GUID of the [Conversation][conversation]. | -| `text` | [Markdown][markdown] (65535) | The message text. | -| `created_at` | [Timestamp][timestamp] | The create timestamp of the message. | +| Property | Type (Length) | Editable | Description | +| ------------------- | ---------------------------- |:--------:| ----------------------------------------------- | +| `author` | [diaspora\* ID][diaspora-id] | ✘ | The diaspora\* ID of the author of the message. | +| `guid` | [GUID][guid] | ✘ | The GUID of the message. | +| `conversation_guid` | [GUID][guid] | ✘ | The GUID of the [Conversation][conversation]. | +| `text` | [Markdown][markdown] (65535) | ✔ | The message text. | +| `created_at` | [Timestamp][timestamp] | ✘ | The create timestamp of the message. | + +## Optional Properties + +| Property | Type (Length) | Editable | Description | +| -------------------- | ---------------------- |:--------:| ------------------------------------------ | +| `edited_at` | [Timestamp][timestamp] | ✔ | The timestamp when the message was edited. | ## Example diff --git a/docs/_entities/photo.md b/docs/_entities/photo.md index caf9acd..c928891 100644 --- a/docs/_entities/photo.md +++ b/docs/_entities/photo.md @@ -6,23 +6,24 @@ This entity represents a photo. It can be standalone or nested in a [StatusMessa ## Properties -| Property | Type (Length) | Description | -| ------------------- | ---------------------------- | ---------------------------------------------------------------- | -| `author` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the author of the photo. | -| `guid` | [GUID][guid] | The GUID of the photo. | -| `public` | [Boolean][boolean] | `true` if the photo is public. | -| `created_at` | [Timestamp][timestamp] | The create timestamp of the photo. | -| `remote_photo_path` | [URL][url] | The URL to the photo, without filename (see `remote_photo_name`) | -| `remote_photo_name` | [String][string] (255) | The filename of the photo. | +| Property | Type (Length) | Editable | Description | +| ------------------- | ---------------------------- |:--------:| ---------------------------------------------------------------- | +| `author` | [diaspora\* ID][diaspora-id] | ✘ | The diaspora\* ID of the author of the photo. | +| `guid` | [GUID][guid] | ✘ | The GUID of the photo. | +| `public` | [Boolean][boolean] | ✘ | `true` if the photo is public. | +| `created_at` | [Timestamp][timestamp] | ✘ | The create timestamp of the photo. | +| `remote_photo_path` | [URL][url] | ✔ | The URL to the photo, without filename (see `remote_photo_name`) | +| `remote_photo_name` | [String][string] (255) | ✔ | The filename of the photo. | ## Optional Properties -| Property | Type (Length) | Description | -| --------------------- | ------------------------ | ------------------------------------------------------------------------------- | -| `text` | [String][string] (65535) | Description text for the photo. | -| `status_message_guid` | [GUID][guid] | The GUID of the [StatusMessage][status_message] to which the photo is attached. | -| `height` | [Integer][integer] | The height of the photo in pixels. | -| `width` | [Integer][integer] | The width of the photo in pixels. | +| Property | Type (Length) | Editable | Description | +| --------------------- | ------------------------ |:--------:| ------------------------------------------------------------------------------- | +| `edited_at` | [Timestamp][timestamp] | ✔ | The timestamp when the photo was edited. | +| `text` | [String][string] (65535) | ✔ | Description text for the photo. | +| `status_message_guid` | [GUID][guid] | ✘ | The GUID of the [StatusMessage][status_message] to which the photo is attached. | +| `height` | [Integer][integer] | ✔ | The height of the photo in pixels. | +| `width` | [Integer][integer] | ✔ | The width of the photo in pixels. | ## Example diff --git a/docs/_entities/status_message.md b/docs/_entities/status_message.md index 1302f4f..6bb1fb7 100644 --- a/docs/_entities/status_message.md +++ b/docs/_entities/status_message.md @@ -6,23 +6,24 @@ This entity represents a reshare of a status message. It inherits from [Post][po ## Properties -| Property | Type (Length) | Description | -| ------------ | ---------------------------- | ------------------------------------------------------ | -| `author` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the author of the status message. | -| `guid` | [GUID][guid] | The GUID of the status message. | -| `created_at` | [Timestamp][timestamp] | The create timestamp of the status message. | -| `public` | [Boolean][boolean] | `true` if the status message is public. | -| `text` | [Markdown][markdown] (65535) | The status message text. | +| Property | Type (Length) | Editable | Description | +| ------------ | ---------------------------- |:--------:| ------------------------------------------------------ | +| `author` | [diaspora\* ID][diaspora-id] | ✘ | The diaspora\* ID of the author of the status message. | +| `guid` | [GUID][guid] | ✘ | The GUID of the status message. | +| `created_at` | [Timestamp][timestamp] | ✘ | The create timestamp of the status message. | +| `public` | [Boolean][boolean] | ✘ | `true` if the status message is public. | +| `text` | [Markdown][markdown] (65535) | ✔ | The status message text. | ## Optional Properties -| Property | Type (Length) | Description | -| ----------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------- | -| `provider_display_name` | [String][string] (255) | The means by which the author has posted the status message. | -| `location` | [Location][location] | The Location information of the status message. | -| `photo` | [Photo][photo]s | The attached Photos of the status message, the `status_message_guid` and the `author` need to match the status message. | -| `poll` | [Poll][poll] | The attached Poll of the status message. | -| `event` | [Event][event] | The attached Event of the status message. | +| Property | Type (Length) | Editable | Description | +| ----------------------- | ---------------------- |:--------:| ----------------------------------------------------------------------------------------------------------------------- | +| `edited_at` | [Timestamp][timestamp] | ✔ | The timestamp when the status message was edited. | +| `provider_display_name` | [String][string] (255) | ✘ | The means by which the author has posted the status message. | +| `location` | [Location][location] | ✔ | The Location information of the status message. | +| `photo` | [Photo][photo]s | ✔ | The attached Photos of the status message, the `status_message_guid` and the `author` need to match the status message. | +| `poll` | [Poll][poll] | ✘ | The attached Poll of the status message. | +| `event` | [Event][event] | ✘ | The attached Event of the status message. | ## Examples diff --git a/lib/diaspora_federation/entities/comment.rb b/lib/diaspora_federation/entities/comment.rb index b5929ef..b3f05e7 100644 --- a/lib/diaspora_federation/entities/comment.rb +++ b/lib/diaspora_federation/entities/comment.rb @@ -17,6 +17,11 @@ module DiasporaFederation # Comment entity creation time # @return [Time] creation time property :created_at, :timestamp, default: -> { Time.now.utc } + + # @!attribute [r] edited_at + # The timestamp when the comment was edited + # @return [Time] edited time + property :edited_at, :timestamp, optional: true end end end diff --git a/lib/diaspora_federation/entities/message.rb b/lib/diaspora_federation/entities/message.rb index ad10c07..c43b53b 100644 --- a/lib/diaspora_federation/entities/message.rb +++ b/lib/diaspora_federation/entities/message.rb @@ -26,6 +26,11 @@ module DiasporaFederation # @return [Time] creation time property :created_at, :timestamp, default: -> { Time.now.utc } + # @!attribute [r] edited_at + # The timestamp when the message was edited + # @return [Time] edited time + property :edited_at, :timestamp, optional: true + # @!attribute [r] conversation_guid # Guid of a conversation this message belongs to # @see Conversation#guid diff --git a/lib/diaspora_federation/entities/photo.rb b/lib/diaspora_federation/entities/photo.rb index b6c847d..0e60f31 100644 --- a/lib/diaspora_federation/entities/photo.rb +++ b/lib/diaspora_federation/entities/photo.rb @@ -26,6 +26,11 @@ module DiasporaFederation # @return [Time] creation time property :created_at, :timestamp, default: -> { Time.now.utc } + # @!attribute [r] edited_at + # The timestamp when the photo was edited + # @return [Time] edited time + property :edited_at, :timestamp, optional: true + # @!attribute [r] remote_photo_path # An url of the photo on a remote server # @return [String] remote photo url diff --git a/lib/diaspora_federation/entities/status_message.rb b/lib/diaspora_federation/entities/status_message.rb index d777b42..c2eda40 100644 --- a/lib/diaspora_federation/entities/status_message.rb +++ b/lib/diaspora_federation/entities/status_message.rb @@ -11,6 +11,11 @@ module DiasporaFederation # @return [String] text of the status message property :text, :string, xml_name: :raw_message + # @!attribute [r] edited_at + # The timestamp when the status message was edited + # @return [Time] edited time + property :edited_at, :timestamp, optional: true + # @!attribute [r] photos # Optional photos attached to the status message # @return [[Entities::Photo]] photos diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb index 253d73f..2f7ca84 100644 --- a/lib/diaspora_federation/test/factories.rb +++ b/lib/diaspora_federation/test/factories.rb @@ -81,6 +81,7 @@ module DiasporaFederation author { Fabricate.sequence(:diaspora_id) } public true created_at { Time.now.utc } + edited_at { Time.now.utc + 3600 } remote_photo_path "https://diaspora.example.tld/uploads/images/" remote_photo_name "f2a41e9d2db4d9a199c8.jpg" text "what you see here..." @@ -107,6 +108,7 @@ module DiasporaFederation guid { Fabricate.sequence(:guid) } public true created_at { Time.now.utc } + edited_at { Time.now.utc + 3600 } end Fabricator(:contact_entity, class_name: DiasporaFederation::Entities::Contact) do @@ -121,6 +123,8 @@ module DiasporaFederation author { Fabricate.sequence(:diaspora_id) } guid { Fabricate.sequence(:guid) } text "this is a very informative comment" + created_at { Time.now.utc } + edited_at { Time.now.utc + 3600 } end Fabricator(:like_entity, class_name: DiasporaFederation::Entities::Like, from: :relayable_entity) do @@ -144,6 +148,7 @@ module DiasporaFederation author { Fabricate.sequence(:diaspora_id) } text "this is a very informative text" created_at { Time.now.utc } + edited_at { Time.now.utc + 3600 } conversation_guid { Fabricate.sequence(:guid) } end diff --git a/spec/lib/diaspora_federation/entities/comment_spec.rb b/spec/lib/diaspora_federation/entities/comment_spec.rb index 41016d3..1263510 100644 --- a/spec/lib/diaspora_federation/entities/comment_spec.rb +++ b/spec/lib/diaspora_federation/entities/comment_spec.rb @@ -8,8 +8,7 @@ module DiasporaFederation :comment_entity, author: alice.diaspora_id, parent_guid: parent.guid, - parent: parent_entity, - created_at: Time.now.utc + parent: parent_entity ).tap {|hash| add_signatures(hash) } } @@ -20,6 +19,7 @@ module DiasporaFederation #{parent.guid} #{data[:text]} #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} #{data[:author_signature]} #{data[:parent_author_signature]} @@ -34,14 +34,16 @@ XML "parent_guid": "#{parent.guid}", "author_signature": "#{data[:author_signature]}", "text": "#{data[:text]}", - "created_at": "#{data[:created_at].iso8601}" + "created_at": "#{data[:created_at].iso8601}", + "edited_at": "#{data[:edited_at].iso8601}" }, "property_order": [ "author", "guid", "parent_guid", "text", - "created_at" + "created_at", + "edited_at" ] } JSON diff --git a/spec/lib/diaspora_federation/entities/message_spec.rb b/spec/lib/diaspora_federation/entities/message_spec.rb index 25412b0..d8aa86d 100644 --- a/spec/lib/diaspora_federation/entities/message_spec.rb +++ b/spec/lib/diaspora_federation/entities/message_spec.rb @@ -8,6 +8,7 @@ module DiasporaFederation #{data[:guid]} #{data[:text]} #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} #{data[:conversation_guid]} XML diff --git a/spec/lib/diaspora_federation/entities/photo_spec.rb b/spec/lib/diaspora_federation/entities/photo_spec.rb index bb30d9e..742f3f9 100644 --- a/spec/lib/diaspora_federation/entities/photo_spec.rb +++ b/spec/lib/diaspora_federation/entities/photo_spec.rb @@ -8,6 +8,7 @@ module DiasporaFederation #{data[:author]} #{data[:public]} #{data[:created_at].utc.iso8601} + #{data[:edited_at].utc.iso8601} #{data[:remote_photo_path]} #{data[:remote_photo_name]} #{data[:text]} @@ -25,6 +26,7 @@ XML "author": "#{data[:author]}", "public": #{data[:public]}, "created_at": "#{data[:created_at].utc.iso8601}", + "edited_at": "#{data[:edited_at].iso8601}", "remote_photo_path": "#{data[:remote_photo_path]}", "remote_photo_name": "#{data[:remote_photo_name]}", "text": "#{data[:text]}", diff --git a/spec/lib/diaspora_federation/entities/status_message_spec.rb b/spec/lib/diaspora_federation/entities/status_message_spec.rb index 3abe6b0..52d550a 100644 --- a/spec/lib/diaspora_federation/entities/status_message_spec.rb +++ b/spec/lib/diaspora_federation/entities/status_message_spec.rb @@ -22,11 +22,13 @@ module DiasporaFederation #{data[:public]} #{data[:provider_display_name]} #{data[:text]} + #{data[:edited_at].utc.iso8601} #{photo1.guid} #{photo1.author} #{photo1.public} #{photo1.created_at.utc.iso8601} + #{photo1.edited_at.utc.iso8601} #{photo1.remote_photo_path} #{photo1.remote_photo_name} #{photo1.text} @@ -39,6 +41,7 @@ module DiasporaFederation #{photo2.author} #{photo2.public} #{photo2.created_at.utc.iso8601} + #{photo2.edited_at.utc.iso8601} #{photo2.remote_photo_path} #{photo2.remote_photo_name} #{photo2.text} @@ -64,6 +67,7 @@ XML "public": #{data[:public]}, "provider_display_name": "#{data[:provider_display_name]}", "text": "#{data[:text]}", + "edited_at": "#{data[:edited_at].iso8601}", "photos": [ { "entity_type": "photo", @@ -72,6 +76,7 @@ XML "author": "#{photo1.author}", "public": #{photo1.public}, "created_at": "#{photo1.created_at.utc.iso8601}", + "edited_at": "#{photo1.edited_at.utc.iso8601}", "remote_photo_path": "#{photo1.remote_photo_path}", "remote_photo_name": "#{photo1.remote_photo_name}", "text": "#{photo1.text}", @@ -87,6 +92,7 @@ XML "author": "#{photo2.author}", "public": #{photo2.public}, "created_at": "#{photo2.created_at.utc.iso8601}", + "edited_at": "#{photo2.edited_at.utc.iso8601}", "remote_photo_path": "#{photo2.remote_photo_path}", "remote_photo_name": "#{photo2.remote_photo_name}", "text": "#{photo2.text}",