mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement EditMessageReceived signal for dbus
This commit is contained in:
parent
7b5b5776f0
commit
a66dd0dc79
4 changed files with 124 additions and 1 deletions
|
@ -545,7 +545,7 @@
|
||||||
"name":"org.asamk.Signal",
|
"name":"org.asamk.Signal",
|
||||||
"allDeclaredMethods":true,
|
"allDeclaredMethods":true,
|
||||||
"allDeclaredClasses":true,
|
"allDeclaredClasses":true,
|
||||||
"methods":[{"name":"getSelfNumber","parameterTypes":[] }, {"name":"sendGroupMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","byte[]"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.lang.String"] }, {"name":"sendMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","java.util.List"] }]
|
"methods":[{"name":"getSelfNumber","parameterTypes":[] }, {"name":"sendGroupMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","byte[]"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.lang.String"] }, {"name":"sendMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","java.util.List"] }, {"name":"subscribeReceive","parameterTypes":[] }, {"name":"unsubscribeReceive","parameterTypes":[] }]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"org.asamk.Signal$Configuration",
|
"name":"org.asamk.Signal$Configuration",
|
||||||
|
@ -557,6 +557,11 @@
|
||||||
"allDeclaredMethods":true,
|
"allDeclaredMethods":true,
|
||||||
"allDeclaredClasses":true
|
"allDeclaredClasses":true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"org.asamk.Signal$EditMessageReceived",
|
||||||
|
"queryAllDeclaredConstructors":true,
|
||||||
|
"queryAllPublicConstructors":true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"org.asamk.Signal$Error$AttachmentInvalid",
|
"name":"org.asamk.Signal$Error$AttachmentInvalid",
|
||||||
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
|
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
|
||||||
|
|
|
@ -235,6 +235,58 @@ public interface Signal extends DBusInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EditMessageReceived extends DBusSignal {
|
||||||
|
|
||||||
|
private final long timestamp;
|
||||||
|
private final long targetSentTimestamp;
|
||||||
|
private final String sender;
|
||||||
|
private final byte[] groupId;
|
||||||
|
private final String message;
|
||||||
|
private final Map<String, Variant<?>> extras;
|
||||||
|
|
||||||
|
public EditMessageReceived(
|
||||||
|
String objectpath,
|
||||||
|
long timestamp,
|
||||||
|
final long targetSentTimestamp,
|
||||||
|
String sender,
|
||||||
|
byte[] groupId,
|
||||||
|
String message,
|
||||||
|
final Map<String, Variant<?>> extras
|
||||||
|
) throws DBusException {
|
||||||
|
super(objectpath, timestamp, targetSentTimestamp, sender, groupId, message, extras);
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.targetSentTimestamp = targetSentTimestamp;
|
||||||
|
this.sender = sender;
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.message = message;
|
||||||
|
this.extras = extras;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTargetSentTimestamp() {
|
||||||
|
return targetSentTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Variant<?>> getExtras() {
|
||||||
|
return extras;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MessageReceived extends DBusSignal {
|
class MessageReceived extends DBusSignal {
|
||||||
|
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
|
private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
|
||||||
private final List<Runnable> closedListeners = new ArrayList<>();
|
private final List<Runnable> closedListeners = new ArrayList<>();
|
||||||
private DBusSigHandler<Signal.MessageReceivedV2> dbusMsgHandler;
|
private DBusSigHandler<Signal.MessageReceivedV2> dbusMsgHandler;
|
||||||
|
private DBusSigHandler<Signal.EditMessageReceived> dbusEditMsgHandler;
|
||||||
private DBusSigHandler<Signal.ReceiptReceivedV2> dbusRcptHandler;
|
private DBusSigHandler<Signal.ReceiptReceivedV2> dbusRcptHandler;
|
||||||
private DBusSigHandler<Signal.SyncMessageReceivedV2> dbusSyncHandler;
|
private DBusSigHandler<Signal.SyncMessageReceivedV2> dbusSyncHandler;
|
||||||
|
|
||||||
|
@ -799,6 +800,49 @@ public class DbusManagerImpl implements Manager {
|
||||||
notifyMessageHandlers(envelope);
|
notifyMessageHandlers(envelope);
|
||||||
};
|
};
|
||||||
connection.addSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
connection.addSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
||||||
|
this.dbusEditMsgHandler = messageReceived -> {
|
||||||
|
final var extras = messageReceived.getExtras();
|
||||||
|
final var envelope = new MessageEnvelope(Optional.of(new RecipientAddress(null,
|
||||||
|
messageReceived.getSender())),
|
||||||
|
0,
|
||||||
|
messageReceived.getTimestamp(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.of(new MessageEnvelope.Edit(messageReceived.getTargetSentTimestamp(),
|
||||||
|
new MessageEnvelope.Data(messageReceived.getTimestamp(),
|
||||||
|
messageReceived.getGroupId().length > 0
|
||||||
|
? Optional.of(new MessageEnvelope.Data.GroupContext(GroupId.unknownVersion(
|
||||||
|
messageReceived.getGroupId()), false, 0))
|
||||||
|
: Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.of(messageReceived.getMessage()),
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
getAttachments(extras),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
List.of(),
|
||||||
|
List.of(),
|
||||||
|
List.of(),
|
||||||
|
List.of()))),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty());
|
||||||
|
notifyMessageHandlers(envelope);
|
||||||
|
};
|
||||||
|
connection.addSigHandler(Signal.EditMessageReceived.class, signal, this.dbusEditMsgHandler);
|
||||||
|
|
||||||
this.dbusRcptHandler = receiptReceived -> {
|
this.dbusRcptHandler = receiptReceived -> {
|
||||||
final var type = switch (receiptReceived.getReceiptType()) {
|
final var type = switch (receiptReceived.getReceiptType()) {
|
||||||
|
@ -901,6 +945,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
try {
|
try {
|
||||||
signal.unsubscribeReceive();
|
signal.unsubscribeReceive();
|
||||||
connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
|
||||||
|
connection.removeSigHandler(Signal.EditMessageReceived.class, signal, this.dbusEditMsgHandler);
|
||||||
connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
|
connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
|
||||||
connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
|
connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
|
|
|
@ -74,6 +74,27 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
||||||
getMessageExtras(message)));
|
getMessageExtras(message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (envelope.edit().isPresent()) {
|
||||||
|
var editMessage = envelope.edit().get();
|
||||||
|
var message = editMessage.dataMessage();
|
||||||
|
|
||||||
|
var groupId = message.groupContext()
|
||||||
|
.map(MessageEnvelope.Data.GroupContext::groupId)
|
||||||
|
.map(GroupId::serialize)
|
||||||
|
.orElseGet(() -> new byte[0]);
|
||||||
|
var isGroupUpdate = message.groupContext()
|
||||||
|
.map(MessageEnvelope.Data.GroupContext::isGroupUpdate)
|
||||||
|
.orElse(false);
|
||||||
|
if (!message.isEndSession() && !isGroupUpdate) {
|
||||||
|
conn.sendMessage(new Signal.EditMessageReceived(objectPath,
|
||||||
|
message.timestamp(),
|
||||||
|
editMessage.targetSentTimestamp(),
|
||||||
|
senderString,
|
||||||
|
groupId,
|
||||||
|
message.body().orElse(""),
|
||||||
|
getMessageExtras(message)));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (envelope.sync().isPresent()) {
|
if (envelope.sync().isPresent()) {
|
||||||
var syncMessage = envelope.sync().get();
|
var syncMessage = envelope.sync().get();
|
||||||
if (syncMessage.sent().isPresent()) {
|
if (syncMessage.sent().isPresent()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue