mirror of
https://github.com/ahabhyde/miguelbridge
synced 2025-01-10 14:34:21 +01:00
Aggiunto Codice
This commit is contained in:
parent
f92450a76d
commit
3fd7446592
2
.gitignore
vendored
2
.gitignore
vendored
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
|
|
||||||
# Ignored files:
|
# Ignored files:
|
||||||
|
# MiguelBridge Bot
|
||||||
|
files/
|
||||||
|
|
||||||
# NetBeans
|
# NetBeans
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
|
674
LICENSE
674
LICENSE
@ -1,674 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
BIN
botIcon.png
Normal file
BIN
botIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
lib/json-simple-1.1.1.jar
Normal file
BIN
lib/json-simple-1.1.1.jar
Normal file
Binary file not shown.
BIN
lib/telegrambots-3.0-jar-with-dependencies.jar
Normal file
BIN
lib/telegrambots-3.0-jar-with-dependencies.jar
Normal file
Binary file not shown.
@ -54,7 +54,43 @@ is divided into following sections:
|
|||||||
<property file="nbproject/project.properties"/>
|
<property file="nbproject/project.properties"/>
|
||||||
</target>
|
</target>
|
||||||
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
|
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
|
||||||
<property name="platform.java" value="${java.home}/bin/java"/>
|
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
|
||||||
|
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
|
||||||
|
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
|
||||||
|
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
|
||||||
|
<condition property="platform.javac" value="${platform.home}/bin/javac">
|
||||||
|
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
|
||||||
|
</condition>
|
||||||
|
<property name="platform.javac" value="${platform.javac.tmp}"/>
|
||||||
|
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
|
||||||
|
<condition property="platform.java" value="${platform.home}/bin/java">
|
||||||
|
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
|
||||||
|
</condition>
|
||||||
|
<property name="platform.java" value="${platform.java.tmp}"/>
|
||||||
|
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
|
||||||
|
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
|
||||||
|
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
|
||||||
|
</condition>
|
||||||
|
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
|
||||||
|
<condition property="platform.invalid" value="true">
|
||||||
|
<or>
|
||||||
|
<contains string="${platform.javac}" substring="$${platforms."/>
|
||||||
|
<contains string="${platform.java}" substring="$${platforms."/>
|
||||||
|
<contains string="${platform.javadoc}" substring="$${platforms."/>
|
||||||
|
</or>
|
||||||
|
</condition>
|
||||||
|
<fail unless="platform.home">Must set platform.home</fail>
|
||||||
|
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
|
||||||
|
<fail unless="platform.java">Must set platform.java</fail>
|
||||||
|
<fail unless="platform.javac">Must set platform.javac</fail>
|
||||||
|
<fail if="platform.invalid">
|
||||||
|
The J2SE Platform is not correctly set up.
|
||||||
|
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
|
||||||
|
Either open the project in the IDE and setup the Platform with the same name or add it manually.
|
||||||
|
For example like this:
|
||||||
|
ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
|
||||||
|
or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used)
|
||||||
|
</fail>
|
||||||
<available file="${manifest.file}" property="manifest.available"/>
|
<available file="${manifest.file}" property="manifest.available"/>
|
||||||
<condition property="splashscreen.available">
|
<condition property="splashscreen.available">
|
||||||
<and>
|
<and>
|
||||||
@ -183,15 +219,6 @@ is divided into following sections:
|
|||||||
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
|
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
|
||||||
<isset property="profile.available"/>
|
<isset property="profile.available"/>
|
||||||
</condition>
|
</condition>
|
||||||
<condition else="false" property="jdkBug6558476">
|
|
||||||
<and>
|
|
||||||
<matches pattern="1\.[56]" string="${java.specification.version}"/>
|
|
||||||
<not>
|
|
||||||
<os family="unix"/>
|
|
||||||
</not>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<property name="javac.fork" value="${jdkBug6558476}"/>
|
|
||||||
<property name="jar.index" value="false"/>
|
<property name="jar.index" value="false"/>
|
||||||
<property name="jar.index.metainf" value="${jar.index}"/>
|
<property name="jar.index.metainf" value="${jar.index}"/>
|
||||||
<property name="copylibs.rebase" value="true"/>
|
<property name="copylibs.rebase" value="true"/>
|
||||||
@ -260,7 +287,7 @@ is divided into following sections:
|
|||||||
<property location="${build.dir}/empty" name="empty.dir"/>
|
<property location="${build.dir}/empty" name="empty.dir"/>
|
||||||
<mkdir dir="${empty.dir}"/>
|
<mkdir dir="${empty.dir}"/>
|
||||||
<mkdir dir="@{apgeneratedsrcdir}"/>
|
<mkdir dir="@{apgeneratedsrcdir}"/>
|
||||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||||
<src>
|
<src>
|
||||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||||
<include name="*"/>
|
<include name="*"/>
|
||||||
@ -300,7 +327,7 @@ is divided into following sections:
|
|||||||
<sequential>
|
<sequential>
|
||||||
<property location="${build.dir}/empty" name="empty.dir"/>
|
<property location="${build.dir}/empty" name="empty.dir"/>
|
||||||
<mkdir dir="${empty.dir}"/>
|
<mkdir dir="${empty.dir}"/>
|
||||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||||
<src>
|
<src>
|
||||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||||
<include name="*"/>
|
<include name="*"/>
|
||||||
@ -381,7 +408,7 @@ is divided into following sections:
|
|||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<property name="junit.forkmode" value="perTest"/>
|
<property name="junit.forkmode" value="perTest"/>
|
||||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||||
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
||||||
<syspropertyset>
|
<syspropertyset>
|
||||||
<propertyref prefix="test-sys-prop."/>
|
<propertyref prefix="test-sys-prop."/>
|
||||||
@ -404,7 +431,7 @@ is divided into following sections:
|
|||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<property name="junit.forkmode" value="perTest"/>
|
<property name="junit.forkmode" value="perTest"/>
|
||||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||||
<batchtest todir="${build.test.results.dir}">
|
<batchtest todir="${build.test.results.dir}">
|
||||||
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
|
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
|
||||||
<filename name="@{testincludes}"/>
|
<filename name="@{testincludes}"/>
|
||||||
@ -443,7 +470,7 @@ is divided into following sections:
|
|||||||
</fileset>
|
</fileset>
|
||||||
</union>
|
</union>
|
||||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
||||||
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MiguelBridge" testname="TestNG tests" workingDir="${work.dir}">
|
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MiguelBridge" testname="TestNG tests" workingDir="${work.dir}">
|
||||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||||
<propertyset>
|
<propertyset>
|
||||||
<propertyref prefix="test-sys-prop."/>
|
<propertyref prefix="test-sys-prop."/>
|
||||||
@ -523,7 +550,7 @@ is divided into following sections:
|
|||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<property name="junit.forkmode" value="perTest"/>
|
<property name="junit.forkmode" value="perTest"/>
|
||||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||||
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
||||||
<syspropertyset>
|
<syspropertyset>
|
||||||
<propertyref prefix="test-sys-prop."/>
|
<propertyref prefix="test-sys-prop."/>
|
||||||
@ -548,7 +575,7 @@ is divided into following sections:
|
|||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<property name="junit.forkmode" value="perTest"/>
|
<property name="junit.forkmode" value="perTest"/>
|
||||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||||
<batchtest todir="${build.test.results.dir}">
|
<batchtest todir="${build.test.results.dir}">
|
||||||
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
|
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
|
||||||
<filename name="@{testincludes}"/>
|
<filename name="@{testincludes}"/>
|
||||||
@ -728,6 +755,9 @@ is divided into following sections:
|
|||||||
<classpath>
|
<classpath>
|
||||||
<path path="@{classpath}"/>
|
<path path="@{classpath}"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
<bootclasspath>
|
||||||
|
<path path="${platform.bootcp}"/>
|
||||||
|
</bootclasspath>
|
||||||
</nbjpdastart>
|
</nbjpdastart>
|
||||||
</sequential>
|
</sequential>
|
||||||
</macrodef>
|
</macrodef>
|
||||||
@ -743,7 +773,9 @@ is divided into following sections:
|
|||||||
</macrodef>
|
</macrodef>
|
||||||
</target>
|
</target>
|
||||||
<target name="-init-debug-args">
|
<target name="-init-debug-args">
|
||||||
<property name="version-output" value="java version "${ant.java.version}"/>
|
<exec executable="${platform.java}" outputproperty="version-output">
|
||||||
|
<arg value="-version"/>
|
||||||
|
</exec>
|
||||||
<condition property="have-jdk-older-than-1.4">
|
<condition property="have-jdk-older-than-1.4">
|
||||||
<or>
|
<or>
|
||||||
<contains string="${version-output}" substring="java version "1.0"/>
|
<contains string="${version-output}" substring="java version "1.0"/>
|
||||||
@ -768,7 +800,7 @@ is divided into following sections:
|
|||||||
<attribute default="${debug.classpath}" name="classpath"/>
|
<attribute default="${debug.classpath}" name="classpath"/>
|
||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<java classname="@{classname}" dir="${work.dir}" fork="true">
|
<java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
|
||||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||||
<jvmarg line="${debug-args-line}"/>
|
<jvmarg line="${debug-args-line}"/>
|
||||||
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
||||||
@ -795,7 +827,7 @@ is divided into following sections:
|
|||||||
<attribute default="jvm" name="jvm"/>
|
<attribute default="jvm" name="jvm"/>
|
||||||
<element name="customize" optional="true"/>
|
<element name="customize" optional="true"/>
|
||||||
<sequential>
|
<sequential>
|
||||||
<java classname="@{classname}" dir="${work.dir}" fork="true">
|
<java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
|
||||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||||
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
||||||
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
||||||
@ -993,7 +1025,7 @@ is divided into following sections:
|
|||||||
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
|
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
|
||||||
<echo level="info">To run this application from the command line without Ant, try:</echo>
|
<echo level="info">To run this application from the command line without Ant, try:</echo>
|
||||||
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
||||||
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
|
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
|
||||||
</target>
|
</target>
|
||||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
|
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
|
||||||
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
|
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
|
||||||
@ -1202,10 +1234,13 @@ is divided into following sections:
|
|||||||
</not>
|
</not>
|
||||||
</and>
|
</and>
|
||||||
</condition>
|
</condition>
|
||||||
|
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
|
||||||
|
<arg value="-version"/>
|
||||||
|
</exec>
|
||||||
<condition else="" property="bug5101868workaround" value="*.java">
|
<condition else="" property="bug5101868workaround" value="*.java">
|
||||||
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
|
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
|
||||||
</condition>
|
</condition>
|
||||||
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
|
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
|
||||||
<classpath>
|
<classpath>
|
||||||
<path path="${javac.classpath}"/>
|
<path path="${javac.classpath}"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
build.xml.data.CRC32=84bad5c7
|
build.xml.data.CRC32=8bbdab13
|
||||||
build.xml.script.CRC32=cdd627cf
|
build.xml.script.CRC32=cdd627cf
|
||||||
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
|
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
nbproject/build-impl.xml.data.CRC32=84bad5c7
|
nbproject/build-impl.xml.data.CRC32=8bbdab13
|
||||||
nbproject/build-impl.xml.script.CRC32=06f300cf
|
nbproject/build-impl.xml.script.CRC32=d8a421a0
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
|
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processor.options=
|
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
application.title=MiguelBridge
|
||||||
|
application.vendor=Emanuele Magon
|
||||||
build.classes.dir=${build.dir}/classes
|
build.classes.dir=${build.dir}/classes
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
@ -26,10 +27,15 @@ dist.archive.excludes=
|
|||||||
dist.dir=dist
|
dist.dir=dist
|
||||||
dist.jar=${dist.dir}/MiguelBridge.jar
|
dist.jar=${dist.dir}/MiguelBridge.jar
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
|
file.reference.json-simple-1.1.1.jar=lib\\json-simple-1.1.1.jar
|
||||||
|
file.reference.telegrambots-3.0-jar-with-dependencies.jar=lib\\telegrambots-3.0-jar-with-dependencies.jar
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
javac.classpath=
|
javac.classpath=\
|
||||||
|
${file.reference.json-simple-1.1.1.jar}:\
|
||||||
|
${file.reference.telegrambots-3.0-jar-with-dependencies.jar}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
@ -53,11 +59,11 @@ javadoc.splitindex=true
|
|||||||
javadoc.use=true
|
javadoc.use=true
|
||||||
javadoc.version=false
|
javadoc.version=false
|
||||||
javadoc.windowtitle=
|
javadoc.windowtitle=
|
||||||
main.class=
|
main.class=com.em.miguelbridge.Launcher
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=false
|
||||||
platform.active=default_platform
|
platform.active=JDK_1.8
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
${build.classes.dir}
|
${build.classes.dir}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
<name>MiguelBridge</name>
|
<name>MiguelBridge</name>
|
||||||
|
<explicit-platform explicit-source-supported="true"/>
|
||||||
<source-roots>
|
<source-roots>
|
||||||
<root id="src.dir"/>
|
<root id="src.dir"/>
|
||||||
</source-roots>
|
</source-roots>
|
||||||
|
29
src/com/em/miguelbridge/Launcher.java
Normal file
29
src/com/em/miguelbridge/Launcher.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.em.miguelbridge;
|
||||||
|
|
||||||
|
import com.em.miguelbridge.telegrambot.TGBot;
|
||||||
|
import org.telegram.telegrambots.ApiContextInitializer;
|
||||||
|
import org.telegram.telegrambots.TelegramBotsApi;
|
||||||
|
import org.telegram.telegrambots.exceptions.TelegramApiException;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author Emanuele Magon
|
||||||
|
*/
|
||||||
|
public class Launcher {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Inizializza il context delle API Telegram (richiesto)
|
||||||
|
ApiContextInitializer.init();
|
||||||
|
|
||||||
|
// Instanzia le API dei bot di Telegram (richiesto)
|
||||||
|
TelegramBotsApi botsApi = new TelegramBotsApi();
|
||||||
|
|
||||||
|
// Avvia il bot di Telegram
|
||||||
|
try {
|
||||||
|
TGBot bot = new TGBot();
|
||||||
|
System.out.println("Caricamento del bot @" + bot.getBotUsername() + " su telegram...");
|
||||||
|
botsApi.registerBot(bot);
|
||||||
|
System.out.println("Bot Telegram avviato! @" + bot.getBotUsername());
|
||||||
|
} catch (TelegramApiException e) {
|
||||||
|
System.err.println("Errore avvio bot: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/com/em/miguelbridge/matrixbot/MatrixBot.java
Normal file
10
src/com/em/miguelbridge/matrixbot/MatrixBot.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.em.miguelbridge.matrixbot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emanuele Magon
|
||||||
|
*/
|
||||||
|
public class MatrixBot {
|
||||||
|
//https://matrix.org/docs/guides/client-server.html
|
||||||
|
|
||||||
|
|
||||||
|
}
|
74
src/com/em/miguelbridge/telegrambot/TGBot.java
Normal file
74
src/com/em/miguelbridge/telegrambot/TGBot.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package com.em.miguelbridge.telegrambot;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.telegram.telegrambots.api.methods.send.*;
|
||||||
|
import org.telegram.telegrambots.api.objects.Update;
|
||||||
|
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author Emanuele Magon
|
||||||
|
*/
|
||||||
|
public class TGBot extends TelegramLongPollingBot {
|
||||||
|
//Costanti con il mio id e il nome del file delle richieste
|
||||||
|
private final String admin_id = "18200812";
|
||||||
|
private final String fileToken = "files/TGbot.token";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdateReceived(Update update) {
|
||||||
|
/*Istruzione usata per prendere i gli ID dei file e documenti
|
||||||
|
try {
|
||||||
|
System.out.println(update.getMessage().getVoice().getFileId());
|
||||||
|
} catch (Exception e) {System.out.println(e);}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Controllo per vedere se l'update è un messaggio testuale e che esso non sia vuoto
|
||||||
|
if (update.hasMessage() && update.getMessage().hasText()) {
|
||||||
|
//Testo e mittente
|
||||||
|
String testoMessaggio = update.getMessage().getText();
|
||||||
|
String chat_id = "" + update.getMessage().getChatId();
|
||||||
|
|
||||||
|
cEcho(chat_id, testoMessaggio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBotUsername() {
|
||||||
|
//Return bot username
|
||||||
|
//If bot username is @MyAmazingBot, it must return 'MyAmazingBot'
|
||||||
|
return "MiguelBridgeBot";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBotToken() {
|
||||||
|
try {
|
||||||
|
//Return bot token from BotFather
|
||||||
|
//Legge il file di testo con il nome passato. Mantiene gli a capo e tabulazioni
|
||||||
|
BufferedReader reader;
|
||||||
|
reader = new BufferedReader(new FileReader (fileToken));
|
||||||
|
return reader.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Errore apertura file token: " + e);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------COMANDI----------
|
||||||
|
public void cEcho(String chat_id, String testoMessaggio){
|
||||||
|
//Crea la stringa da mandare e la rende uguale al messaggio originale
|
||||||
|
SendMessage messaggio;
|
||||||
|
messaggio = new SendMessage()
|
||||||
|
.setChatId(chat_id)
|
||||||
|
.setText(testoMessaggio);
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Invia il messaggio all'utente
|
||||||
|
sendMessage(messaggio);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Errore: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public class MalformedEventException extends MatrixException {
|
|
||||||
|
|
||||||
public MalformedEventException(String s) {
|
|
||||||
super("M_NOT_JSON", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MalformedEventException forId(String id) {
|
|
||||||
return new MalformedEventException("Event " + id + " is malformed");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public class MatrixErrorInfo {
|
|
||||||
|
|
||||||
private String errcode;
|
|
||||||
private String error;
|
|
||||||
|
|
||||||
public MatrixErrorInfo(String errcode) {
|
|
||||||
this.errcode = errcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixErrorInfo(Throwable t) {
|
|
||||||
this.errcode = "AS_INTERNAL_SERVER_ERROR";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrcode() {
|
|
||||||
return errcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getError() {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public class MatrixException extends RuntimeException {
|
|
||||||
|
|
||||||
private String errorCode;
|
|
||||||
private String error;
|
|
||||||
|
|
||||||
public MatrixException(String errorCode, String error) {
|
|
||||||
super(errorCode + ": " + error);
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
this.error = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixException(String errorCode, String error, Throwable t) {
|
|
||||||
super(errorCode + ": " + error, t);
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
this.error = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorCode() {
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getError() {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class MatrixID implements _MatrixID {
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private MatrixID mxId;
|
|
||||||
|
|
||||||
public Builder(String id) {
|
|
||||||
mxId = MatrixID.parse(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixID valid() {
|
|
||||||
if (!mxId.isValid()) {
|
|
||||||
throw new IllegalArgumentException(mxId + " is not a valid Matrix ID");
|
|
||||||
}
|
|
||||||
return mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixID acceptable() {
|
|
||||||
if (!mxId.isAcceptable()) {
|
|
||||||
throw new IllegalArgumentException(mxId + " is not an acceptable Matrix ID");
|
|
||||||
}
|
|
||||||
return mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Pattern LAX_PATTERN = Pattern.compile("@(.*?):(.+)");
|
|
||||||
private static final Pattern STRICT_PATTERN = Pattern.compile("@([0-9a-z-.=_]+):(.+)");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private String localpart;
|
|
||||||
private String domain;
|
|
||||||
|
|
||||||
private static String buildRaw(String localpart, String domain) {
|
|
||||||
return "@" + localpart + ":" + domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MatrixID parse(String id) {
|
|
||||||
Matcher m = LAX_PATTERN.matcher(id);
|
|
||||||
if (!m.matches()) {
|
|
||||||
throw new IllegalArgumentException(id + " is not a Matrix ID");
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixID mxId = new MatrixID();
|
|
||||||
mxId.id = id;
|
|
||||||
mxId.localpart = m.group(1);
|
|
||||||
mxId.domain = m.group(2);
|
|
||||||
return mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder from(String id) {
|
|
||||||
return new Builder(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder from(String local, String domain) {
|
|
||||||
return from(buildRaw(local, domain));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MatrixID asValid(String id) {
|
|
||||||
return new Builder(id).valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MatrixID asAcceptable(String local, String domain) {
|
|
||||||
return from(local, domain).acceptable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MatrixID asAcceptable(String id) {
|
|
||||||
return from(id).acceptable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatrixID() {
|
|
||||||
// not for public consumption
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatrixID(MatrixID mxId) {
|
|
||||||
this.id = mxId.id;
|
|
||||||
this.localpart = mxId.localpart;
|
|
||||||
this.domain = mxId.domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public MatrixID(String mxId) {
|
|
||||||
this(parse(mxId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public MatrixID(String localpart, String domain) {
|
|
||||||
this(parse(buildRaw(localpart, domain)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLocalPart() {
|
|
||||||
return localpart;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MatrixID canonicalize() {
|
|
||||||
return parse(getId().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid() {
|
|
||||||
return isAcceptable() && STRICT_PATTERN.matcher(id).matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAcceptable() {
|
|
||||||
// TODO properly implement
|
|
||||||
|
|
||||||
return id.length() <= 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof MatrixID)) return false;
|
|
||||||
|
|
||||||
MatrixID matrixID = (MatrixID) o;
|
|
||||||
|
|
||||||
return id.equals(matrixID.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return id.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public class ThreePid implements _ThreePid {
|
|
||||||
|
|
||||||
private String medium;
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
public ThreePid(String medium, String address) {
|
|
||||||
this.medium = medium;
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMedium() {
|
|
||||||
return medium;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
ThreePid threePid = (ThreePid) o;
|
|
||||||
|
|
||||||
if (!medium.equals(threePid.medium)) return false;
|
|
||||||
return address.equals(threePid.address);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = medium.hashCode();
|
|
||||||
result = 31 * result + address.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public class ThreePidMapping implements _ThreePidMapping {
|
|
||||||
|
|
||||||
private _ThreePid threePid;
|
|
||||||
private _MatrixID mxId;
|
|
||||||
|
|
||||||
public ThreePidMapping(_ThreePid threePid, _MatrixID mxId) {
|
|
||||||
this.threePid = threePid;
|
|
||||||
this.mxId = mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _ThreePid getThreePid() {
|
|
||||||
return threePid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixID getMatrixId() {
|
|
||||||
return mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
ThreePidMapping that = (ThreePidMapping) o;
|
|
||||||
|
|
||||||
if (!threePid.equals(that.threePid)) return false;
|
|
||||||
return mxId.equals(that.mxId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = threePid.hashCode();
|
|
||||||
result = 31 * result + mxId.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public enum ThreePidMedium {
|
|
||||||
|
|
||||||
Email("email"),
|
|
||||||
PhoneNumber("msisdn");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
ThreePidMedium(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is(String s) {
|
|
||||||
return getId().contentEquals(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _MatrixContent {
|
|
||||||
|
|
||||||
URI getAddress();
|
|
||||||
|
|
||||||
boolean isValid();
|
|
||||||
|
|
||||||
Optional<String> getType();
|
|
||||||
|
|
||||||
byte[] getData();
|
|
||||||
|
|
||||||
Optional<String> getFilename();
|
|
||||||
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public interface _MatrixID {
|
|
||||||
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
String getLocalPart();
|
|
||||||
|
|
||||||
String getDomain();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render this Matrix ID strictly valid. In technical term, transform this ID so
|
|
||||||
* <code>isValid()</code> returns true.
|
|
||||||
*
|
|
||||||
* @return A canonical Matrix ID
|
|
||||||
*/
|
|
||||||
_MatrixID canonicalize();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the Matrix ID is strictly valid in the protocol as per
|
|
||||||
* http://matrix.org/docs/spec/intro.html#user-identifiers
|
|
||||||
*
|
|
||||||
* @return true if strictly valid, false if not
|
|
||||||
*/
|
|
||||||
boolean isValid();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the Matrix ID is acceptable in the protocol as per
|
|
||||||
* http://matrix.org/docs/spec/intro.html#historical-user-ids
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean isAcceptable();
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client._Presence;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _MatrixUser {
|
|
||||||
|
|
||||||
_MatrixID getId();
|
|
||||||
|
|
||||||
Optional<String> getName();
|
|
||||||
|
|
||||||
Optional<_MatrixContent> getAvatar();
|
|
||||||
|
|
||||||
Optional<_Presence> getPresence();
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public interface _ThreePid {
|
|
||||||
|
|
||||||
String getMedium();
|
|
||||||
|
|
||||||
String getAddress();
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
public interface _ThreePidMapping {
|
|
||||||
|
|
||||||
_ThreePid getThreePid();
|
|
||||||
|
|
||||||
_MatrixID getMatrixId();
|
|
||||||
|
|
||||||
}
|
|
@ -1,401 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixErrorInfo;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.hs._MatrixHomeserver;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.client.entity.EntityBuilder;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpRequestBase;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public abstract class AMatrixHttpClient implements _MatrixClientRaw {
|
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(AMatrixHttpClient.class);
|
|
||||||
|
|
||||||
protected MatrixClientContext context = new MatrixClientContext();
|
|
||||||
|
|
||||||
protected Gson gson = new Gson();
|
|
||||||
protected JsonParser jsonParser = new JsonParser();
|
|
||||||
private CloseableHttpClient client = HttpClients.createDefault();
|
|
||||||
|
|
||||||
private Pattern accessTokenUrlPattern = Pattern.compile("\\?access_token=(?<token>[^&]*)");
|
|
||||||
|
|
||||||
public AMatrixHttpClient(String domain) {
|
|
||||||
context.setDomain(domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AMatrixHttpClient(URL hsBaseUrl) {
|
|
||||||
context.setHsBaseUrl(hsBaseUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AMatrixHttpClient(MatrixClientContext context) {
|
|
||||||
this.context = new MatrixClientContext(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<_AutoDiscoverySettings> discoverSettings() {
|
|
||||||
if (StringUtils.isBlank(context.getDomain())) {
|
|
||||||
throw new IllegalStateException("A non-empty Matrix domain must be set to discover the client settings");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String hostname = context.getDomain().split(":")[0];
|
|
||||||
log.info("Performing .well-known auto-discovery for {}", hostname);
|
|
||||||
|
|
||||||
URIBuilder builder = new URIBuilder();
|
|
||||||
builder.setScheme("https");
|
|
||||||
builder.setHost(hostname);
|
|
||||||
builder.setPath("/.well-known/matrix/client");
|
|
||||||
HttpGet req = new HttpGet(builder.build());
|
|
||||||
String body = execute(new MatrixHttpRequest(req).addIgnoredErrorCode(404));
|
|
||||||
if (StringUtils.isBlank(body)) {
|
|
||||||
if (Objects.isNull(context.getHsBaseUrl())) {
|
|
||||||
throw new IllegalStateException("No valid Homeserver base URL was found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// No .well-known data found
|
|
||||||
// FIXME improve SDK so we can differentiate between not found and empty.
|
|
||||||
// not found = skip
|
|
||||||
// empty = failure
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Found body: {}", body);
|
|
||||||
|
|
||||||
WellKnownAutoDiscoverySettings settings = new WellKnownAutoDiscoverySettings(body);
|
|
||||||
log.info("Found .well-known data");
|
|
||||||
|
|
||||||
// TODO reconsider if and where we should check for an already present HS url in the context
|
|
||||||
if (settings.getHsBaseUrls().isEmpty()) {
|
|
||||||
throw new IllegalStateException("No valid Homeserver base URL was found");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (URL baseUrlCandidate : settings.getHsBaseUrls()) {
|
|
||||||
context.setHsBaseUrl(baseUrlCandidate);
|
|
||||||
try {
|
|
||||||
if (!getHomeApiVersions().isEmpty()) {
|
|
||||||
log.info("Found a valid HS at {}", getContext().getHsBaseUrl().toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (MatrixClientRequestException e) {
|
|
||||||
log.warn("Error when trying to fetch {}: {}", baseUrlCandidate, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (URL baseUrlCandidate : settings.getIsBaseUrls()) {
|
|
||||||
context.setIsBaseUrl(baseUrlCandidate);
|
|
||||||
try {
|
|
||||||
if (validateIsBaseUrl()) {
|
|
||||||
log.info("Found a valid IS at {}", getContext().getHsBaseUrl().toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (MatrixClientRequestException e) {
|
|
||||||
log.warn("Error when trying to fetch {}: {}", baseUrlCandidate, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.of(settings);
|
|
||||||
} catch (URISyntaxException e) { // The domain was invalid when used in a URL
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MatrixClientContext getContext() {
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixHomeserver getHomeserver() {
|
|
||||||
return context.getHomeserver();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getAccessToken() {
|
|
||||||
return Optional.ofNullable(context.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessTokenOrThrow() {
|
|
||||||
return getAccessToken()
|
|
||||||
.orElseThrow(() -> new IllegalStateException("This method can only be used with a valid token."));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getHomeApiVersions() {
|
|
||||||
String body = execute(new HttpGet(getPath("client", "", "versions")));
|
|
||||||
return GsonUtil.asList(GsonUtil.parseObj(body), "versions", String.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean validateIsBaseUrl() {
|
|
||||||
String body = execute(new HttpGet(getIdentityPath("identity", "api", "/v1")));
|
|
||||||
return "{}".equals(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<_MatrixID> getUser() {
|
|
||||||
return context.getUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String execute(HttpRequestBase request) {
|
|
||||||
return execute(new MatrixHttpRequest(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String execute(MatrixHttpRequest matrixRequest) {
|
|
||||||
log(matrixRequest.getHttpRequest());
|
|
||||||
try (CloseableHttpResponse response = client.execute(matrixRequest.getHttpRequest())) {
|
|
||||||
|
|
||||||
String body = getBody(response.getEntity());
|
|
||||||
int responseStatus = response.getStatusLine().getStatusCode();
|
|
||||||
|
|
||||||
if (responseStatus == 200) {
|
|
||||||
log.debug("Request successfully executed.");
|
|
||||||
} else if (matrixRequest.getIgnoredErrorCodes().contains(responseStatus)) {
|
|
||||||
log.debug("Error code ignored: " + responseStatus);
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
MatrixErrorInfo info = createErrorInfo(body, responseStatus);
|
|
||||||
|
|
||||||
body = handleError(matrixRequest, responseStatus, info);
|
|
||||||
}
|
|
||||||
return body;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new MatrixClientRequestException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default handling of errors. Can be overwritten by a custom implementation in inherited classes.
|
|
||||||
*
|
|
||||||
* @param matrixRequest
|
|
||||||
* @param responseStatus
|
|
||||||
* @param info
|
|
||||||
* @return body of the response of a repeated call of the request, else this methods throws a
|
|
||||||
* MatrixClientRequestException
|
|
||||||
*/
|
|
||||||
protected String handleError(MatrixHttpRequest matrixRequest, int responseStatus, MatrixErrorInfo info) {
|
|
||||||
String message = String.format("Request failed with status code: %s", responseStatus);
|
|
||||||
|
|
||||||
if (responseStatus == 429) {
|
|
||||||
return handleRateLimited(matrixRequest, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new MatrixClientRequestException(info, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default handling of rate limited calls. Can be overwritten by a custom implementation in inherited classes.
|
|
||||||
*
|
|
||||||
* @param matrixRequest
|
|
||||||
* @param info
|
|
||||||
* @return body of the response of a repeated call of the request, else this methods throws a
|
|
||||||
* MatrixClientRequestException
|
|
||||||
*/
|
|
||||||
protected String handleRateLimited(MatrixHttpRequest matrixRequest, MatrixErrorInfo info) {
|
|
||||||
throw new MatrixClientRequestException(info, "Request was rate limited.");
|
|
||||||
// TODO Add default handling of rate limited call, i.e. repeated call after given time interval.
|
|
||||||
// 1. Wait for timeout
|
|
||||||
// 2. return execute(request)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MatrixHttpContentResult executeContentRequest(MatrixHttpRequest matrixRequest) {
|
|
||||||
log(matrixRequest.getHttpRequest());
|
|
||||||
try (CloseableHttpResponse response = client.execute(matrixRequest.getHttpRequest())) {
|
|
||||||
|
|
||||||
HttpEntity entity = response.getEntity();
|
|
||||||
int responseStatus = response.getStatusLine().getStatusCode();
|
|
||||||
|
|
||||||
MatrixHttpContentResult result = new MatrixHttpContentResult(response);
|
|
||||||
|
|
||||||
if (responseStatus == 200) {
|
|
||||||
log.debug("Request successfully executed.");
|
|
||||||
|
|
||||||
if (entity == null) {
|
|
||||||
log.debug("No data received.");
|
|
||||||
} else if (entity.getContentType() == null) {
|
|
||||||
log.debug("No content type was given.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (matrixRequest.getIgnoredErrorCodes().contains(responseStatus)) {
|
|
||||||
log.debug("Error code ignored: " + responseStatus);
|
|
||||||
} else {
|
|
||||||
String body = getBody(entity);
|
|
||||||
MatrixErrorInfo info = createErrorInfo(body, responseStatus);
|
|
||||||
|
|
||||||
result = handleErrorContentRequest(matrixRequest, responseStatus, info);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new MatrixClientRequestException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MatrixHttpContentResult handleErrorContentRequest(MatrixHttpRequest matrixRequest, int responseStatus,
|
|
||||||
MatrixErrorInfo info) {
|
|
||||||
String message = String.format("Request failed with status code: %s", responseStatus);
|
|
||||||
|
|
||||||
if (responseStatus == 429) {
|
|
||||||
return handleRateLimitedContentRequest(matrixRequest, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new MatrixClientRequestException(info, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MatrixHttpContentResult handleRateLimitedContentRequest(MatrixHttpRequest matrixRequest,
|
|
||||||
MatrixErrorInfo info) {
|
|
||||||
throw new MatrixClientRequestException(info, "Request was rate limited.");
|
|
||||||
// TODO Add default handling of rate limited call, i.e. repeated call after given time interval.
|
|
||||||
// 1. Wait for timeout
|
|
||||||
// 2. return execute(request)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Optional<String> extractAsStringFromBody(String body, String jsonObjectName) {
|
|
||||||
if (StringUtils.isNotEmpty(body)) {
|
|
||||||
return Optional.of(new JsonParser().parse(body).getAsJsonObject().get(jsonObjectName).getAsString());
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getBody(HttpEntity entity) throws IOException {
|
|
||||||
Charset charset = ContentType.getOrDefault(entity).getCharset();
|
|
||||||
return IOUtils.toString(entity.getContent(), charset);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatrixErrorInfo createErrorInfo(String body, int responseStatus) {
|
|
||||||
MatrixErrorInfo info = gson.fromJson(body, MatrixErrorInfo.class);
|
|
||||||
log.debug("Request returned with an error. Status code: {}, errcode: {}, error: {}", responseStatus,
|
|
||||||
info.getErrcode(), info.getError());
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void log(HttpRequestBase req) {
|
|
||||||
String reqUrl = req.getURI().toASCIIString();
|
|
||||||
Matcher m = accessTokenUrlPattern.matcher(reqUrl);
|
|
||||||
if (m.find()) {
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
b.append(reqUrl.substring(0, m.start("token")));
|
|
||||||
b.append("<redacted>");
|
|
||||||
b.append(reqUrl.substring(m.end("token"), reqUrl.length()));
|
|
||||||
reqUrl = b.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Doing {} {}", req.getMethod(), reqUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URIBuilder getPathBuilder(URIBuilder base, String module, String version, String action) {
|
|
||||||
base.setPath(base.getPath() + "/_matrix/" + module + "/" + version + action);
|
|
||||||
if (context.isVirtual()) {
|
|
||||||
context.getUser().ifPresent(user -> base.setParameter("user_id", user.getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URIBuilder getPathBuilder(String module, String version, String action) {
|
|
||||||
return getPathBuilder(context.getHomeserver().getBaseEndpointBuilder(), module, version, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URIBuilder getIdentityPathBuilder(String module, String version, String action) {
|
|
||||||
return getPathBuilder(new URIBuilder(URI.create(context.getIsBaseUrl().toString())), module, version, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getPath(String module, String version, String action) {
|
|
||||||
try {
|
|
||||||
return getPathBuilder(module, version, action).build();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getIdentityPath(String module, String version, String action) {
|
|
||||||
try {
|
|
||||||
return getIdentityPathBuilder(module, version, action).build();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URIBuilder getClientPathBuilder(String action) {
|
|
||||||
return getPathBuilder("client", "r0", action);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URIBuilder getMediaPathBuilder(String action) {
|
|
||||||
return getPathBuilder("media", "v1", action);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getWithAccessToken(URIBuilder builder) {
|
|
||||||
try {
|
|
||||||
builder.setParameter("access_token", getAccessTokenOrThrow());
|
|
||||||
return builder.build();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getClientPathWithAccessToken(String action) {
|
|
||||||
return getWithAccessToken(getClientPathBuilder(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getClientPath(String action) {
|
|
||||||
try {
|
|
||||||
return getClientPathBuilder(action).build();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URI getMediaPath(String action) {
|
|
||||||
return getWithAccessToken(getMediaPathBuilder(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected HttpEntity getJsonEntity(Object o) {
|
|
||||||
return EntityBuilder.create().setText(gson.toJson(o)).setContentType(ContentType.APPLICATION_JSON).build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.hs.MatrixHomeserver;
|
|
||||||
import io.kamax.matrix.hs._MatrixHomeserver;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixClientContext {
|
|
||||||
|
|
||||||
private String domain;
|
|
||||||
private URL hsBaseUrl;
|
|
||||||
private URL isBaseUrl;
|
|
||||||
private _MatrixID user;
|
|
||||||
private String token;
|
|
||||||
private boolean isVirtual;
|
|
||||||
private String deviceId;
|
|
||||||
|
|
||||||
public MatrixClientContext() {
|
|
||||||
// stub
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext(MatrixClientContext other) {
|
|
||||||
this.domain = other.domain;
|
|
||||||
this.hsBaseUrl = other.hsBaseUrl;
|
|
||||||
this.isBaseUrl = other.isBaseUrl;
|
|
||||||
this.user = other.user;
|
|
||||||
this.token = other.token;
|
|
||||||
this.isVirtual = other.isVirtual;
|
|
||||||
this.deviceId = other.deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext(_MatrixHomeserver hs) {
|
|
||||||
setDomain(hs.getDomain());
|
|
||||||
setHsBaseUrl(hs.getBaseEndpoint());
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext(_MatrixHomeserver hs, _MatrixID user, String token) {
|
|
||||||
this(hs);
|
|
||||||
setUser(user);
|
|
||||||
setToken(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public _MatrixHomeserver getHomeserver() {
|
|
||||||
if (Objects.isNull(hsBaseUrl)) {
|
|
||||||
throw new IllegalStateException("Homeserver Base URL is not set");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MatrixHomeserver(domain, hsBaseUrl.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDomain() {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setDomain(String domain) {
|
|
||||||
this.domain = domain;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getHsBaseUrl() {
|
|
||||||
return hsBaseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setHsBaseUrl(URL hsBaseUrl) {
|
|
||||||
this.hsBaseUrl = hsBaseUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getIsBaseUrl() {
|
|
||||||
return isBaseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setIsBaseUrl(URL isBaseUrl) {
|
|
||||||
this.isBaseUrl = isBaseUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<_MatrixID> getUser() {
|
|
||||||
return Optional.ofNullable(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setUser(_MatrixID user) {
|
|
||||||
this.user = user;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setUserWithLocalpart(String localpart) {
|
|
||||||
setUser(MatrixID.asAcceptable(localpart, getDomain()));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setToken(String token) {
|
|
||||||
this.token = token;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isVirtual() {
|
|
||||||
return isVirtual;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setVirtual(boolean virtual) {
|
|
||||||
isVirtual = virtual;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientContext setDeviceId(String deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixErrorInfo;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixClientRequestException extends RuntimeException {
|
|
||||||
|
|
||||||
private MatrixErrorInfo errorInfo;
|
|
||||||
|
|
||||||
public MatrixClientRequestException(IOException e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixClientRequestException(MatrixErrorInfo errorInfo, String message) {
|
|
||||||
super(message);
|
|
||||||
|
|
||||||
this.errorInfo = errorInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<MatrixErrorInfo> getError() {
|
|
||||||
return Optional.ofNullable(errorInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixContent;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.http.Header;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class MatrixHttpContent extends AMatrixHttpClient implements _MatrixContent {
|
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(MatrixHttpContent.class);
|
|
||||||
private final Pattern filenamePattern = Pattern.compile("filename=\"?(?<filename>[^\";]+)");
|
|
||||||
private URI address;
|
|
||||||
|
|
||||||
private MatrixHttpContentResult result;
|
|
||||||
|
|
||||||
private boolean loaded = false;
|
|
||||||
private boolean valid = false;
|
|
||||||
|
|
||||||
public MatrixHttpContent(MatrixClientContext context, URI address) {
|
|
||||||
super(context);
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO switch a HTTP HEAD to fetch initial data, instead of loading in memory directly
|
|
||||||
private synchronized void load() {
|
|
||||||
if (loaded) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!StringUtils.equalsIgnoreCase("mxc", address.getScheme())) {
|
|
||||||
log.debug("{} is not a supported protocol for avatars, ignoring", address.getScheme());
|
|
||||||
} else {
|
|
||||||
URI path = getMediaPath("/download/" + address.getHost() + address.getPath());
|
|
||||||
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
result = executeContentRequest(request);
|
|
||||||
valid = result.isValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (MatrixClientRequestException e) {
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URI getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid() {
|
|
||||||
load();
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getType() {
|
|
||||||
load();
|
|
||||||
|
|
||||||
if (!isValid()) {
|
|
||||||
throw new IllegalStateException("This method should only be called, if valid is true.");
|
|
||||||
}
|
|
||||||
return result.getContentType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getData() {
|
|
||||||
load();
|
|
||||||
|
|
||||||
if (!isValid()) {
|
|
||||||
throw new IllegalStateException("This method should only be called, if valid is true.");
|
|
||||||
}
|
|
||||||
return result.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getFilename() {
|
|
||||||
load();
|
|
||||||
|
|
||||||
if (!isValid()) {
|
|
||||||
throw new IllegalStateException("This method should only be called, if valid is true.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Header> contentDisposition = result.getHeader("Content-Disposition");
|
|
||||||
if (contentDisposition.isPresent()) {
|
|
||||||
Matcher m = filenamePattern.matcher(contentDisposition.get().getValue());
|
|
||||||
if (m.find()) {
|
|
||||||
return Optional.of(m.group("filename"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import org.apache.http.Header;
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MatrixHttpContentResult {
|
|
||||||
private final boolean valid;
|
|
||||||
private final List<Header> headers;
|
|
||||||
private final Optional<String> contentType;
|
|
||||||
private final byte[] data;
|
|
||||||
|
|
||||||
public MatrixHttpContentResult(CloseableHttpResponse response) throws IOException {
|
|
||||||
HttpEntity entity = response.getEntity();
|
|
||||||
valid = entity != null && response.getStatusLine().getStatusCode() == 200;
|
|
||||||
|
|
||||||
if (entity != null) {
|
|
||||||
headers = Arrays.asList(response.getAllHeaders());
|
|
||||||
Header contentTypeHeader = entity.getContentType();
|
|
||||||
if (contentTypeHeader != null) {
|
|
||||||
contentType = Optional.of(contentTypeHeader.getValue());
|
|
||||||
} else {
|
|
||||||
contentType = Optional.empty();
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
||||||
entity.writeTo(outStream);
|
|
||||||
data = outStream.toByteArray();
|
|
||||||
} else {
|
|
||||||
headers = new ArrayList<>();
|
|
||||||
contentType = Optional.empty();
|
|
||||||
data = new byte[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValid() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Header> getHeader(String name) {
|
|
||||||
for (Header header : headers) {
|
|
||||||
if (Objects.equals(header.getName(), name)) {
|
|
||||||
return Optional.of(header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getContentType() {
|
|
||||||
return contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpRequestBase;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MatrixHttpRequest {
|
|
||||||
private final HttpRequestBase httpRequest;
|
|
||||||
private List<Integer> ignoredErrorCodes = new ArrayList<>();
|
|
||||||
|
|
||||||
public MatrixHttpRequest(HttpRequestBase request) {
|
|
||||||
this.httpRequest = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixHttpRequest addIgnoredErrorCode(int errcode) {
|
|
||||||
ignoredErrorCodes.add(errcode);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpRequestBase getHttpRequest() {
|
|
||||||
return httpRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getIgnoredErrorCodes() {
|
|
||||||
return ignoredErrorCodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,183 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
import io.kamax.matrix.json.RoomMessageChunkResponseJson;
|
|
||||||
import io.kamax.matrix.json.RoomMessageFormattedTextPutBody;
|
|
||||||
import io.kamax.matrix.json.RoomMessageTextPutBody;
|
|
||||||
import io.kamax.matrix.json.event.MatrixJsonEvent;
|
|
||||||
import io.kamax.matrix.room.MatrixRoomMessageChunk;
|
|
||||||
import io.kamax.matrix.room._MatrixRoomMessageChunk;
|
|
||||||
import io.kamax.matrix.room._MatrixRoomMessageChunkOptions;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.client.methods.HttpPut;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class MatrixHttpRoom extends AMatrixHttpClient implements _MatrixRoom {
|
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(MatrixHttpRoom.class);
|
|
||||||
|
|
||||||
private String roomId;
|
|
||||||
|
|
||||||
public MatrixHttpRoom(MatrixClientContext context, String roomId) {
|
|
||||||
super(context);
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URIBuilder getClientPathBuilder(String action) {
|
|
||||||
URIBuilder builder = super.getClientPathBuilder(action);
|
|
||||||
builder.setPath(builder.getPath().replace("{roomId}", roomId));
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAddress() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getName() {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/state/m.room.name");
|
|
||||||
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
request.addIgnoredErrorCode(404);
|
|
||||||
String body = execute(request);
|
|
||||||
return extractAsStringFromBody(body, "name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getTopic() {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/state/m.room.topic");
|
|
||||||
MatrixHttpRequest matrixRequest = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
matrixRequest.addIgnoredErrorCode(404);
|
|
||||||
String body = execute(matrixRequest);
|
|
||||||
return extractAsStringFromBody(body, "topic");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void join() {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/join");
|
|
||||||
execute(new HttpPost(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void leave() {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/leave");
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpPost(path));
|
|
||||||
|
|
||||||
// TODO Find a better way to handle room objects for unknown rooms
|
|
||||||
// Maybe throw exception?
|
|
||||||
// TODO implement method to check room existence - isValid() ?
|
|
||||||
// if (res.getStatusLine().getStatusCode() == 404) {
|
|
||||||
// log.warn("Room {} is not joined, ignoring call", roomId);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
request.addIgnoredErrorCode(404);
|
|
||||||
execute(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendMessage(RoomMessageTextPutBody content) {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/send/m.room.message/" + System.currentTimeMillis());
|
|
||||||
HttpPut httpPut = new HttpPut(path);
|
|
||||||
httpPut.setEntity(getJsonEntity(content));
|
|
||||||
execute(httpPut);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendText(String message) {
|
|
||||||
sendMessage(new RoomMessageTextPutBody(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendFormattedText(String formatted, String rawFallback) {
|
|
||||||
// TODO sanitize input
|
|
||||||
sendMessage(new RoomMessageFormattedTextPutBody(rawFallback, formatted));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendNotice(String message) {
|
|
||||||
sendMessage(new RoomMessageTextPutBody("m.notice", message));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendNotice(String formatted, String plain) {
|
|
||||||
// TODO sanitize input
|
|
||||||
sendMessage(new RoomMessageFormattedTextPutBody("m.notice", plain, formatted));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invite(_MatrixID mxId) {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/invite");
|
|
||||||
HttpPost req = new HttpPost(path);
|
|
||||||
req.setEntity(getJsonEntity(GsonUtil.makeObj("user_id", mxId.getId())));
|
|
||||||
execute(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<_MatrixID> getJoinedUsers() {
|
|
||||||
URI path = getClientPathWithAccessToken("/rooms/{roomId}/joined_members");
|
|
||||||
String body = execute(new HttpGet(path));
|
|
||||||
|
|
||||||
List<_MatrixID> ids = new ArrayList<>();
|
|
||||||
if (StringUtils.isNotEmpty(body)) {
|
|
||||||
JsonObject joinedUsers = jsonParser.parse(body).getAsJsonObject().get("joined").getAsJsonObject();
|
|
||||||
for (Map.Entry<String, JsonElement> entry : joinedUsers.entrySet()) {
|
|
||||||
ids.add(new MatrixID(entry.getKey()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixRoomMessageChunk getMessages(_MatrixRoomMessageChunkOptions options) {
|
|
||||||
URIBuilder builder = getClientPathBuilder("/rooms/{roomId}/messages");
|
|
||||||
builder.setParameter("from", options.getFromToken());
|
|
||||||
builder.setParameter("dir", options.getDirection());
|
|
||||||
options.getToToken().ifPresent(token -> builder.setParameter("to", token));
|
|
||||||
options.getLimit().ifPresent(limit -> builder.setParameter("limit", limit.toString()));
|
|
||||||
|
|
||||||
String bodyRaw = execute(new HttpGet(getWithAccessToken(builder)));
|
|
||||||
RoomMessageChunkResponseJson body = GsonUtil.get().fromJson(bodyRaw, RoomMessageChunkResponseJson.class);
|
|
||||||
return new MatrixRoomMessageChunk(body.getStart(), body.getEnd(),
|
|
||||||
body.getChunk().stream().map(MatrixJsonEvent::new).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixContent;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixUser;
|
|
||||||
import io.kamax.matrix.client.regular.Presence;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixHttpUser extends AMatrixHttpClient implements _MatrixUser {
|
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(MatrixHttpUser.class);
|
|
||||||
|
|
||||||
private _MatrixID mxId;
|
|
||||||
|
|
||||||
public MatrixHttpUser(MatrixClientContext context, _MatrixID mxId) {
|
|
||||||
super(context);
|
|
||||||
|
|
||||||
this.mxId = mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixID getId() {
|
|
||||||
return mxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getName() {
|
|
||||||
URI path = getClientPathWithAccessToken("/profile/" + mxId.getId() + "/displayname");
|
|
||||||
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
request.addIgnoredErrorCode(404);
|
|
||||||
String body = execute(request);
|
|
||||||
return extractAsStringFromBody(body, "displayname");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<_MatrixContent> getAvatar() {
|
|
||||||
URI path = getClientPathWithAccessToken("/profile/" + mxId.getId() + "/avatar_url");
|
|
||||||
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
request.addIgnoredErrorCode(404);
|
|
||||||
String body = execute(request);
|
|
||||||
Optional<String> uri = extractAsStringFromBody(body, "avatar_url");
|
|
||||||
if (uri.isPresent()) {
|
|
||||||
try {
|
|
||||||
return Optional.of(new MatrixHttpContent(getContext(), new URI(uri.get())));
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
log.debug("{} is not a valid URI for avatar, returning empty", uri.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<_Presence> getPresence() {
|
|
||||||
URI path = getClientPathWithAccessToken("/presence/" + mxId.getId() + "/status");
|
|
||||||
MatrixHttpRequest request = new MatrixHttpRequest(new HttpGet(path));
|
|
||||||
request.addIgnoredErrorCode(404);
|
|
||||||
String body = execute(request);
|
|
||||||
if (StringUtils.isBlank(body)) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.of(new Presence(GsonUtil.parseObj(body)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
public class MatrixPasswordLoginCredentials {
|
|
||||||
private final String localPart;
|
|
||||||
private final String password;
|
|
||||||
|
|
||||||
public MatrixPasswordLoginCredentials(String localPart, String password) {
|
|
||||||
this.localPart = localPart;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalPart() {
|
|
||||||
return localPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
public enum PresenceStatus {
|
|
||||||
|
|
||||||
Online("online"),
|
|
||||||
Offline("offline"),
|
|
||||||
Unavailable("unavailable");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
PresenceStatus(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is(String status) {
|
|
||||||
return StringUtils.equals(id, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
import io.kamax.matrix.json.InvalidJsonException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class WellKnownAutoDiscoverySettings implements _AutoDiscoverySettings {
|
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(WellKnownAutoDiscoverySettings.class);
|
|
||||||
|
|
||||||
private JsonObject raw;
|
|
||||||
|
|
||||||
private List<URL> hsBaseUrls = new ArrayList<>();
|
|
||||||
private List<URL> isBaseUrls = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build .well-known auto-discovery settings from a .well-known source.
|
|
||||||
*
|
|
||||||
* @param raw
|
|
||||||
* The raw JSON data
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the data is invalid and couldn't be parsed.
|
|
||||||
*/
|
|
||||||
public WellKnownAutoDiscoverySettings(String raw) {
|
|
||||||
try {
|
|
||||||
setRaw(GsonUtil.parseObj(raw));
|
|
||||||
} catch (JsonParseException | InvalidJsonException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid JSON data for .well-known string");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setRaw(JsonObject raw) {
|
|
||||||
this.raw = raw;
|
|
||||||
process();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<URL> getUrl(String url) {
|
|
||||||
try {
|
|
||||||
return Optional.of(new URL(url));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
log.warn("Ignoring invalid Base URL entry in well-known: {} - {}", url, e.getMessage());
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<URL> getUrls(JsonArray array) {
|
|
||||||
List<URL> urls = new ArrayList<>();
|
|
||||||
|
|
||||||
array.forEach(el -> {
|
|
||||||
if (!el.isJsonPrimitive()) {
|
|
||||||
log.warn("Ignoring invalid Base URL entry in well-known: {} - Not a string", GsonUtil.get().toJson(el));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
getUrl(el.getAsString()).ifPresent(urls::add);
|
|
||||||
});
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<URL> processUrls(JsonObject base, String key) {
|
|
||||||
List<URL> urls = new ArrayList<>();
|
|
||||||
|
|
||||||
GsonUtil.findObj(base, key).ifPresent(cfg -> {
|
|
||||||
log.info("Found data");
|
|
||||||
|
|
||||||
GsonUtil.findArray(cfg, "base_urls").ifPresent(arr -> {
|
|
||||||
log.info("Found base URL(s)");
|
|
||||||
urls.addAll(getUrls(arr));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (urls.isEmpty()) {
|
|
||||||
GsonUtil.findString(cfg, "base_url").flatMap(this::getUrl).ifPresent(urls::add);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void process() {
|
|
||||||
log.info("Processing Homeserver Base URLs");
|
|
||||||
hsBaseUrls = processUrls(raw, "m.homeserver");
|
|
||||||
log.info("Found {} valid URL(s)", hsBaseUrls.size());
|
|
||||||
|
|
||||||
log.info("Processing Identity server Base URLs");
|
|
||||||
isBaseUrls = processUrls(raw, "m.identity_server");
|
|
||||||
log.info("Found {} valid URL(s)", isBaseUrls.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonObject getRaw() {
|
|
||||||
return raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<URL> getHsBaseUrls() {
|
|
||||||
return Collections.unmodifiableList(hsBaseUrls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<URL> getIsBaseUrls() {
|
|
||||||
return Collections.unmodifiableList(isBaseUrls);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface _AutoDiscoverySettings {
|
|
||||||
|
|
||||||
JsonObject getRaw();
|
|
||||||
|
|
||||||
List<URL> getHsBaseUrls();
|
|
||||||
|
|
||||||
List<URL> getIsBaseUrls();
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixUser;
|
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
|
||||||
import io.kamax.matrix.room.RoomAlias;
|
|
||||||
import io.kamax.matrix.room._RoomAliasLookup;
|
|
||||||
import io.kamax.matrix.room._RoomCreationOptions;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _MatrixClient extends _MatrixClientRaw {
|
|
||||||
|
|
||||||
void setDisplayName(String name);
|
|
||||||
|
|
||||||
_RoomAliasLookup lookup(RoomAlias alias);
|
|
||||||
|
|
||||||
_MatrixRoom createRoom(_RoomCreationOptions options);
|
|
||||||
|
|
||||||
_MatrixRoom getRoom(String roomId);
|
|
||||||
|
|
||||||
_MatrixRoom joinRoom(String roomIdOrAlias);
|
|
||||||
|
|
||||||
_MatrixUser getUser(_MatrixID mxId);
|
|
||||||
|
|
||||||
Optional<String> getDeviceId();
|
|
||||||
|
|
||||||
void login(MatrixPasswordLoginCredentials credentials);
|
|
||||||
|
|
||||||
void logout();
|
|
||||||
|
|
||||||
_SyncData sync(_SyncOptions options);
|
|
||||||
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.hs._MatrixHomeserver;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _MatrixClientRaw {
|
|
||||||
|
|
||||||
MatrixClientContext getContext();
|
|
||||||
|
|
||||||
_MatrixHomeserver getHomeserver();
|
|
||||||
|
|
||||||
Optional<String> getAccessToken();
|
|
||||||
|
|
||||||
Optional<_MatrixID> getUser();
|
|
||||||
|
|
||||||
Optional<_AutoDiscoverySettings> discoverSettings();
|
|
||||||
|
|
||||||
// FIXME
|
|
||||||
// we should maybe have a dedicated object for HS related items and be merged into getHomeserver() which is only
|
|
||||||
// holding state at this point and is not functional
|
|
||||||
List<String> getHomeApiVersions();
|
|
||||||
|
|
||||||
// FIXME
|
|
||||||
// we should maybe have a dedicated object for IS related items. Will reconsider when implementing
|
|
||||||
// other part of the IS API
|
|
||||||
boolean validateIsBaseUrl();
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public interface _Presence {
|
|
||||||
|
|
||||||
String getStatus();
|
|
||||||
|
|
||||||
Instant getLastActive();
|
|
||||||
|
|
||||||
}
|
|
@ -1,185 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
import io.kamax.matrix.event._MatrixStateEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Representation of the data when performing a sync call on the Matrix Client API.
|
|
||||||
*/
|
|
||||||
public interface _SyncData {
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The state of the room.
|
|
||||||
*
|
|
||||||
* @return a list of state events.
|
|
||||||
*/
|
|
||||||
List<_MatrixStateEvent> getEvents();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Timeline {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Events that happened in the sync window.
|
|
||||||
*
|
|
||||||
* @return List of events.
|
|
||||||
*/
|
|
||||||
List<_MatrixEvent> getEvents();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the number of events returned was limited by the sync filter.
|
|
||||||
*
|
|
||||||
* @return true if the number of events was limited, false if not.
|
|
||||||
*/
|
|
||||||
boolean isLimited();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Token that can be supplied to fetch previous events for the associated room.
|
|
||||||
*
|
|
||||||
* @return the token.
|
|
||||||
*/
|
|
||||||
String getPreviousBatchToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface InvitedRoom {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the room the user was invited to.
|
|
||||||
*
|
|
||||||
* @return the room ID.
|
|
||||||
*/
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The state of the room at the invite event.
|
|
||||||
*
|
|
||||||
* @return a list of state events.
|
|
||||||
*/
|
|
||||||
State getState();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JoinedRoom {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the room the user is joined to.
|
|
||||||
*
|
|
||||||
* @return the room id.
|
|
||||||
*/
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State changes prior the start of the timeline.
|
|
||||||
*
|
|
||||||
* @return a list of state events.
|
|
||||||
*/
|
|
||||||
State getState();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The room timeline for this sync batch.
|
|
||||||
*
|
|
||||||
* @return the timeline.
|
|
||||||
*/
|
|
||||||
Timeline getTimeline();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LeftRoom {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the room the user is joined to.
|
|
||||||
*
|
|
||||||
* @return the room id.
|
|
||||||
*/
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State changes prior the start of the timeline.
|
|
||||||
*
|
|
||||||
* @return a list of state events.
|
|
||||||
*/
|
|
||||||
State getState();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The room timeline up to the leave event.
|
|
||||||
*
|
|
||||||
* @return the timeline.
|
|
||||||
*/
|
|
||||||
Timeline getTimeline();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Rooms {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms the user was invited to within this sync window.
|
|
||||||
*
|
|
||||||
* @return Set of InvitedRoom objects.
|
|
||||||
*/
|
|
||||||
Set<InvitedRoom> getInvited();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms the user was joined in within this sync window.
|
|
||||||
*
|
|
||||||
* @return Set of JoinedRoom objects.
|
|
||||||
*/
|
|
||||||
Set<JoinedRoom> getJoined();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms the user left from within this sync window.
|
|
||||||
*
|
|
||||||
* @return Set of LeftRoom objects.
|
|
||||||
*/
|
|
||||||
Set<LeftRoom> getLeft();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The batch token to supply in the next sync call.
|
|
||||||
*
|
|
||||||
* @return the batch token.
|
|
||||||
*/
|
|
||||||
String nextBatchToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update to the rooms.
|
|
||||||
*
|
|
||||||
* @return rooms object.
|
|
||||||
*/
|
|
||||||
Rooms getRooms();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The raw JSON data for this object.
|
|
||||||
*
|
|
||||||
* @return the JSON data.
|
|
||||||
*/
|
|
||||||
JsonObject getJson();
|
|
||||||
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Possible options that can be passed to the sync call.
|
|
||||||
*/
|
|
||||||
public interface _SyncOptions {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The point of time to continue the sync from.
|
|
||||||
*
|
|
||||||
* @return A token that was provided in a previous sync call, if set.
|
|
||||||
*/
|
|
||||||
Optional<String> getSince();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The filter to use for the sync.
|
|
||||||
*
|
|
||||||
* @return The ID or raw JSON filter, if set.
|
|
||||||
*/
|
|
||||||
Optional<String> getFilter();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the full state should be included in the sync.
|
|
||||||
*
|
|
||||||
* @return The full state option, if set.
|
|
||||||
*/
|
|
||||||
Optional<Boolean> withFullState();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the client should automatically be marked as online.
|
|
||||||
*
|
|
||||||
* @return The set presence option, if set.
|
|
||||||
*/
|
|
||||||
Optional<String> getSetPresence();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum time to wait, in milliseconds, before ending the sync call.
|
|
||||||
*
|
|
||||||
* @return The timeout option, if set.
|
|
||||||
*/
|
|
||||||
Optional<Long> getTimeout();
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.as;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client.MatrixClientContext;
|
|
||||||
import io.kamax.matrix.client._MatrixClient;
|
|
||||||
import io.kamax.matrix.client.regular.MatrixHttpClient;
|
|
||||||
import io.kamax.matrix.json.VirtualUserRegistrationBody;
|
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
public class MatrixApplicationServiceClient extends MatrixHttpClient implements _MatrixApplicationServiceClient {
|
|
||||||
|
|
||||||
private Logger log = LoggerFactory.getLogger(MatrixApplicationServiceClient.class);
|
|
||||||
|
|
||||||
public MatrixApplicationServiceClient(MatrixClientContext context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatrixHttpClient createClient(String localpart) {
|
|
||||||
MatrixClientContext context = new MatrixClientContext(getContext()).setUserWithLocalpart(localpart)
|
|
||||||
.setVirtual(true);
|
|
||||||
return new MatrixHttpClient(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixClient createUser(String localpart) {
|
|
||||||
log.debug("Creating new user {}", localpart);
|
|
||||||
URI path = getClientPathWithAccessToken("/register");
|
|
||||||
HttpPost req = new HttpPost(path);
|
|
||||||
req.setEntity(getJsonEntity(new VirtualUserRegistrationBody(localpart)));
|
|
||||||
execute(req);
|
|
||||||
|
|
||||||
return createClient(localpart);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixClient getUser(String localpart) {
|
|
||||||
return createClient(localpart);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.as;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client._MatrixClient;
|
|
||||||
|
|
||||||
public interface _MatrixApplicationServiceClient extends _MatrixClient {
|
|
||||||
|
|
||||||
_MatrixClient createUser(String localpart);
|
|
||||||
|
|
||||||
_MatrixClient getUser(String localpart);
|
|
||||||
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.regular;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixUser;
|
|
||||||
import io.kamax.matrix.client.*;
|
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
|
||||||
import io.kamax.matrix.json.*;
|
|
||||||
import io.kamax.matrix.room.RoomAlias;
|
|
||||||
import io.kamax.matrix.room.RoomAliasLookup;
|
|
||||||
import io.kamax.matrix.room._RoomAliasLookup;
|
|
||||||
import io.kamax.matrix.room._RoomCreationOptions;
|
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.client.methods.HttpPut;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixHttpClient extends AMatrixHttpClient implements _MatrixClient {
|
|
||||||
|
|
||||||
public MatrixHttpClient(String domain) {
|
|
||||||
super(domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixHttpClient(MatrixClientContext context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected _MatrixID getMatrixId(String localpart) {
|
|
||||||
return new MatrixID(localpart, getHomeserver().getDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URIBuilder getClientPathBuilder(String action) {
|
|
||||||
URIBuilder builder = super.getClientPathBuilder(action);
|
|
||||||
context.getUser().ifPresent(user -> builder.setPath(builder.getPath().replace("{userId}", user.getId())));
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDisplayName(String name) {
|
|
||||||
URI path = getClientPathWithAccessToken("/profile/{userId}/displayname");
|
|
||||||
HttpPut req = new HttpPut(path);
|
|
||||||
req.setEntity(getJsonEntity(new UserDisplaynameSetBody(name)));
|
|
||||||
execute(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _RoomAliasLookup lookup(RoomAlias alias) {
|
|
||||||
URI path = getClientPath("/directory/room/" + alias.getId());
|
|
||||||
HttpGet req = new HttpGet(path);
|
|
||||||
String resBody = execute(req);
|
|
||||||
RoomAliasLookupJson lookup = GsonUtil.get().fromJson(resBody, RoomAliasLookupJson.class);
|
|
||||||
return new RoomAliasLookup(lookup.getRoomId(), alias.getId(), lookup.getServers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixRoom createRoom(_RoomCreationOptions options) {
|
|
||||||
URI path = getClientPathWithAccessToken("/createRoom");
|
|
||||||
HttpPost req = new HttpPost(path);
|
|
||||||
req.setEntity(getJsonEntity(new RoomCreationRequestJson(options)));
|
|
||||||
|
|
||||||
String resBody = execute(req);
|
|
||||||
String roomId = GsonUtil.get().fromJson(resBody, RoomCreationResponseJson.class).getRoomId();
|
|
||||||
return getRoom(roomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixRoom getRoom(String roomId) {
|
|
||||||
return new MatrixHttpRoom(getContext(), roomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixRoom joinRoom(String roomIdOrAlias) {
|
|
||||||
URI path = getClientPathWithAccessToken("/join/ " + roomIdOrAlias);
|
|
||||||
HttpPost req = new HttpPost(path);
|
|
||||||
req.setEntity(getJsonEntity(new JsonObject()));
|
|
||||||
|
|
||||||
String resBody = execute(req);
|
|
||||||
String roomId = GsonUtil.get().fromJson(resBody, RoomCreationResponseJson.class).getRoomId();
|
|
||||||
return getRoom(roomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixUser getUser(_MatrixID mxId) {
|
|
||||||
return new MatrixHttpUser(getContext(), mxId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getDeviceId() {
|
|
||||||
return Optional.ofNullable(context.getDeviceId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void login(MatrixPasswordLoginCredentials credentials) {
|
|
||||||
HttpPost request = new HttpPost(getClientPath("/login"));
|
|
||||||
if (getDeviceId().isPresent()) {
|
|
||||||
request.setEntity(getJsonEntity(
|
|
||||||
new LoginPostBody(credentials.getLocalPart(), credentials.getPassword(), getDeviceId().get())));
|
|
||||||
} else {
|
|
||||||
request.setEntity(getJsonEntity(new LoginPostBody(credentials.getLocalPart(), credentials.getPassword())));
|
|
||||||
}
|
|
||||||
|
|
||||||
String body = execute(request);
|
|
||||||
LoginResponse response = gson.fromJson(body, LoginResponse.class);
|
|
||||||
context.setToken(response.getAccessToken());
|
|
||||||
context.setDeviceId(response.getDeviceId());
|
|
||||||
context.setUser(new MatrixID(response.getUserId()));
|
|
||||||
|
|
||||||
// FIXME spec returns hostname which we might not be the same as what has been used in baseUrl to login. Must
|
|
||||||
// update internals accordingly
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logout() {
|
|
||||||
URI path = getClientPathWithAccessToken("/logout");
|
|
||||||
HttpPost req = new HttpPost(path);
|
|
||||||
execute(req);
|
|
||||||
context.setToken(null);
|
|
||||||
context.setUser(null);
|
|
||||||
context.setDeviceId(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _SyncData sync(_SyncOptions options) {
|
|
||||||
URIBuilder path = getClientPathBuilder("/sync");
|
|
||||||
|
|
||||||
path.addParameter("timeout", options.getTimeout().map(Long::intValue).orElse(30000).toString());
|
|
||||||
options.getSince().ifPresent(since -> path.addParameter("since", since));
|
|
||||||
options.getFilter().ifPresent(filter -> path.addParameter("filter", filter));
|
|
||||||
options.withFullState().ifPresent(state -> path.addParameter("full_state", state ? "true" : "false"));
|
|
||||||
options.getSetPresence().ifPresent(presence -> path.addParameter("presence", presence));
|
|
||||||
|
|
||||||
String body = execute(new HttpGet(getWithAccessToken(path)));
|
|
||||||
return new SyncDataJson(GsonUtil.parseObj(body));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.regular;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client._Presence;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public class Presence implements _Presence {
|
|
||||||
|
|
||||||
private String status;
|
|
||||||
private Instant lastActive;
|
|
||||||
|
|
||||||
public Presence(JsonObject json) {
|
|
||||||
this.status = GsonUtil.getStringOrThrow(json, "presence");
|
|
||||||
this.lastActive = Instant.ofEpochMilli(GsonUtil.getLong(json, "last_active_ago"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Instant getLastActive() {
|
|
||||||
return lastActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,264 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.regular;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.client._SyncData;
|
|
||||||
import io.kamax.matrix.event.EventKey;
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
import io.kamax.matrix.event._MatrixStateEvent;
|
|
||||||
import io.kamax.matrix.json.MatrixJsonObject;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class SyncDataJson extends MatrixJsonObject implements _SyncData {
|
|
||||||
|
|
||||||
public class MatrixEventJson extends MatrixJsonObject implements _MatrixEvent {
|
|
||||||
|
|
||||||
public MatrixEventJson(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return findString(EventKey.Id.get()).orElse(""); // FIXME refactor event structure
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
return getString(EventKey.Type.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Instant getTime() {
|
|
||||||
return Instant.ofEpochMilli(getLong(EventKey.Timestamp.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixID getSender() {
|
|
||||||
return MatrixID.from(getString(EventKey.Sender.get())).acceptable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MatrixStateEventJson extends MatrixEventJson implements _MatrixStateEvent {
|
|
||||||
|
|
||||||
public MatrixStateEventJson(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStateKey() {
|
|
||||||
return getString(EventKey.StateKey.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StateJson extends MatrixJsonObject implements _SyncData.State {
|
|
||||||
|
|
||||||
private List<_MatrixStateEvent> events = new ArrayList<>();
|
|
||||||
|
|
||||||
public StateJson(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
findArray("events").ifPresent(array -> array.forEach(el -> {
|
|
||||||
events.add(new MatrixStateEventJson(asObj(el)));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<_MatrixStateEvent> getEvents() {
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TimelineJson extends MatrixJsonObject implements _SyncData.Timeline {
|
|
||||||
|
|
||||||
private List<_MatrixEvent> events = new ArrayList<>();
|
|
||||||
|
|
||||||
public TimelineJson(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
findArray("events").ifPresent(array -> array.forEach(el -> {
|
|
||||||
events.add(new MatrixEventJson(asObj(el)));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<_MatrixEvent> getEvents() {
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLimited() {
|
|
||||||
return findString("limited").map("true"::equals).orElse(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreviousBatchToken() {
|
|
||||||
return getString("prev_batch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InvitedRoomJson extends MatrixJsonObject implements _SyncData.InvitedRoom {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private State state;
|
|
||||||
|
|
||||||
public InvitedRoomJson(String id, JsonObject data) {
|
|
||||||
super(data);
|
|
||||||
this.id = id;
|
|
||||||
this.state = new StateJson(findObj("state").orElseGet(JsonObject::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public State getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class JoinedRoomJson extends MatrixJsonObject implements _SyncData.JoinedRoom {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private State state;
|
|
||||||
private Timeline timeline;
|
|
||||||
|
|
||||||
public JoinedRoomJson(String id, JsonObject data) {
|
|
||||||
super(data);
|
|
||||||
this.id = id;
|
|
||||||
this.state = new StateJson(findObj("state").orElseGet(JsonObject::new));
|
|
||||||
this.timeline = new TimelineJson(findObj("timeline").orElseGet(JsonObject::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public State getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Timeline getTimeline() {
|
|
||||||
return timeline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LeftRoomJson extends MatrixJsonObject implements _SyncData.LeftRoom {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private State state;
|
|
||||||
private Timeline timeline;
|
|
||||||
|
|
||||||
public LeftRoomJson(String id, JsonObject data) {
|
|
||||||
super(data);
|
|
||||||
this.id = id;
|
|
||||||
this.state = new StateJson(findObj("state").orElseGet(JsonObject::new));
|
|
||||||
this.timeline = new TimelineJson(findObj("timeline").orElseGet(JsonObject::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public State getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Timeline getTimeline() {
|
|
||||||
return timeline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RoomsJson extends MatrixJsonObject implements _SyncData.Rooms {
|
|
||||||
|
|
||||||
private Set<InvitedRoom> invited = new HashSet<>();
|
|
||||||
private Set<JoinedRoom> joined = new HashSet<>();
|
|
||||||
private Set<LeftRoom> left = new HashSet<>();
|
|
||||||
|
|
||||||
public RoomsJson(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
findObj("invite").ifPresent(o -> o.entrySet().forEach(entry -> {
|
|
||||||
invited.add(new InvitedRoomJson(entry.getKey(), asObj(entry.getValue())));
|
|
||||||
}));
|
|
||||||
|
|
||||||
findObj("join").ifPresent(o -> o.entrySet().forEach(entry -> {
|
|
||||||
joined.add(new JoinedRoomJson(entry.getKey(), asObj(entry.getValue())));
|
|
||||||
}));
|
|
||||||
|
|
||||||
findObj("leave").ifPresent(o -> o.entrySet().forEach(entry -> {
|
|
||||||
left.add(new LeftRoomJson(entry.getKey(), asObj(entry.getValue())));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<InvitedRoom> getInvited() {
|
|
||||||
return invited;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<JoinedRoom> getJoined() {
|
|
||||||
return joined;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<LeftRoom> getLeft() {
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nextBatch;
|
|
||||||
private RoomsJson rooms;
|
|
||||||
|
|
||||||
public SyncDataJson(JsonObject data) {
|
|
||||||
super(data);
|
|
||||||
nextBatch = getString("next_batch");
|
|
||||||
rooms = new RoomsJson(findObj("rooms").orElseGet(JsonObject::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String nextBatchToken() {
|
|
||||||
return nextBatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Rooms getRooms() {
|
|
||||||
return rooms;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.client.regular;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client._SyncOptions;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class SyncOptions implements _SyncOptions {
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private final SyncOptions obj;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
this.obj = new SyncOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SyncOptions get() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSince(String since) {
|
|
||||||
obj.since = since;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFilter(String filter) {
|
|
||||||
obj.filter = filter;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setWithFullState(boolean withFullState) {
|
|
||||||
obj.fullState = withFullState;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPresence(boolean setPresence) {
|
|
||||||
obj.setPresence = setPresence ? null : "offline";
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setTimeout(long timeout) {
|
|
||||||
obj.timeout = timeout;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder build() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String since;
|
|
||||||
private String filter;
|
|
||||||
private Boolean fullState;
|
|
||||||
private String setPresence;
|
|
||||||
private Long timeout;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getSince() {
|
|
||||||
return Optional.ofNullable(since);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getFilter() {
|
|
||||||
return Optional.ofNullable(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Boolean> withFullState() {
|
|
||||||
return Optional.ofNullable(fullState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getSetPresence() {
|
|
||||||
return Optional.ofNullable(setPresence);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Long> getTimeout() {
|
|
||||||
return Optional.ofNullable(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.codec;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public class MxBase64 {
|
|
||||||
|
|
||||||
public static String encode(byte[] data) {
|
|
||||||
return Base64.getEncoder().withoutPadding().encodeToString(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String encode(String data) {
|
|
||||||
return encode(data.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.codec;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
public class MxSha256 {
|
|
||||||
|
|
||||||
private MessageDigest md;
|
|
||||||
|
|
||||||
public MxSha256() {
|
|
||||||
try {
|
|
||||||
md = MessageDigest.getInstance("SHA-256");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String hash(byte[] data) {
|
|
||||||
return MxBase64.encode(md.digest(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String hash(String data) {
|
|
||||||
return hash(data.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MalformedEventException;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public enum EventKey {
|
|
||||||
|
|
||||||
AuthEvents("auth_events"),
|
|
||||||
Content("content"),
|
|
||||||
Depth("depth"),
|
|
||||||
Hashes("hashes"),
|
|
||||||
Id("event_id"),
|
|
||||||
Origin("origin"),
|
|
||||||
Timestamp("origin_server_ts"),
|
|
||||||
PreviousEvents("prev_events"),
|
|
||||||
PreviousState("prev_state"),
|
|
||||||
RoomId("room_id"),
|
|
||||||
Sender("sender"),
|
|
||||||
Signatures("signatures"),
|
|
||||||
StateKey("state_key"),
|
|
||||||
Type("type"),
|
|
||||||
Membership("membership"),
|
|
||||||
Unsigned("unsigned");
|
|
||||||
|
|
||||||
private String key;
|
|
||||||
|
|
||||||
EventKey(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String get() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject getObj(JsonObject o) {
|
|
||||||
return findObj(o).orElseThrow(() -> new MalformedEventException(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonElement getElement(JsonObject o) {
|
|
||||||
return GsonUtil.findElement(o, key).orElseThrow(() -> new MalformedEventException(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<JsonObject> findObj(JsonObject o) {
|
|
||||||
return GsonUtil.findObj(o, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> findString(JsonObject o) {
|
|
||||||
return GsonUtil.findString(o, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(JsonObject o) {
|
|
||||||
return findString(o).orElseThrow(() -> new MalformedEventException(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStringOrNull(JsonObject o) {
|
|
||||||
return GsonUtil.getStringOrNull(o, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLong(JsonObject o) {
|
|
||||||
return GsonUtil.getLong(o, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public interface _MatrixEvent {
|
|
||||||
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
String getType();
|
|
||||||
|
|
||||||
Instant getTime();
|
|
||||||
|
|
||||||
_MatrixID getSender();
|
|
||||||
|
|
||||||
JsonObject getJson();
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
public interface _MatrixStateEvent extends _MatrixEvent {
|
|
||||||
|
|
||||||
String getStateKey();
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
public interface _RoomEvent extends _MatrixEvent {
|
|
||||||
|
|
||||||
String getRoomId();
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _RoomMembershipEvent extends _RoomEvent {
|
|
||||||
|
|
||||||
String getMembership();
|
|
||||||
|
|
||||||
Optional<String> getAvatarUrl();
|
|
||||||
|
|
||||||
Optional<String> getDisplayName();
|
|
||||||
|
|
||||||
_MatrixID getInvitee();
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.event;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _RoomMessageEvent extends _RoomEvent {
|
|
||||||
|
|
||||||
String getBody();
|
|
||||||
|
|
||||||
String getBodyType();
|
|
||||||
|
|
||||||
Optional<String> getFormat();
|
|
||||||
|
|
||||||
Optional<String> getFormattedBody();
|
|
||||||
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.hs;
|
|
||||||
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class MatrixHomeserver implements _MatrixHomeserver {
|
|
||||||
|
|
||||||
private String domain;
|
|
||||||
private URL base;
|
|
||||||
|
|
||||||
private static URL getURL(String url) {
|
|
||||||
try {
|
|
||||||
return new URL(url);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixHomeserver(String domain, URL baseUrl) {
|
|
||||||
this.domain = domain;
|
|
||||||
this.base = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixHomeserver(String domain, String baseUrl) {
|
|
||||||
this(domain, getURL(baseUrl));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URL getBaseEndpoint() {
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URIBuilder getBaseEndpointBuilder() {
|
|
||||||
return new URIBuilder(URI.create(base.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.hs;
|
|
||||||
|
|
||||||
public enum RoomMembership {
|
|
||||||
|
|
||||||
Invite("invite"),
|
|
||||||
Join("join"),
|
|
||||||
Leave("leave"),
|
|
||||||
Ban("ban"),
|
|
||||||
Knock("knock");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
RoomMembership(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String get() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is(String id) {
|
|
||||||
return this.id.contentEquals(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.hs;
|
|
||||||
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public interface _MatrixHomeserver {
|
|
||||||
|
|
||||||
String getDomain();
|
|
||||||
|
|
||||||
URL getBaseEndpoint();
|
|
||||||
|
|
||||||
URIBuilder getBaseEndpointBuilder();
|
|
||||||
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.hs;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.room._MatrixRoomMessageChunk;
|
|
||||||
import io.kamax.matrix.room._MatrixRoomMessageChunkOptions;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _MatrixRoom {
|
|
||||||
|
|
||||||
_MatrixHomeserver getHomeserver();
|
|
||||||
|
|
||||||
String getAddress();
|
|
||||||
|
|
||||||
Optional<String> getName();
|
|
||||||
|
|
||||||
Optional<String> getTopic();
|
|
||||||
|
|
||||||
void join();
|
|
||||||
|
|
||||||
void leave();
|
|
||||||
|
|
||||||
void sendText(String message);
|
|
||||||
|
|
||||||
void sendFormattedText(String formatted, String rawFallback);
|
|
||||||
|
|
||||||
void sendNotice(String message);
|
|
||||||
|
|
||||||
void sendNotice(String formatted, String plain);
|
|
||||||
|
|
||||||
void invite(_MatrixID mxId);
|
|
||||||
|
|
||||||
List<_MatrixID> getJoinedUsers();
|
|
||||||
|
|
||||||
_MatrixRoomMessageChunk getMessages(_MatrixRoomMessageChunkOptions options);
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.is;
|
|
||||||
|
|
||||||
import io.kamax.matrix._ThreePid;
|
|
||||||
import io.kamax.matrix._ThreePidMapping;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _IdentityServer {
|
|
||||||
|
|
||||||
Optional<_ThreePidMapping> find(_ThreePid threePid);
|
|
||||||
|
|
||||||
List<_ThreePidMapping> find(List<_ThreePid> threePidList);
|
|
||||||
|
|
||||||
}
|
|
@ -1,179 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class GsonUtil {
|
|
||||||
|
|
||||||
private static Gson instance = build();
|
|
||||||
private static Gson instancePretty = buildPretty();
|
|
||||||
|
|
||||||
private static GsonBuilder buildImpl() {
|
|
||||||
return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
|
||||||
.disableHtmlEscaping();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gson buildPretty() {
|
|
||||||
return buildImpl().setPrettyPrinting().create();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gson build() {
|
|
||||||
return buildImpl().create();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonArray asArray(List<JsonElement> elements) {
|
|
||||||
JsonArray a = new JsonArray();
|
|
||||||
elements.forEach(a::add);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonArray asArrayObj(List<? extends Object> elements) {
|
|
||||||
return asArray(elements.stream().map(e -> get().toJsonTree(e)).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonArray asArray(String... elements) {
|
|
||||||
return asArray(Arrays.stream(elements).map(JsonPrimitive::new).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonArray asArray(Collection<String> elements) {
|
|
||||||
JsonArray a = new JsonArray();
|
|
||||||
elements.forEach(a::add);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> List<T> asList(JsonArray a, Class<T> c) {
|
|
||||||
List<T> l = new ArrayList<>();
|
|
||||||
a.forEach(v -> l.add(GsonUtil.get().fromJson(v, c)));
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> List<T> asList(JsonObject obj, String member, Class<T> c) {
|
|
||||||
return asList(getArray(obj, member), c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject makeObj(Object o) {
|
|
||||||
return instance.toJsonTree(o).getAsJsonObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject makeObj(String key, Object value) {
|
|
||||||
return makeObj(key, instance.toJsonTree(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject makeObj(String key, JsonElement el) {
|
|
||||||
JsonObject obj = new JsonObject();
|
|
||||||
obj.add(key, el);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gson get() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gson getPretty() {
|
|
||||||
return instancePretty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrettyForLog(Object o) {
|
|
||||||
return System.lineSeparator() + getPretty().toJson(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonElement parse(String s) {
|
|
||||||
try {
|
|
||||||
return new JsonParser().parse(s);
|
|
||||||
} catch (JsonParseException e) {
|
|
||||||
throw new InvalidJsonException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject parseObj(String s) {
|
|
||||||
try {
|
|
||||||
return parse(s).getAsJsonObject();
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
throw new InvalidJsonException("Not an object");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonArray getArray(JsonObject obj, String member) {
|
|
||||||
return findArray(obj, member).orElseThrow(() -> new InvalidJsonException("Not an array"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject getObj(JsonObject obj, String member) {
|
|
||||||
return findObj(obj, member).orElseThrow(() -> new InvalidJsonException("No object for member " + member));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<String> findString(JsonObject o, String key) {
|
|
||||||
return findPrimitive(o, key).map(JsonPrimitive::getAsString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStringOrNull(JsonObject o, String key) {
|
|
||||||
JsonElement el = o.get(key);
|
|
||||||
if (el != null && el.isJsonPrimitive()) {
|
|
||||||
return el.getAsString();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStringOrThrow(JsonObject obj, String member) {
|
|
||||||
if (!obj.has(member)) {
|
|
||||||
throw new InvalidJsonException(member + " key is missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj.get(member).getAsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<JsonElement> findElement(JsonObject o, String key) {
|
|
||||||
return Optional.ofNullable(o.get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<JsonPrimitive> findPrimitive(JsonObject o, String key) {
|
|
||||||
return findElement(o, key).map(el -> el.isJsonPrimitive() ? el.getAsJsonPrimitive() : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonPrimitive getPrimitive(JsonObject o, String key) {
|
|
||||||
return findPrimitive(o, key).orElseThrow(() -> new InvalidJsonException("No primitive value for key " + key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<Long> findLong(JsonObject o, String key) {
|
|
||||||
return findPrimitive(o, key).map(JsonPrimitive::getAsLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getLong(JsonObject o, String key) {
|
|
||||||
return findLong(o, key).orElseThrow(() -> new InvalidJsonException("No numeric value for key " + key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<JsonObject> findObj(JsonObject o, String key) {
|
|
||||||
if (!o.has(key)) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.ofNullable(o.getAsJsonObject(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<JsonArray> findArray(JsonObject o, String key) {
|
|
||||||
return findElement(o, key).filter(JsonElement::isJsonArray).map(JsonElement::getAsJsonArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixException;
|
|
||||||
|
|
||||||
public class InvalidJsonException extends MatrixException {
|
|
||||||
|
|
||||||
public InvalidJsonException(Throwable t) {
|
|
||||||
super("M_BAD_JSON", t.getMessage(), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvalidJsonException(String error) {
|
|
||||||
super("M_BAD_JSON", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class JsonCanonicalException extends RuntimeException {
|
|
||||||
|
|
||||||
public JsonCanonicalException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonCanonicalException(Throwable t) {
|
|
||||||
super(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class LoginPostBody {
|
|
||||||
private String type = "m.login.password";
|
|
||||||
private String user;
|
|
||||||
private String password;
|
|
||||||
private String device_id;
|
|
||||||
|
|
||||||
public LoginPostBody(String user, String password) {
|
|
||||||
this.user = user;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginPostBody(String user, String password, String device_id) {
|
|
||||||
this(user, password);
|
|
||||||
this.device_id = device_id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class LoginResponse {
|
|
||||||
|
|
||||||
private String access_token;
|
|
||||||
private String home_server;
|
|
||||||
private String user_id;
|
|
||||||
private String device_id;
|
|
||||||
|
|
||||||
public String getAccessToken() {
|
|
||||||
return access_token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHomeServer() {
|
|
||||||
return home_server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return user_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceId() {
|
|
||||||
return device_id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MatrixJson {
|
|
||||||
|
|
||||||
// Needed to avoid silly try/catch block in lambdas
|
|
||||||
// We only use ByteArray streams, so IOException will not happen (unless irrecoverable situation like OOM)
|
|
||||||
private static class JsonWriterUnchecked extends JsonWriter {
|
|
||||||
|
|
||||||
public JsonWriterUnchecked(Writer out) {
|
|
||||||
super(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonWriter name(String value) {
|
|
||||||
try {
|
|
||||||
return super.name(value);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JsonCanonicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JsonParser parser = new JsonParser();
|
|
||||||
|
|
||||||
private static void encodeCanonical(JsonObject el, JsonWriterUnchecked writer) throws IOException {
|
|
||||||
writer.beginObject();
|
|
||||||
el.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).forEachOrdered(entry -> {
|
|
||||||
writer.name(entry.getKey());
|
|
||||||
encodeCanonicalElement(entry.getValue(), writer);
|
|
||||||
});
|
|
||||||
writer.endObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void encodeCanonicalArray(JsonArray array, JsonWriterUnchecked writer) throws IOException {
|
|
||||||
writer.beginArray();
|
|
||||||
array.forEach(el -> encodeCanonicalElement(el, writer));
|
|
||||||
writer.endArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void encodeCanonicalElement(JsonElement el, JsonWriterUnchecked writer) {
|
|
||||||
try {
|
|
||||||
if (el.isJsonObject()) encodeCanonical(el.getAsJsonObject(), writer);
|
|
||||||
else if (el.isJsonPrimitive()) writer.jsonValue(el.toString());
|
|
||||||
else if (el.isJsonArray()) encodeCanonicalArray(el.getAsJsonArray(), writer);
|
|
||||||
else if (el.isJsonNull()) writer.nullValue();
|
|
||||||
else throw new JsonCanonicalException("Unexpected JSON type, this is a bug, report!");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JsonCanonicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String encodeCanonical(JsonObject obj) {
|
|
||||||
try {
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
JsonWriterUnchecked writer = new JsonWriterUnchecked(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
|
||||||
writer.setIndent("");
|
|
||||||
writer.setHtmlSafe(false);
|
|
||||||
writer.setLenient(false);
|
|
||||||
|
|
||||||
encodeCanonical(obj, writer);
|
|
||||||
writer.close();
|
|
||||||
return out.toString(StandardCharsets.UTF_8.name());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JsonCanonicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String encodeCanonical(String data) {
|
|
||||||
JsonElement el = parser.parse(data);
|
|
||||||
if (!el.isJsonObject()) {
|
|
||||||
/*
|
|
||||||
* TODO seems implied because of how signing/checking signatures is done and because of
|
|
||||||
* https://matrix.to/#/!XqBunHwQIXUiqCaoxq:matrix.org/$15075894901530229RWcIi:matrix.org
|
|
||||||
* with the "whole object".
|
|
||||||
*/
|
|
||||||
throw new JsonCanonicalException("Not a JSON object, cannot encode canonical");
|
|
||||||
}
|
|
||||||
return encodeCanonical(el.getAsJsonObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
import io.kamax.matrix.json.event.MatrixJsonEvent;
|
|
||||||
import io.kamax.matrix.json.event.MatrixJsonRoomMembershipEvent;
|
|
||||||
import io.kamax.matrix.json.event.MatrixJsonRoomMessageEvent;
|
|
||||||
|
|
||||||
public class MatrixJsonEventFactory {
|
|
||||||
|
|
||||||
public static _MatrixEvent get(JsonObject obj) {
|
|
||||||
String type = obj.get("type").getAsString();
|
|
||||||
|
|
||||||
if ("m.room.member".contentEquals(type)) {
|
|
||||||
return new MatrixJsonRoomMembershipEvent(obj);
|
|
||||||
} else if ("m.room.message".contentEquals(type)) {
|
|
||||||
return new MatrixJsonRoomMessageEvent(obj);
|
|
||||||
} else {
|
|
||||||
return new MatrixJsonEvent(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixJsonObject {
|
|
||||||
|
|
||||||
private JsonObject obj;
|
|
||||||
|
|
||||||
public MatrixJsonObject(JsonObject obj) {
|
|
||||||
this.obj = obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Optional<String> findString(String field) {
|
|
||||||
return GsonUtil.findString(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getString(String field) {
|
|
||||||
return GsonUtil.getStringOrNull(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getStringOrNull(JsonObject obj, String field) {
|
|
||||||
return GsonUtil.findString(obj, field).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getStringOrNull(String field) {
|
|
||||||
return getStringOrNull(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getInt(String field) {
|
|
||||||
return GsonUtil.getPrimitive(obj, field).getAsInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getInt(String field, int failover) {
|
|
||||||
return GsonUtil.findPrimitive(obj, field).map(JsonPrimitive::getAsInt).orElse(failover);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long getLong(String field) {
|
|
||||||
return GsonUtil.getLong(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JsonObject asObj(JsonElement el) {
|
|
||||||
if (!el.isJsonObject()) {
|
|
||||||
throw new IllegalArgumentException("Not a JSON object");
|
|
||||||
}
|
|
||||||
|
|
||||||
return el.getAsJsonObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JsonObject getObj(String field) {
|
|
||||||
return GsonUtil.getObj(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Optional<JsonObject> findObj(String field) {
|
|
||||||
return GsonUtil.findObj(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Optional<JsonArray> findArray(String field) {
|
|
||||||
return GsonUtil.findArray(obj, field);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject getJson() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RoomAliasLookupJson {
|
|
||||||
|
|
||||||
private String roomId;
|
|
||||||
private List<String> servers;
|
|
||||||
|
|
||||||
public String getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoomId(String roomId) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getServers() {
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServers(List<String> servers) {
|
|
||||||
this.servers = servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.room._RoomCreationOptions;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class RoomCreationRequestJson {
|
|
||||||
|
|
||||||
private String visibility;
|
|
||||||
private String roomAliasName;
|
|
||||||
private String name;
|
|
||||||
private String topic;
|
|
||||||
private Set<String> invite;
|
|
||||||
private Map<String, JsonElement> creationContent;
|
|
||||||
private String preset;
|
|
||||||
private Boolean isDirect;
|
|
||||||
private Boolean guestCanJoin;
|
|
||||||
|
|
||||||
public RoomCreationRequestJson(_RoomCreationOptions options) {
|
|
||||||
this.visibility = options.getVisibility().orElse(null);
|
|
||||||
this.roomAliasName = options.getAliasName().orElse(null);
|
|
||||||
this.name = options.getName().orElse(null);
|
|
||||||
this.topic = options.getTopic().orElse(null);
|
|
||||||
this.invite = options.getInvites().filter(ids -> !ids.isEmpty())
|
|
||||||
.map(ids -> ids.stream().map(_MatrixID::getId).collect(Collectors.toSet())).orElse(null);
|
|
||||||
this.creationContent = options.getCreationContent().filter(c -> !c.isEmpty()).orElse(null);
|
|
||||||
this.preset = options.getPreset().orElse(null);
|
|
||||||
this.isDirect = options.isDirect().orElse(null);
|
|
||||||
this.guestCanJoin = options.isGuestCanJoin().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class RoomCreationResponseJson {
|
|
||||||
|
|
||||||
private String roomId;
|
|
||||||
|
|
||||||
public String getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RoomMessageChunkResponseJson {
|
|
||||||
|
|
||||||
private String start;
|
|
||||||
private String end;
|
|
||||||
private List<JsonObject> chunk;
|
|
||||||
|
|
||||||
public String getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JsonObject> getChunk() {
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class RoomMessageFormattedTextPutBody extends RoomMessageTextPutBody {
|
|
||||||
|
|
||||||
private String formatted_body;
|
|
||||||
private String format = "org.matrix.custom.html";
|
|
||||||
|
|
||||||
public RoomMessageFormattedTextPutBody(String body, String formattedBody) {
|
|
||||||
super(body);
|
|
||||||
|
|
||||||
this.formatted_body = formattedBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoomMessageFormattedTextPutBody(String msgtype, String body, String formattedBody) {
|
|
||||||
super(msgtype, body);
|
|
||||||
|
|
||||||
this.formatted_body = formattedBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormatted_body() {
|
|
||||||
return formatted_body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormat() {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class RoomMessageTextPutBody {
|
|
||||||
|
|
||||||
private String msgtype = "m.text";
|
|
||||||
private String body;
|
|
||||||
|
|
||||||
public RoomMessageTextPutBody(String body) {
|
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoomMessageTextPutBody(String msgType, String body) {
|
|
||||||
this(body);
|
|
||||||
this.msgtype = msgType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsgtype() {
|
|
||||||
return msgtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class UserDisplaynameSetBody {
|
|
||||||
|
|
||||||
private String displayname;
|
|
||||||
|
|
||||||
public UserDisplaynameSetBody(String displayname) {
|
|
||||||
this.displayname = displayname;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json;
|
|
||||||
|
|
||||||
public class VirtualUserRegistrationBody {
|
|
||||||
|
|
||||||
private String type = "m.login.application_server";
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
public VirtualUserRegistrationBody(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
import io.kamax.matrix.json.MatrixJsonObject;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public class MatrixJsonEvent extends MatrixJsonObject implements _MatrixEvent {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String type;
|
|
||||||
private Instant time;
|
|
||||||
private int age;
|
|
||||||
private _MatrixID sender;
|
|
||||||
|
|
||||||
public MatrixJsonEvent(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
id = getString("event_id");
|
|
||||||
type = getString("type");
|
|
||||||
time = Instant.ofEpochMilli(obj.get("origin_server_ts").getAsLong());
|
|
||||||
age = getInt("age", -1);
|
|
||||||
sender = MatrixID.asAcceptable(getString("sender"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Instant getTime() {
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixID getSender() {
|
|
||||||
return sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._RoomEvent;
|
|
||||||
|
|
||||||
public class MatrixJsonRoomEvent extends MatrixJsonEvent implements _RoomEvent {
|
|
||||||
|
|
||||||
private String roomId;
|
|
||||||
|
|
||||||
public MatrixJsonRoomEvent(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
roomId = getString("room_id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRoomId() {
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.MatrixID;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
import io.kamax.matrix.event._RoomMembershipEvent;
|
|
||||||
import io.kamax.matrix.json.MatrixJsonObject;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixJsonRoomMembershipEvent extends MatrixJsonRoomEvent implements _RoomMembershipEvent {
|
|
||||||
|
|
||||||
private Content content;
|
|
||||||
private _MatrixID invitee;
|
|
||||||
|
|
||||||
public MatrixJsonRoomMembershipEvent(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
content = new Content(getObj("content"));
|
|
||||||
invitee = new MatrixID(getString("state_key"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMembership() {
|
|
||||||
return content.getMembership();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getAvatarUrl() {
|
|
||||||
return Optional.ofNullable(content.getAvatar());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getDisplayName() {
|
|
||||||
return Optional.ofNullable(content.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public _MatrixID getInvitee() {
|
|
||||||
return invitee;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Content extends MatrixJsonObject {
|
|
||||||
|
|
||||||
private String membership;
|
|
||||||
private String avatar;
|
|
||||||
private String displayName;
|
|
||||||
|
|
||||||
Content(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
setMembership(getString("membership"));
|
|
||||||
setAvatar(avatar = getStringOrNull("avatar_url"));
|
|
||||||
setDisplayName(displayName = getStringOrNull("displayname"));
|
|
||||||
}
|
|
||||||
|
|
||||||
String getMembership() {
|
|
||||||
return membership;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMembership(String membership) {
|
|
||||||
this.membership = membership;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getAvatar() {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAvatar(String avatar) {
|
|
||||||
this.avatar = avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDisplayName(String displayName) {
|
|
||||||
this.displayName = displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.json.event;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._RoomMessageEvent;
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixJsonRoomMessageEvent extends MatrixJsonRoomEvent implements _RoomMessageEvent {
|
|
||||||
|
|
||||||
private JsonObject content;
|
|
||||||
|
|
||||||
public MatrixJsonRoomMessageEvent(JsonObject obj) {
|
|
||||||
super(obj);
|
|
||||||
|
|
||||||
this.content = obj.getAsJsonObject("content");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBody() {
|
|
||||||
return content.get("body").getAsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBodyType() {
|
|
||||||
return content.has("msgtype") ? content.get("msgtype").getAsString() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getFormat() {
|
|
||||||
return GsonUtil.findString(content, "format");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getFormattedBody() {
|
|
||||||
return GsonUtil.findString(content, "formatted_body");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MatrixRoomMessageChunk implements _MatrixRoomMessageChunk {
|
|
||||||
|
|
||||||
private String startToken;
|
|
||||||
private String endToken;
|
|
||||||
private List<_MatrixEvent> events;
|
|
||||||
|
|
||||||
public MatrixRoomMessageChunk(String startToken, String endToken, List<_MatrixEvent> events) {
|
|
||||||
this.startToken = startToken;
|
|
||||||
this.endToken = endToken;
|
|
||||||
this.events = events;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStartToken() {
|
|
||||||
return startToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEndToken() {
|
|
||||||
return endToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<_MatrixEvent> getEvents() {
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MatrixRoomMessageChunkOptions implements _MatrixRoomMessageChunkOptions {
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private MatrixRoomMessageChunkOptions obj;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
this.obj = new MatrixRoomMessageChunkOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFromToken(String token) {
|
|
||||||
obj.from = token;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setToToken(String token) {
|
|
||||||
obj.to = token;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setDirection(String direction) {
|
|
||||||
obj.dir = direction;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setDirection(_MatrixRoomMessageChunkOptions.Direction direction) {
|
|
||||||
return setDirection(direction.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLimit(long limit) {
|
|
||||||
obj.limit = limit;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatrixRoomMessageChunkOptions get() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder build() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String from;
|
|
||||||
private String to;
|
|
||||||
private String dir;
|
|
||||||
private Long limit;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFromToken() {
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getToToken() {
|
|
||||||
return Optional.ofNullable(to);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDirection() {
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Long> getLimit() {
|
|
||||||
return Optional.ofNullable(limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class RoomAlias {
|
|
||||||
|
|
||||||
private static final String sigill = "#";
|
|
||||||
private static final Pattern idPattern = Pattern.compile(sigill + "(.+?):(.+)");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String localpart;
|
|
||||||
private String domain;
|
|
||||||
|
|
||||||
public static RoomAlias from(String localpart, String domain) {
|
|
||||||
return from(sigill + localpart + ":" + domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RoomAlias from(String id) {
|
|
||||||
if (id.length() > 255) {
|
|
||||||
throw new IllegalArgumentException("Room aliases cannot be longer than 255 characters");
|
|
||||||
}
|
|
||||||
|
|
||||||
Matcher m = idPattern.matcher(id);
|
|
||||||
if (!m.matches()) {
|
|
||||||
throw new IllegalArgumentException(id + " is not a valid Room alias");
|
|
||||||
}
|
|
||||||
|
|
||||||
RoomAlias r = new RoomAlias();
|
|
||||||
r.id = id;
|
|
||||||
r.localpart = m.group(1);
|
|
||||||
r.domain = m.group(2);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean is(String id) {
|
|
||||||
try {
|
|
||||||
from(id);
|
|
||||||
return true;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private RoomAlias() {
|
|
||||||
// cannot instantiate directly
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalpart() {
|
|
||||||
return localpart;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDomain() {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RoomAliasLookup extends RoomAliasMapping implements _RoomAliasLookup {
|
|
||||||
|
|
||||||
private List<String> servers;
|
|
||||||
|
|
||||||
public RoomAliasLookup(String id, String alias, Collection<String> servers) {
|
|
||||||
super(id, alias);
|
|
||||||
this.servers = new ArrayList<>(servers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getServers() {
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
public class RoomAliasMapping implements _RoomAliasMapping {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private String alias;
|
|
||||||
|
|
||||||
public RoomAliasMapping(String id, String alias) {
|
|
||||||
this.id = id;
|
|
||||||
this.alias = alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAlias() {
|
|
||||||
return alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,160 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class RoomCreationOptions implements _RoomCreationOptions {
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private RoomCreationOptions obj;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
this.obj = new RoomCreationOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setVisibility(String visibility) {
|
|
||||||
obj.visibility = visibility;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setVisibility(RoomDirectoryVisibility visibility) {
|
|
||||||
return setVisibility(visibility.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setAliasName(String aliasName) {
|
|
||||||
obj.aliasName = aliasName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setName(String name) {
|
|
||||||
obj.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setTopic(String topic) {
|
|
||||||
obj.topic = topic;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInvites(Set<_MatrixID> invites) {
|
|
||||||
obj.invites = Collections.unmodifiableSet(new HashSet<>(invites));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setCreationContent(Map<String, JsonElement> creationContent) {
|
|
||||||
obj.creationContent = Collections.unmodifiableMap(new HashMap<>(creationContent));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPreset(String preset) {
|
|
||||||
obj.preset = preset;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPreset(RoomCreationPreset preset) {
|
|
||||||
return setPreset(preset.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setDirect(boolean isDirect) {
|
|
||||||
obj.isDirect = isDirect;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setGuestCanJoin(boolean guestCanJoin) {
|
|
||||||
obj.guestCanJoin = guestCanJoin;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoomCreationOptions get() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder build() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RoomCreationOptions none() {
|
|
||||||
return build().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String visibility;
|
|
||||||
private String aliasName;
|
|
||||||
private String name;
|
|
||||||
private String topic;
|
|
||||||
private Set<_MatrixID> invites = new HashSet<>();
|
|
||||||
private Map<String, JsonElement> creationContent = new HashMap<>();
|
|
||||||
private String preset;
|
|
||||||
private Boolean isDirect;
|
|
||||||
private Boolean guestCanJoin;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getVisibility() {
|
|
||||||
return Optional.ofNullable(visibility);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getAliasName() {
|
|
||||||
return Optional.ofNullable(aliasName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getName() {
|
|
||||||
return Optional.ofNullable(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getTopic() {
|
|
||||||
return Optional.ofNullable(topic);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Set<_MatrixID>> getInvites() {
|
|
||||||
return Optional.ofNullable(invites);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Map<String, JsonElement>> getCreationContent() {
|
|
||||||
return Optional.ofNullable(creationContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> getPreset() {
|
|
||||||
return Optional.ofNullable(preset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Boolean> isDirect() {
|
|
||||||
return Optional.ofNullable(isDirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Boolean> isGuestCanJoin() {
|
|
||||||
return Optional.ofNullable(guestCanJoin);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Room creation presets available in the specification.
|
|
||||||
*/
|
|
||||||
public enum RoomCreationPreset {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The following room state will be set:
|
|
||||||
* - join_rules is set to invite.
|
|
||||||
* - history_visibility is set to shared.
|
|
||||||
*/
|
|
||||||
Private("private_chat"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The following room state will be set:
|
|
||||||
* - join_rules is set to invite.
|
|
||||||
* - history_visibility is set to shared.
|
|
||||||
* - All invitees are given the same power level as the room creator.
|
|
||||||
*/
|
|
||||||
TrustedPrivate("trusted_private_chat"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The following room state will be set:
|
|
||||||
* - join_rules is set to public.
|
|
||||||
* - history_visibility is set to shared.
|
|
||||||
*/
|
|
||||||
PublicChat("public_chat");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
RoomCreationPreset(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Matrix value for this setting.
|
|
||||||
*
|
|
||||||
* @return the value.
|
|
||||||
*/
|
|
||||||
public String get() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Room Directory visibility status available in the specification.
|
|
||||||
*/
|
|
||||||
public enum RoomDirectoryVisibility {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The room will not be visible in the directory.
|
|
||||||
*/
|
|
||||||
Private("private"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The room will be visible by anyone, without authentication.
|
|
||||||
*/
|
|
||||||
Public("public");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
RoomDirectoryVisibility(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Matrix value for this setting.
|
|
||||||
*
|
|
||||||
* @return the value.
|
|
||||||
*/
|
|
||||||
public String get() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import io.kamax.matrix.event._MatrixEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Room messages pagination chunk.
|
|
||||||
*/
|
|
||||||
public interface _MatrixRoomMessageChunk {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The token the pagination starts from.
|
|
||||||
*
|
|
||||||
* @return the token.
|
|
||||||
*/
|
|
||||||
String getStartToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The token the pagination ends at.
|
|
||||||
*
|
|
||||||
* @return the token.
|
|
||||||
*/
|
|
||||||
String getEndToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of room events.
|
|
||||||
*
|
|
||||||
* @return the list.
|
|
||||||
*/
|
|
||||||
List<_MatrixEvent> getEvents();
|
|
||||||
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Possible options that can be passed to the room messages chunk call.
|
|
||||||
*/
|
|
||||||
public interface _MatrixRoomMessageChunkOptions {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The direction to return events from.
|
|
||||||
*/
|
|
||||||
enum Direction {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch events backward.
|
|
||||||
*/
|
|
||||||
Backward("b"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch events forward.
|
|
||||||
*/
|
|
||||||
Forward("f");
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
Direction(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the protocol value.
|
|
||||||
*
|
|
||||||
* @return the value.
|
|
||||||
*/
|
|
||||||
public String get() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The token to start returning events from.
|
|
||||||
*
|
|
||||||
* @return the token.
|
|
||||||
*/
|
|
||||||
String getFromToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The token to stop returning events at, if any.
|
|
||||||
*
|
|
||||||
* @return the token.
|
|
||||||
*/
|
|
||||||
Optional<String> getToToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The direction to return events from.
|
|
||||||
*
|
|
||||||
* @return the direction.
|
|
||||||
*/
|
|
||||||
String getDirection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum number of events to return.
|
|
||||||
*
|
|
||||||
* @return the value.
|
|
||||||
*/
|
|
||||||
Optional<Long> getLimit();
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface _RoomAliasLookup extends _RoomAliasMapping {
|
|
||||||
|
|
||||||
List<String> getServers();
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
public interface _RoomAliasMapping {
|
|
||||||
|
|
||||||
String getId();
|
|
||||||
|
|
||||||
String getAlias();
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
package io.kamax.matrix.room;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import io.kamax.matrix._MatrixID;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Possible options that can be passed to the room creation call.
|
|
||||||
*/
|
|
||||||
public interface _RoomCreationOptions {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the room directory visibility.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<String> getVisibility();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the desired room alias local part.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<String> getAliasName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the room name.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<String> getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the room topic.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<String> getTopic();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of user Matrix IDs to invite to the room.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<Set<_MatrixID>> getInvites();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extra keys to be added to the content of the m.room.create event.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<Map<String, JsonElement>> getCreationContent();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the convenience parameter for setting various default state events.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<String> getPreset();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* What the is_direct flag on the m.room.member event for the invites should be set to.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<Boolean> isDirect();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get guest allowance to join the room.
|
|
||||||
*
|
|
||||||
* @return the optional value.
|
|
||||||
*/
|
|
||||||
Optional<Boolean> isGuestCanJoin();
|
|
||||||
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.sign;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class KeyFileStore implements _KeyStore {
|
|
||||||
|
|
||||||
private final Charset charset = StandardCharsets.ISO_8859_1;
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
|
|
||||||
public KeyFileStore(String path) {
|
|
||||||
File file = new File(path);
|
|
||||||
if (!file.exists()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
throw new IllegalArgumentException("Signing key file storage " + path + " is a directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.isFile()) {
|
|
||||||
throw new IllegalArgumentException("Signing key file storage " + path + " is not a regular file");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.canRead()) {
|
|
||||||
throw new IllegalArgumentException("Signing key file storage " + path + " is not readable");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> load() {
|
|
||||||
try {
|
|
||||||
String key = FileUtils.readFileToString(file, charset);
|
|
||||||
return StringUtils.isBlank(key) ? Optional.empty() : Optional.of(key);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void store(String key) {
|
|
||||||
try {
|
|
||||||
FileUtils.writeStringToFile(file, key, charset);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.sign;
|
|
||||||
|
|
||||||
import io.kamax.matrix.codec.MxBase64;
|
|
||||||
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
|
|
||||||
import net.i2p.crypto.eddsa.EdDSAPublicKey;
|
|
||||||
import net.i2p.crypto.eddsa.KeyPairGenerator;
|
|
||||||
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
|
|
||||||
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
|
|
||||||
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;
|
|
||||||
import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;
|
|
||||||
|
|
||||||
public class KeyManager {
|
|
||||||
|
|
||||||
public static KeyManager fromFile(String path) {
|
|
||||||
return new KeyManager(new KeyFileStore(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeyManager fromMemory() {
|
|
||||||
return new KeyManager(new KeyMemoryStore());
|
|
||||||
}
|
|
||||||
|
|
||||||
private EdDSAParameterSpec keySpecs;
|
|
||||||
private List<KeyPair> keys;
|
|
||||||
|
|
||||||
public KeyManager(_KeyStore store) {
|
|
||||||
keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
|
|
||||||
keys = new ArrayList<>();
|
|
||||||
|
|
||||||
String seedBase64 = store.load().orElseGet(() -> {
|
|
||||||
KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
|
|
||||||
String keyEncoded = MxBase64.encode(pair.getPrivate().getEncoded());
|
|
||||||
store.store(keyEncoded);
|
|
||||||
return keyEncoded;
|
|
||||||
});
|
|
||||||
byte[] seed = Base64.getDecoder().decode(seedBase64);
|
|
||||||
EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
|
|
||||||
EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
|
|
||||||
keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentIndex() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyPair getKeys(int index) {
|
|
||||||
return keys.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateKey getPrivateKey(int index) {
|
|
||||||
return getKeys(index).getPrivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EdDSAPublicKey getPublicKey(int index) {
|
|
||||||
return (EdDSAPublicKey) getKeys(index).getPublic();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EdDSAParameterSpec getSpecs() {
|
|
||||||
return keySpecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPublicKeyBase64(int index) {
|
|
||||||
return MxBase64.encode(getPublicKey(index).getAbyte());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.sign;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class KeyMemoryStore implements _KeyStore {
|
|
||||||
|
|
||||||
private String data;
|
|
||||||
|
|
||||||
public KeyMemoryStore() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyMemoryStore(String data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> load() {
|
|
||||||
return Optional.ofNullable(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void store(String key) {
|
|
||||||
data = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.sign;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import io.kamax.matrix.codec.MxBase64;
|
|
||||||
import io.kamax.matrix.json.MatrixJson;
|
|
||||||
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SignatureException;
|
|
||||||
|
|
||||||
|
|
||||||
import net.i2p.crypto.eddsa.EdDSAEngine;
|
|
||||||
|
|
||||||
public class SignatureManager {
|
|
||||||
|
|
||||||
private KeyManager keyMgr;
|
|
||||||
private String domain;
|
|
||||||
|
|
||||||
private EdDSAEngine signEngine;
|
|
||||||
|
|
||||||
public SignatureManager(KeyManager keyMgr, String domain) {
|
|
||||||
this.keyMgr = keyMgr;
|
|
||||||
this.domain = domain;
|
|
||||||
|
|
||||||
try {
|
|
||||||
signEngine = new EdDSAEngine(MessageDigest.getInstance(keyMgr.getSpecs().getHashAlgorithm()));
|
|
||||||
signEngine.initSign(keyMgr.getPrivateKey(keyMgr.getCurrentIndex()));
|
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String sign(JsonObject obj) {
|
|
||||||
return sign(MatrixJson.encodeCanonical(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String sign(String message) {
|
|
||||||
try {
|
|
||||||
byte[] signRaw = signEngine.signOneShot(message.getBytes());
|
|
||||||
return MxBase64.encode(signRaw);
|
|
||||||
} catch (SignatureException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject signMessageGson(String message) {
|
|
||||||
String sign = sign(message);
|
|
||||||
|
|
||||||
JsonObject keySignature = new JsonObject();
|
|
||||||
// FIXME should create a signing key object what would give this ed and index values
|
|
||||||
keySignature.addProperty("ed25519:" + keyMgr.getCurrentIndex(), sign);
|
|
||||||
JsonObject signature = new JsonObject();
|
|
||||||
signature.add(domain, keySignature);
|
|
||||||
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix.sign;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface _KeyStore {
|
|
||||||
|
|
||||||
Optional<String> load();
|
|
||||||
|
|
||||||
void store(String key);
|
|
||||||
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
import io.kamax.matrix.client.MatrixClientContext;
|
|
||||||
import io.kamax.matrix.client.MatrixClientRequestException;
|
|
||||||
import io.kamax.matrix.client.MatrixHttpTest;
|
|
||||||
import io.kamax.matrix.client.MatrixHttpUser;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public abstract class AMatrixHttpUserTest extends MatrixHttpTest {
|
|
||||||
protected String avatarMediaUrl = "mxc://matrix.org/wefh34uihSDRGhw34";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getName() throws URISyntaxException {
|
|
||||||
assertThat(createUserObject().getName(), is(equalTo(Optional.of(username))));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNameNotFound() throws URISyntaxException {
|
|
||||||
assertThat(createUserObject().getName(), is(equalTo(Optional.empty())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNameAccessDenied() throws URISyntaxException {
|
|
||||||
MatrixClientRequestException e = assertThrows(MatrixClientRequestException.class, createUserObject()::getName);
|
|
||||||
checkErrorInfoAccessDenied(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNameRateLimited() throws URISyntaxException {
|
|
||||||
MatrixClientRequestException e = assertThrows(MatrixClientRequestException.class, createUserObject()::getName);
|
|
||||||
checkErrorInfoRateLimited(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvatar() throws URISyntaxException {
|
|
||||||
Optional<_MatrixContent> matrixContent = createUserObject().getAvatar();
|
|
||||||
assertTrue(matrixContent.isPresent());
|
|
||||||
assertThat(matrixContent.get().getAddress(), is(equalTo(new URI(avatarMediaUrl))));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvatarNotFound() throws URISyntaxException {
|
|
||||||
assertThat(createUserObject().getAvatar(), is(equalTo(Optional.empty())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvatarAccessDenied() throws URISyntaxException {
|
|
||||||
MatrixClientRequestException e = assertThrows(MatrixClientRequestException.class,
|
|
||||||
createUserObject()::getAvatar);
|
|
||||||
checkErrorInfoAccessDenied(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvatarRateLimited() throws URISyntaxException {
|
|
||||||
MatrixClientRequestException e = assertThrows(MatrixClientRequestException.class,
|
|
||||||
createUserObject()::getAvatar);
|
|
||||||
checkErrorInfoRateLimited(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatrixHttpUser createUserObject() throws URISyntaxException {
|
|
||||||
MatrixClientContext context = getOrCreateClientContext();
|
|
||||||
return new MatrixHttpUser(context, context.getUser().get());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* matrix-java-sdk - Matrix Client SDK for Java
|
|
||||||
* Copyright (C) 2017 Arne Augenstein
|
|
||||||
*
|
|
||||||
* https://www.kamax.io/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package io.kamax.matrix;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.slf4j.helpers.NOPLoggerFactory;
|
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A small test class, intended to verify that the logging framework has
|
|
||||||
* a suitable logging implementation.
|
|
||||||
*/
|
|
||||||
public class LoggingDependencyTest {
|
|
||||||
@Test
|
|
||||||
public void login() throws URISyntaxException {
|
|
||||||
if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory) {
|
|
||||||
Assert.fail("No logging implementation found, using fallback NOP logger");
|
|
||||||
}
|
|
||||||
Logger logger = LoggerFactory.getLogger("");
|
|
||||||
logger.info("If you see this info in the logger, everything is alright");
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user