Record Class Jid

java.lang.Object
java.lang.Record
it.auties.whatsapp.model.jid.Jid
All Implemented Interfaces:
JidProvider

public record Jid(String user, JidServer server, Integer device, Integer agent) extends Record implements JidProvider
A model class that represents a jid. This class is only a model, this means that changing its values will have no real effect on WhatsappWeb's servers.
  • Field Details

    • user

      private final String user
      The field for the user record component.
    • server

      private final JidServer server
      The field for the server record component.
    • device

      private final Integer device
      The field for the device record component.
    • agent

      private final Integer agent
      The field for the agent record component.
  • Constructor Details

  • Method Details

    • ofServer

      public static Jid ofServer(JidServer server)
      Constructs a new ContactId that represents a server
      Parameters:
      server - the non-null custom server
      Returns:
      a non-null contact jid
    • ofProtobuf

      public static Jid ofProtobuf(String input)
    • of

      public static Jid of(String jid, JidServer server)
      Constructs a new ContactId for a user from a jid and a custom server
      Parameters:
      jid - the nullable jid of the user
      server - the non-null custom server
      Returns:
      a non-null contact jid
    • withoutServer

      public static String withoutServer(String jid)
      Parses a nullable jid to the Whatsapp Jid Format
      Parameters:
      jid - the nullable jid to parse
      Returns:
      null if jid == null, otherwise a non-null string
    • tryParseAgent

      private static Integer tryParseAgent(String string)
    • ofDevice

      public static Jid ofDevice(String jid, int device)
      Constructs a new ContactId for a device
      Parameters:
      jid - the nullable jid of the user
      device - the device jid
      Returns:
      a non-null contact jid
    • of

      public static Jid of(String jid)
      Constructs a new ContactId for a user from a jid
      Parameters:
      jid - the non-null jid of the user
      Returns:
      a non-null contact jid
    • of

      public static Jid of(long jid)
      Constructs a new ContactId for a user from a jid
      Parameters:
      jid - the non-null jid of the user
      Returns:
      a non-null contact jid
    • type

      public JidType type()
      Returns the type of this jid
      Returns:
      a non null type
    • isCompanion

      public boolean isCompanion()
      Returns whether this jid is associated with a companion device
      Returns:
      true if this jid is a companion
    • hasServer

      public boolean hasServer(JidServer server)
      Returns whether this jid ends with the provided server
      Parameters:
      server - the server to check against
      Returns:
      a boolean
    • isServerJid

      public boolean isServerJid(JidServer server)
      Returns whether this jid is a server jid
      Parameters:
      server - the server to check against
      Returns:
      a boolean
    • withServer

      public Jid withServer(JidServer server)
      Returns a new jid using with a different server
      Parameters:
      server - the new server
      Returns:
      a non-null jid
    • toSimpleJid

      public Jid toSimpleJid()
      Converts this jid to a user jid
      Returns:
      a non-null jid
    • toPhoneNumber

      public String toPhoneNumber()
      Converts this jid to a non-formatted phone number
      Returns:
      a non-null String
    • toString

      public String toString()
      Converts this jid to a String
      Specified by:
      toString in class Record
      Returns:
      a non-null String
    • toSignalAddress

      public SessionAddress toSignalAddress()
      Converts this jid to a signal address
      Returns:
      a non-null SessionAddress
    • toJid

      public Jid toJid()
      Returns this object as a jid
      Specified by:
      toJid in interface JidProvider
      Returns:
      a non-null jid
    • device

      public Integer device()
      Returns the value of the device record component.
      Returns:
      the value of the device record component
    • hasDevice

      public boolean hasDevice()
      Returns whether this jid specifies a device
      Returns:
      a boolean
    • agent

      public Integer agent()
      Returns the value of the agent record component.
      Returns:
      the value of the agent record component
    • hasAgent

      public boolean hasAgent()
      Returns whether this jid specifies an agent
      Returns:
      a boolean
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • user

      public String user()
      Returns the value of the user record component.
      Returns:
      the value of the user record component
    • server

      public JidServer server()
      Returns the value of the server record component.
      Returns:
      the value of the server record component