Class Post

java.lang.Object
io.github.mastodonContentMover.Post

public class Post extends Object
Holds in an XML-persistable object all the data associated with a Mastodon status, using MediaFile objects to store metadata associated with media files.

Since:
0.01.00
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Post(String postId, String mastodonId, PostArchive pa)
    Loads the Post object with the specified archiveId in the specified PostArchive from file if it is available, or creates a new Post object if no data is found for that archiveId on the filesystem within the given data directory for the specified PostArchive.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Associates with this Post object a new mastodonId String value, comprised of the Mastodon instance hostname/address concatenated with the id used for the status on that instance, and saves the change to file if persistance has not been paused.
    protected void
    addMedia(String u, String mmt, String tu, String at, float x, float y)
    Saves media from a URL and attaches it to this Post object, together with its thumbnail (when it is a video) and other metadata used by Mastodon, as a MediaFile object.
    protected String
    Gives the MastodonContentMover internal id for this Post object, based on the creation date of the Mastodon post that was first downloaded and from which this Post object, in this archive, was first created.
    protected long
    Obtains as a primitive long the number of a count of favourites for the status represented by this Post object.
    protected String
    Obtains the MastodonContentMover internal archiveId for a Post object to which this Post object is a reply.
    protected String
    Obtains as a String value an ISO 639 Part 1 two-letter language code for the Mastodon status represented by this Post object.
    protected String
    Returns the most recent Mastodon instance id used for this Post on the instance specified as a parameter.
    protected String[]
    Obtains an ordered primitive String array of all the mastodonId values associated with this Post object, each comprised of a Mastodon instance hostname/address concatenated with the id used for the status on that instance.
    protected List<MediaFile>
    Obtains media attached to this Post object, as a List of MediaFile objects.
    protected long
    Obtains as a primitive long the number of times the Mastodon status represented by this Post object was reblogged.
    protected String
    Obtains as a String the URL of a Mastodon status that was reblogged in the status this Post object represents.
    protected String
    Retrieves the value of the Mastodon spoiler_text field stored for this Post object.
    protected String
    Retrieves the plain text that comprises the body of the Mastodon status this Post object represents.
    protected String
    Obtains as a String value the visibility of the Mastodon status represented by this Post object.
    protected boolean
    Checks whether the specified mastodonId String value, comprised of a Mastodon instance hostname/address concatenated with the id used for the status on that instance, is already among those associated with this Post object.
    protected boolean
    Indicates whether this Post object has any media attachments.
    protected boolean
    isAfter(String isoDateTime)
    Determines whether this Post object was created (so far as the tool is aware) after the given date and time, specified as an ISO 8601 compliant String.
    protected boolean
    isBefore(String isoDateTime)
    Determines whether this Post object was created (so far as the tool is aware) before the given date and time, specified as an ISO 8601 compliant String.
    protected boolean
    Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is bookmarked by the account used to save it to the archive.
    protected boolean
    Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is favourited by the account used to save it to the archive.
    protected boolean
    Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is pinned by the account used to save it to the archive.
    protected boolean
    Obtains as a primitive boolean value the sensitivity of the Mastodon status represented by this Post object.
    protected void
    Halts the saving to file of changes to this Post object as and when they are made, until this behaviour is restored with .
    protected void
    Resumes the saving to file of changes to this Post object as and when they are made, and saves its current state to file.
    protected void
    Stores as a primitive long the number of favourites for the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.
    protected void
    Stores the MastodonContentMover internal archiveId for a Post object to which this Post object is a reply, and saves the change to file if persistance has not been paused.
    protected void
    setIsBookmarked(boolean ib)
    Stores as a primitive boolean whether the Mastodon status represented by this Post object is bookmarked by the account used to save it to the archive, and saves the change to file if persistance has not been paused.
    protected void
    setIsFavourited(boolean ifav)
    Stores as a primitive boolean whether the Mastodon status represented by this Post object is favourited by the account used to save it to the archive, and saves the change to file if persistance has not been paused.
    protected void
    setIsPinned(boolean ip)
    Stores as a primitive boolean whether the Mastodon status represented by this Post object is pinned by the account used to save it to the archive, and saves the change to file if persistance has not been paused.
    protected void
    setIsSensitive(boolean is)
    Stores as a primitive boolean value the sensitivity of the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.
    protected void
    Stores as a String value an ISO 639 Part 1 two-letter language code for the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.
    protected void
    setReblogsCount(long rc)
    Stores as a primitive long the number of times the Mastodon status represented by this Post object was reblogged, and saves the change to file if persistance has not been paused.
    protected void
    Stores as a String the URL of a Mastodon status that was reblogged in the status this Post object represents, and saves the change to file if persistance has not been paused.
    protected void
    Stores the value of the Mastodon spoiler_text field in this Post object, and saves the change to file if persistance has not been paused.
    protected void
    Stores the Mastodon StatusSource, which is the plain text used to compose the status, to this Post object, and saves the change to file if persistance has not been paused.
    protected void
    Stores as a String value the visibility of the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Post

      protected Post(String postId, String mastodonId, PostArchive pa) throws jakarta.xml.bind.JAXBException, IOException
      Loads the Post object with the specified archiveId in the specified PostArchive from file if it is available, or creates a new Post object if no data is found for that archiveId on the filesystem within the given data directory for the specified PostArchive.

      Currently the mastodonId parameter can be null, but it would be better if a separate constructor was made without the mastodonId parameter. This constructor could then call that constructor and perform the processing required for the mastodonId specified after receiving the Post object from that constructor (including registering it with the archive). Then parameters would never need to be null. Also the postId parameter would really be better if it was named archiveId. (TODO)

      Would also be good to mention in this doc info when this is likely to be called (TODO)

      Parameters:
      postId - the MastodonContentMover internal archiveId for this post
      mastodonId - the id for this post on a specific Mastodon instance
      pa - the PostArchive from which to load the Post object

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)
      IllegalStateException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
  • Method Details

    • getArchiveId

      protected String getArchiveId()
      Gives the MastodonContentMover internal id for this Post object, based on the creation date of the Mastodon post that was first downloaded and from which this Post object, in this archive, was first created.

      For example, if you create an archive from "instance #1", use that archive to populate "instance #2", then create a fresh archive from "instance #2", the date that will be used for this comparison will be the date you used your initial archive to populate "instance #2" (not the date you first created the post on "instance #1").

      Returns:
      the archiveId of this Post object

      Since:
      0.01.00
    • getLatestMastodonId

      protected String getLatestMastodonId(String i)
      Returns the most recent Mastodon instance id used for this Post on the instance specified as a parameter.

      Parameters:
      i - the instance address or hostname, specified as a String
      Returns:
      the most recent Mastodon instance id, comprised of the address or hostname for that instance and the internal id for this post on that instance, that was retrieved when reposting this Post from this archive to the instance specified.

      Since:
      0.01.00
      See Also:
    • addMastodonId

      protected void addMastodonId(String mi) throws jakarta.xml.bind.JAXBException, IOException
      Associates with this Post object a new mastodonId String value, comprised of the Mastodon instance hostname/address concatenated with the id used for the status on that instance, and saves the change to file if persistance has not been paused.

      Parameters:
      mi - a Mastodon instance hostname/address concatenated with a separator and the id used for the status on that instance

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • hasMastodonId

      protected boolean hasMastodonId(String mi)
      Checks whether the specified mastodonId String value, comprised of a Mastodon instance hostname/address concatenated with the id used for the status on that instance, is already among those associated with this Post object.

      Parameters:
      mi - a Mastodon instance hostname/address concatenated with a separator and the id used for the status on that instance

      Since:
      0.01.05
    • getMastodonIds

      protected String[] getMastodonIds()
      Obtains an ordered primitive String array of all the mastodonId values associated with this Post object, each comprised of a Mastodon instance hostname/address concatenated with the id used for the status on that instance.

      The array is ordered according to the sequence in which this Post object was reposted to each Mastodon instance. The same Mastodon instance may appear more than once in the list (although presumably not with the same id - if that has happened it probably means something has gone wrong, as the alternative of the same status having been assigned the same numeric id by the same instance on two separate occasions is highly unlikely - TODO: check for duplicates on adding?)

      Returns:
      an array of String objects each containing a Mastodon instance hostname/address concatenated with a separator and the id used for the status on that instance

      Since:
      0.01.00
      See Also:
    • pausePersistence

      protected void pausePersistence()
      Halts the saving to file of changes to this Post object as and when they are made, until this behaviour is restored with .

      Since:
      0.01.00
    • resumePersistence

      protected void resumePersistence() throws jakarta.xml.bind.JAXBException, IOException
      Resumes the saving to file of changes to this Post object as and when they are made, and saves its current state to file.

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
    • setText

      protected void setText(String pt) throws jakarta.xml.bind.JAXBException, IOException
      Stores the Mastodon StatusSource, which is the plain text used to compose the status, to this Post object, and saves the change to file if persistance has not been paused.

      Parameters:
      pt - the plain text that comprises the body of this post

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
    • getText

      protected String getText()
      Retrieves the plain text that comprises the body of the Mastodon status this Post object represents.

      Returns:
      the body text of this Post object in plain text

      Since:
      0.01.00
    • setSpoilerText

      protected void setSpoilerText(String st) throws jakarta.xml.bind.JAXBException, IOException
      Stores the value of the Mastodon spoiler_text field in this Post object, and saves the change to file if persistance has not been paused.

      Parameters:
      st - the text used to apply a spoiler or content warning on this post, also known elsewhere on ActivityPub as a summary

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getSpoilerText

      protected String getSpoilerText()
      Retrieves the value of the Mastodon spoiler_text field stored for this Post object.

      Returns:
      the text used to apply a spoiler or content warning on this post, also known elsewhere on ActivityPub as a summary

      Since:
      0.01.00
      See Also:
    • setVisibility

      protected void setVisibility(String v) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a String value the visibility of the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.

      As specified in the Mastodon API documentation, and must match the value used in the BigBone API used by this tool to interact with the Mastodon API.

      At time of writing, values are:

      • public = Visible to everyone, shown in public timelines.
      • unlisted = Visible to public, but not included in public timelines.
      • private = Visible to followers only, and to any mentioned users.
      • direct = Visible only to mentioned users.


      Parameters:
      v - the visibility of the status represented by this Post object

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getVisibility

      protected String getVisibility()
      Obtains as a String value the visibility of the Mastodon status represented by this Post object.

      As specified in the Mastodon API documentation, and must match the value used in the BigBone API used by this tool to interact with the Mastodon API.

      At time of writing, values are:

      • public = Visible to everyone, shown in public timelines.
      • unlisted = Visible to public, but not included in public timelines.
      • private = Visible to followers only, and to any mentioned users.
      • direct = Visible only to mentioned users.


      Returns:
      the visibility of the status represented by this Post object

      Since:
      0.01.00
      See Also:
    • setIsSensitive

      protected void setIsSensitive(boolean is) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive boolean value the sensitivity of the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.

      Parameters:
      is - true for statuses that should be concealed beneath a spoiler or content warning, or false where that is not the case

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • isSensitive

      protected boolean isSensitive()
      Obtains as a primitive boolean value the sensitivity of the Mastodon status represented by this Post object.

      Returns:
      true for statuses that should be concealed beneath a spoiler or content warning, or false where that is not the case

      Since:
      0.01.00
      See Also:
    • setInReplyToArchiveId

      protected void setInReplyToArchiveId(String irtai) throws jakarta.xml.bind.JAXBException, IOException
      Stores the MastodonContentMover internal archiveId for a Post object to which this Post object is a reply, and saves the change to file if persistance has not been paused.

      This tool only links self-replies in this way, not replies to statuses by other users.

      Parameters:
      irtai - the archiveId for a Post object to which this Post object is a reply

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getInReplyToArchiveId

      protected String getInReplyToArchiveId()
      Obtains the MastodonContentMover internal archiveId for a Post object to which this Post object is a reply.

      This tool only links self-replies in this way, not replies to statuses by other users.

      Returns:
      the archiveId for a Post object to which this Post object is a reply

      Since:
      0.01.00
      See Also:
    • setReblogUrl

      protected void setReblogUrl(String ru) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a String the URL of a Mastodon status that was reblogged in the status this Post object represents, and saves the change to file if persistance has not been paused.

      Parameters:
      ru - the url of a Mastodon status reblogged in this Post object

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getReblogUrl

      protected String getReblogUrl()
      Obtains as a String the URL of a Mastodon status that was reblogged in the status this Post object represents.

      In order to repost this reblogged status, it is necessary to search for this URL on the Mastodon instance where this Post object is being reposted, using "resolve=true", to get the status id on that instance. (This is not implemented yet - TODO!)

      Returns:
      the url of a Mastodon status reblogged in this Post object

      Since:
      0.01.00
      See Also:
    • setLanguage

      protected void setLanguage(String l) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a String value an ISO 639 Part 1 two-letter language code for the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.

      As specified in the Mastodon API documentation, and must match the value used in the BigBone API used by this tool to interact with the Mastodon API.

      Parameters:
      l - an ISO 639 Part 1 two-letter language code for the status represented by this Post object

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getLanguage

      protected String getLanguage()
      Obtains as a String value an ISO 639 Part 1 two-letter language code for the Mastodon status represented by this Post object.

      As specified in the Mastodon API documentation, and must match the value used in the BigBone API used by this tool to interact with the Mastodon API.

      Returns:
      an ISO 639 Part 1 two-letter language code for the status represented by this Post object

      Since:
      0.01.00
      See Also:
    • setIsFavourited

      protected void setIsFavourited(boolean ifav) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive boolean whether the Mastodon status represented by this Post object is favourited by the account used to save it to the archive, and saves the change to file if persistance has not been paused.

      This field may later be used to determine whether a status created when this Post is reposted should be favourited again, based also on the parameters specified when the tool is run. (TODO)

      Parameters:
      ifav - true for statuses that have been favourited by the account used to save it to the archive, or false otherwise

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • isFavourited

      protected boolean isFavourited()
      Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is favourited by the account used to save it to the archive.

      This field may later be used to determine whether a status created when this Post is reposted should be favourited again, based also on the parameters specified when the tool is run. (TODO)

      Returns:
      true for statuses that have been favourited by the account used to save it to the archive, or false otherwise

      Since:
      0.01.00
      See Also:
    • setIsBookmarked

      protected void setIsBookmarked(boolean ib) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive boolean whether the Mastodon status represented by this Post object is bookmarked by the account used to save it to the archive, and saves the change to file if persistance has not been paused.

      This field is used to determine whether a status created when this Post is reposted should be bookmarked again, based also on the parameters specified when the tool is run.

      Parameters:
      ib - true for statuses that have been bookmarked by the account used to save it to the archive, or false otherwise

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • isBookmarked

      protected boolean isBookmarked()
      Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is bookmarked by the account used to save it to the archive.

      This field is used to determine whether a status created when this Post is reposted should be bookmarked again, based also on the parameters specified when the tool is run.

      Returns:
      true for statuses that have been bookmarked by the account used to save it to the archive, or false otherwise

      Since:
      0.01.00
      See Also:
    • setIsPinned

      protected void setIsPinned(boolean ip) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive boolean whether the Mastodon status represented by this Post object is pinned by the account used to save it to the archive, and saves the change to file if persistance has not been paused.

      This field is used to determine whether a status created when this Post is reposted should be pinned again, based also on the parameters specified when the tool is run.

      Parameters:
      ip - true for statuses that have been pinned by the account used to save it to the archive, or false otherwise

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • isPinned

      protected boolean isPinned()
      Obtains a primitive boolean value that indicates whether the Mastodon status represented by this Post object is pinned by the account used to save it to the archive.

      This field is used to determine whether a status created when this Post is reposted should be pinned again, based also on the parameters specified when the tool is run.

      Returns:
      true for statuses that have been pinned by the account used to save it to the archive, or false otherwise

      Since:
      0.01.00
      See Also:
    • setFavouritesCount

      protected void setFavouritesCount(long fc) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive long the number of favourites for the Mastodon status represented by this Post object, and saves the change to file if persistance has not been paused.

      This field may later be used to determine whether or not to repost this Post object, based on a threshold specified when the tool is run. (TODO)

      Parameters:
      fc - the number of favourites for the Mastodon status represented by this Post object when it was saved to the archive

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getFavouritesCount

      protected long getFavouritesCount()
      Obtains as a primitive long the number of a count of favourites for the status represented by this Post object.

      This may later be used to determine whether or not to repost this Post object, based on a threshold specified when the tool is run. (TODO)

      Returns:
      the count of favourites for the Mastodon status represented by this Post object when it was saved to the archive

      Since:
      0.01.00
      See Also:
    • setReblogsCount

      protected void setReblogsCount(long rc) throws jakarta.xml.bind.JAXBException, IOException
      Stores as a primitive long the number of times the Mastodon status represented by this Post object was reblogged, and saves the change to file if persistance has not been paused.

      This field may later be used to determine whether or not to repost this Post object, based on a threshold specified when the tool is run. (TODO)

      Parameters:
      rc - the number of times the Mastodon status represented by this Post object had been reblogged when it was saved to the archive

      Throws:
      jakarta.xml.bind.JAXBException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • getReblogsCount

      protected long getReblogsCount()
      Obtains as a primitive long the number of times the Mastodon status represented by this Post object was reblogged.

      This may later be used to determine whether or not to repost this Post object, based on a threshold specified when the tool is run. (TODO)

      Returns:
      the number of times the Mastodon status represented by this Post object had been reblogged when it was saved to the archive

      Since:
      0.01.00
      See Also:
    • addMedia

      protected void addMedia(String u, String mmt, String tu, String at, float x, float y) throws FileNotFoundException, MalformedURLException, IOException
      Saves media from a URL and attaches it to this Post object, together with its thumbnail (when it is a video) and other metadata used by Mastodon, as a MediaFile object.

      Parameters:
      u - the URL for the media file
      mmt - the media type as specified by/for Mastodon
      tu - the URL of the thumbnail for this media
      at - the "alt text" or description of this media
      x - the x-coordinate of the Mastodon focal point for this media
      y - the y-coordinate of the Mastodon focal point for this media

      Throws:
      FileNotFoundException - (TODO: add more info here on when this happens)
      MalformedURLException - (TODO: add more info here on when this happens)
      IOException - (TODO: add more info here on when this happens)

      Since:
      0.01.00
      See Also:
    • hasMedia

      protected boolean hasMedia()
      Indicates whether this Post object has any media attachments.

      Returns:
      true if this Post object has any media attachments, or false otherwise

      Since:
      0.01.00
    • getMedia

      protected List<MediaFile> getMedia()
      Obtains media attached to this Post object, as a List of MediaFile objects.

      A read-only, deep-cloned version *should* be returned here; right now the objects returned are the actual data objects held within this Post object, when there is no need to modify them programmatically. This should be fixed *asap* as inadvertent changes to the data within could then be persisted and the archive may be damaged (TODO: make MediaFile cloneable then do a deep copy of the array list here)

      Returns:
      a List of MediaFile objects representing the media that attached to the status represented by this Post object.

      Since:
      0.01.00
      See Also:
    • isAfter

      protected boolean isAfter(String isoDateTime)
      Determines whether this Post object was created (so far as the tool is aware) after the given date and time, specified as an ISO 8601 compliant String.

      This relies on the archiveId of the post, which in turn is based on the creation date of the Mastodon post that was first downloaded and from which this Post object, in this archive, was first created.

      Handling of dates and their conversion into archiveIds is done by PostArchive

      Parameters:
      isoDateTime - an ISO 8601 compliant String
      Returns:
      true if this Post was created after the specified date and time, or false otherwise

      Since:
      0.01.00
      See Also:
    • isBefore

      protected boolean isBefore(String isoDateTime)
      Determines whether this Post object was created (so far as the tool is aware) before the given date and time, specified as an ISO 8601 compliant String.

      This relies on the archiveId of the post, which in turn is based on the creation date of the Mastodon post that was first downloaded and from which this Post object, in this archive, was first created.

      Handling of dates and their conversion into archiveIds is done by PostArchive

      Parameters:
      isoDateTime - an ISO 8601 compliant String
      Returns:
      true if this Post was created before the specified date and time, or false otherwise

      Since:
      0.01.00
      See Also: