Merge the matrix-java-sdk due to it no longer maintained. Remove thirdparty repositories.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._DirectEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.matrix.json.InvalidJsonException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MatrixJsonDirectEvent extends MatrixJsonEphemeralEvent implements _DirectEvent {
|
||||
|
||||
private Map<_MatrixID, List<String>> mappings = new HashMap<>();
|
||||
|
||||
public MatrixJsonDirectEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
if (!StringUtils.equals(Type, getType())) { // FIXME check should be done in the abstract class
|
||||
throw new InvalidJsonException("Type is not " + Type);
|
||||
}
|
||||
|
||||
getObj("content").entrySet().forEach(entry -> {
|
||||
if (!entry.getValue().isJsonArray()) {
|
||||
throw new InvalidJsonException("Content key " + entry.getKey() + " is not an array");
|
||||
}
|
||||
_MatrixID id = MatrixID.asAcceptable(entry.getKey());
|
||||
mappings.put(id, GsonUtil.asList(entry.getValue().getAsJsonArray(), String.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<_MatrixID, List<String>> getMappings() {
|
||||
return Collections.unmodifiableMap(mappings);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._MatrixEphemeralEvent;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
public class MatrixJsonEphemeralEvent extends MatrixJsonObject implements _MatrixEphemeralEvent {
|
||||
|
||||
private String type;
|
||||
|
||||
public MatrixJsonEphemeralEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
type = getString("type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2017 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._MatrixPersistentEvent;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
public class MatrixJsonPersistentEvent extends MatrixJsonObject implements _MatrixPersistentEvent {
|
||||
|
||||
private String id;
|
||||
private String type;
|
||||
private Long time;
|
||||
private int age;
|
||||
private _MatrixID sender;
|
||||
|
||||
public MatrixJsonPersistentEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
id = getString("event_id");
|
||||
type = getString("type");
|
||||
time = getLong("origin_server_ts");
|
||||
age = getInt("age", -1);
|
||||
sender = MatrixID.asAcceptable(getString("sender"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public _MatrixID getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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.event._ReadReceiptEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MatrixJsonReadReceiptEvent extends MatrixJsonEphemeralEvent implements _ReadReceiptEvent {
|
||||
|
||||
/**
|
||||
* Read receipts for a specific event.
|
||||
*/
|
||||
public static class Receipt {
|
||||
/**
|
||||
* ID of the event, the read markers point to.
|
||||
*/
|
||||
private String eventId;
|
||||
|
||||
/**
|
||||
* Every user whose read marker is set to the event specified by eventId
|
||||
* and it's point in time when this marker has been set to this event.
|
||||
*/
|
||||
private Map<MatrixID, Long> users;
|
||||
|
||||
public Receipt(String id, Map<MatrixID, Long> readMarkers) {
|
||||
this.eventId = id;
|
||||
this.users = readMarkers;
|
||||
}
|
||||
|
||||
public Map<MatrixID, Long> getUsersWithTimestamp() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public Set<MatrixID> getUsers() {
|
||||
return users.keySet();
|
||||
}
|
||||
|
||||
public String getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Receipt> receipts;
|
||||
|
||||
@Override
|
||||
public List<Receipt> getReceipts() {
|
||||
return receipts;
|
||||
}
|
||||
|
||||
public MatrixJsonReadReceiptEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
JsonObject content = getObj("content");
|
||||
List<String> eventIds = content.entrySet().stream().map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
receipts = eventIds.stream().map(id -> {
|
||||
JsonObject targetEvent = content.getAsJsonObject(id);
|
||||
JsonObject mRead = targetEvent.getAsJsonObject("m.read");
|
||||
|
||||
Map<MatrixID, Long> readMarkers = mRead.entrySet().stream()
|
||||
.collect(Collectors.toMap(it -> MatrixID.asAcceptable(it.getKey()),
|
||||
it -> GsonUtil.getLong(it.getValue().getAsJsonObject(), "ts")));
|
||||
return new Receipt(id, readMarkers);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomAliasesEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MatrixJsonRoomAliasesEvent extends MatrixJsonRoomEvent implements _RoomAliasesEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private List<String> aliases;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
setAliases(GsonUtil.asList(obj, "aliases", String.class));
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public void setAliases(List<String> aliases) {
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomAliasesEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
this.content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases() {
|
||||
return Collections.unmodifiableList(content.getAliases());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomAvatarEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
|
||||
public class MatrixJsonRoomAvatarEvent extends MatrixJsonRoomEvent implements _RoomAvatarEvent {
|
||||
|
||||
public static class Content {
|
||||
|
||||
private String url;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomAvatarEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
this.content = GsonUtil.get().fromJson(getObj("content"), Content.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return content.getUrl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomCanonicalAliasEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MatrixJsonRoomCanonicalAliasEvent extends MatrixJsonRoomEvent implements _RoomCanonicalAliasEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private String alias;
|
||||
|
||||
public Content(JsonObject content) {
|
||||
super(content);
|
||||
findString("alias").filter(StringUtils::isNotEmpty).ifPresent(this::setAlias);
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomCanonicalAliasEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
if (!StringUtils.equals(Type, getType())) { // FIXME check should be done in the abstract class
|
||||
throw new IllegalArgumentException("Type is not " + Type);
|
||||
}
|
||||
|
||||
this.content = new Content(GsonUtil.getObj(obj, "content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlias() {
|
||||
return StringUtils.isNotEmpty(content.getAlias());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getAlias() {
|
||||
return Optional.ofNullable(content.getAlias());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2017 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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 MatrixJsonPersistentEvent implements _RoomEvent {
|
||||
|
||||
private String roomId;
|
||||
|
||||
public MatrixJsonRoomEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
roomId = getString("room_id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomHistoryVisibilityEvent;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
public class MatrixJsonRoomHistoryVisibilityEvent extends MatrixJsonRoomEvent implements _RoomHistoryVisibilityEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private String historyVisibility;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
setHistoryVisibility(getString("history_visibility"));
|
||||
}
|
||||
|
||||
public String getHistoryVisibility() {
|
||||
return historyVisibility;
|
||||
}
|
||||
|
||||
public void setHistoryVisibility(String historyVisibility) {
|
||||
this.historyVisibility = historyVisibility;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomHistoryVisibilityEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHistoryVisibility() {
|
||||
return content.getHistoryVisibility();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2017 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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 {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private String membership;
|
||||
private String avatar;
|
||||
private String displayName;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
setMembership(getString("membership"));
|
||||
setAvatar(avatar = getStringOrNull("avatar_url"));
|
||||
setDisplayName(displayName = getStringOrNull("displayname"));
|
||||
}
|
||||
|
||||
public String getMembership() {
|
||||
return membership;
|
||||
}
|
||||
|
||||
public void setMembership(String membership) {
|
||||
this.membership = membership;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2017 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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 {
|
||||
|
||||
protected 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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomNameEvent;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MatrixJsonRoomNameEvent extends MatrixJsonRoomEvent implements _RoomNameEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private String name;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
setName(getStringOrNull("name"));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomNameEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
this.content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getName() {
|
||||
return Optional.ofNullable(content.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomPowerLevelsEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MatrixJsonRoomPowerLevelsEvent extends MatrixJsonRoomEvent implements _RoomPowerLevelsEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private Double ban;
|
||||
private Map<String, Double> events = new HashMap<>();
|
||||
private Double eventsDefault;
|
||||
private Double invite;
|
||||
private Double kick;
|
||||
private Double redact;
|
||||
private Double stateDefault;
|
||||
private Map<String, Double> users = new HashMap<>();
|
||||
private Double usersDefault;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
setBan(getDoubleIfPresent("ban"));
|
||||
setEventsDefault(getDoubleIfPresent("events_default"));
|
||||
setInvite(getDoubleIfPresent("invite"));
|
||||
setKick(getDoubleIfPresent("kick"));
|
||||
setRedact(getDoubleIfPresent("redact"));
|
||||
setStateDefault(getDoubleIfPresent("state_default"));
|
||||
setUsersDefault(getDoubleIfPresent("users_default"));
|
||||
|
||||
GsonUtil.findObj(obj, "events").ifPresent(eventsJson -> {
|
||||
Map<String, Double> eventsMap = eventsJson.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, it -> it.getValue().getAsDouble()));
|
||||
setEvents(eventsMap);
|
||||
});
|
||||
|
||||
GsonUtil.findObj(obj, "users").ifPresent(usersJson -> {
|
||||
Map<String, Double> usersMap = usersJson.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, it -> it.getValue().getAsDouble()));
|
||||
setUsers(usersMap);
|
||||
});
|
||||
}
|
||||
|
||||
public Double getBan() {
|
||||
return ban;
|
||||
}
|
||||
|
||||
public void setBan(Double ban) {
|
||||
this.ban = ban;
|
||||
}
|
||||
|
||||
public Double getEventsDefault() {
|
||||
return eventsDefault;
|
||||
}
|
||||
|
||||
public void setEventsDefault(Double eventsDefault) {
|
||||
this.eventsDefault = eventsDefault;
|
||||
}
|
||||
|
||||
public Map<String, Double> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public void setEvents(Map<String, Double> events) {
|
||||
this.events.putAll(events);
|
||||
}
|
||||
|
||||
public Double getInvite() {
|
||||
return invite;
|
||||
}
|
||||
|
||||
public void setInvite(Double invite) {
|
||||
this.invite = invite;
|
||||
}
|
||||
|
||||
public Double getKick() {
|
||||
return kick;
|
||||
}
|
||||
|
||||
public void setKick(Double kick) {
|
||||
this.kick = kick;
|
||||
}
|
||||
|
||||
public Double getRedact() {
|
||||
return redact;
|
||||
}
|
||||
|
||||
public void setRedact(Double redact) {
|
||||
this.redact = redact;
|
||||
}
|
||||
|
||||
public Double getStateDefault() {
|
||||
return stateDefault;
|
||||
}
|
||||
|
||||
public void setStateDefault(Double stateDefault) {
|
||||
this.stateDefault = stateDefault;
|
||||
}
|
||||
|
||||
public Map<String, Double> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Map<String, Double> users) {
|
||||
this.users.putAll(users);
|
||||
}
|
||||
|
||||
public Double getUsersDefault() {
|
||||
return usersDefault;
|
||||
}
|
||||
|
||||
public void setUsersDefault(Double usersDefault) {
|
||||
this.usersDefault = usersDefault;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomPowerLevelsEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getBan() {
|
||||
return Optional.ofNullable(content.getBan());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Double> getEvents() {
|
||||
return Collections.unmodifiableMap(content.getEvents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getEventsDefault() {
|
||||
return Optional.ofNullable(content.getEventsDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getInvite() {
|
||||
return Optional.ofNullable(content.getInvite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getKick() {
|
||||
return Optional.ofNullable(content.getKick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getRedact() {
|
||||
return Optional.ofNullable(content.getRedact());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getStateDefault() {
|
||||
return Optional.ofNullable(content.getStateDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Double> getUsers() {
|
||||
return Collections.unmodifiableMap(content.getUsers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getUsersDefault() {
|
||||
return Optional.ofNullable(content.getUsersDefault());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.kamax.matrix.event._TagsEvent;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
import io.kamax.matrix.room.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MatrixJsonRoomTagsEvent extends MatrixJsonObject implements _TagsEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
GsonUtil.findObj(obj, "tags").ifPresent(tagsJson -> {
|
||||
List<Tag> tags = tagsJson.entrySet().stream().map(it -> {
|
||||
String completeName = it.getKey();
|
||||
String name = completeName;
|
||||
String namespace = "";
|
||||
|
||||
int lastDotIndex = completeName.lastIndexOf(".");
|
||||
|
||||
if (lastDotIndex >= 0 && lastDotIndex < completeName.length() - 1) {
|
||||
namespace = completeName.substring(0, lastDotIndex);
|
||||
name = completeName.substring(lastDotIndex + 1);
|
||||
}
|
||||
|
||||
JsonElement jsonOrder = it.getValue().getAsJsonObject().get("order");
|
||||
|
||||
if (jsonOrder != null) {
|
||||
return new Tag(namespace, name, jsonOrder.getAsDouble());
|
||||
}
|
||||
return new Tag(namespace, name, null);
|
||||
}).collect(Collectors.toList());
|
||||
setTags(tags);
|
||||
});
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = new ArrayList<>(tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String type;
|
||||
protected Content content;
|
||||
|
||||
public MatrixJsonRoomTagsEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
type = getString("type");
|
||||
content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getTags() {
|
||||
return Collections.unmodifiableList(content.getTags());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* matrix-java-sdk - Matrix Client SDK for Java
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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._RoomTopicEvent;
|
||||
import io.kamax.matrix.json.MatrixJsonObject;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MatrixJsonRoomTopicEvent extends MatrixJsonRoomEvent implements _RoomTopicEvent {
|
||||
|
||||
public static class Content extends MatrixJsonObject {
|
||||
|
||||
private String topic;
|
||||
|
||||
public Content(JsonObject obj) {
|
||||
super(obj);
|
||||
|
||||
setTopic(getStringOrNull("topic"));
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(String topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Content content;
|
||||
|
||||
public MatrixJsonRoomTopicEvent(JsonObject obj) {
|
||||
super(obj);
|
||||
this.content = new Content(getObj("content"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getTopic() {
|
||||
return Optional.ofNullable(content.getTopic());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user