mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-04 05:00:39 +00:00
extend DBus signals with a field for mentions
This change affects the DBus signals `SyncMessageReceived` and `MessageReceived`. Mentions are represented as an array of structs. Each mention holds the name of the mentioned user, its position and length.
This commit is contained in:
parent
dedbafb99a
commit
dcb90d8fa1
4 changed files with 61 additions and 4 deletions
|
@ -223,7 +223,7 @@ isRegistred -> result<b>::
|
||||||
|
|
||||||
== Signals
|
== Signals
|
||||||
|
|
||||||
SyncMessageReceived (timestamp<x>, sender<s>, destination<s>, groupId<ay>,message<s>, attachments<as>)::
|
SyncMessageReceived (timestamp<x>, sender<s>, destination<s>, groupId<ay>, message<s>, mentions<a(sii)>, attachments<as>)::
|
||||||
The sync message is received when the user sends a message from a linked device.
|
The sync message is received when the user sends a message from a linked device.
|
||||||
|
|
||||||
ReceiptReceived (timestamp<x>, sender<s>)::
|
ReceiptReceived (timestamp<x>, sender<s>)::
|
||||||
|
@ -232,11 +232,12 @@ ReceiptReceived (timestamp<x>, sender<s>)::
|
||||||
|
|
||||||
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
|
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
|
||||||
|
|
||||||
MessageReceived(timestamp<x>, sender<s>, groupId<ay>, message<s>, attachments<as>)::
|
MessageReceived(timestamp<x>, sender<s>, groupId<ay>, message<s>, mentions<a(sii)>, attachments<as>)::
|
||||||
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
|
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
|
||||||
* sender : Phone number of the sender
|
* sender : Phone number of the sender
|
||||||
* groupId : Byte array representing the internal group identifier (empty when private message)
|
* groupId : Byte array representing the internal group identifier (empty when private message)
|
||||||
* message : Message text
|
* message : Message text
|
||||||
|
* mentions : Struct array of mentions. A mention consists of a user name, its position in the message string and its length.
|
||||||
* attachments : String array of filenames for the attachments. These files are located in the signal-cli storage and the current user needs to have read access there
|
* attachments : String array of filenames for the attachments. These files are located in the signal-cli storage and the current user needs to have read access there
|
||||||
|
|
||||||
This signal is received whenever we get a private message or a message is posted in a group we are an active member
|
This signal is received whenever we get a private message or a message is posted in a group we are an active member
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.asamk;
|
package org.asamk;
|
||||||
|
|
||||||
|
import org.asamk.signal.dbus.DbusMention;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||||
|
@ -101,6 +102,7 @@ public interface Signal extends DBusInterface {
|
||||||
private final String sender;
|
private final String sender;
|
||||||
private final byte[] groupId;
|
private final byte[] groupId;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
private final List<DbusMention> mentions;
|
||||||
private final List<String> attachments;
|
private final List<String> attachments;
|
||||||
|
|
||||||
public MessageReceived(
|
public MessageReceived(
|
||||||
|
@ -109,13 +111,15 @@ public interface Signal extends DBusInterface {
|
||||||
String sender,
|
String sender,
|
||||||
byte[] groupId,
|
byte[] groupId,
|
||||||
String message,
|
String message,
|
||||||
|
List<DbusMention> mentions,
|
||||||
List<String> attachments
|
List<String> attachments
|
||||||
) throws DBusException {
|
) throws DBusException {
|
||||||
super(objectpath, timestamp, sender, groupId, message, attachments);
|
super(objectpath, timestamp, sender, groupId, message, mentions, attachments);
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.mentions = mentions;
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +139,10 @@ public interface Signal extends DBusInterface {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DbusMention> getMentions() {
|
||||||
|
return mentions;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getAttachments() {
|
public List<String> getAttachments() {
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
@ -167,6 +175,7 @@ public interface Signal extends DBusInterface {
|
||||||
private final String destination;
|
private final String destination;
|
||||||
private final byte[] groupId;
|
private final byte[] groupId;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
private final List<DbusMention> mentions;
|
||||||
private final List<String> attachments;
|
private final List<String> attachments;
|
||||||
|
|
||||||
public SyncMessageReceived(
|
public SyncMessageReceived(
|
||||||
|
@ -176,14 +185,16 @@ public interface Signal extends DBusInterface {
|
||||||
String destination,
|
String destination,
|
||||||
byte[] groupId,
|
byte[] groupId,
|
||||||
String message,
|
String message,
|
||||||
|
List<DbusMention> mentions,
|
||||||
List<String> attachments
|
List<String> attachments
|
||||||
) throws DBusException {
|
) throws DBusException {
|
||||||
super(objectpath, timestamp, source, destination, groupId, message, attachments);
|
super(objectpath, timestamp, source, destination, groupId, message, mentions, attachments);
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.mentions = mentions;
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +218,10 @@ public interface Signal extends DBusInterface {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DbusMention> getMentions() {
|
||||||
|
return mentions;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getAttachments() {
|
public List<String> getAttachments() {
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.asamk.signal;
|
package org.asamk.signal;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.dbus.DbusMention;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
|
@ -74,6 +75,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
getLegacyIdentifier(sender),
|
getLegacyIdentifier(sender),
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId != null ? groupId : new byte[0],
|
||||||
message.getBody().isPresent() ? message.getBody().get() : "",
|
message.getBody().isPresent() ? message.getBody().get() : "",
|
||||||
|
JsonDbusReceiveMessageHandler.getMentions(message, m),
|
||||||
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -99,6 +101,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
: "",
|
: "",
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId != null ? groupId : new byte[0],
|
||||||
message.getBody().isPresent() ? message.getBody().get() : "",
|
message.getBody().isPresent() ? message.getBody().get() : "",
|
||||||
|
JsonDbusReceiveMessageHandler.getMentions(message, m),
|
||||||
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -126,6 +129,16 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private List<DbusMention> getMentions(SignalServiceDataMessage message, Manager m) {
|
||||||
|
var mentions = new ArrayList<DbusMention>();
|
||||||
|
if (message.getMentions().isPresent()) {
|
||||||
|
for (var mention : message.getMentions().get()) {
|
||||||
|
mentions.add(new DbusMention(mention, m));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mentions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
||||||
super.handleMessage(envelope, content, exception);
|
super.handleMessage(envelope, content, exception);
|
||||||
|
|
28
src/main/java/org/asamk/signal/dbus/DbusMention.java
Normal file
28
src/main/java/org/asamk/signal/dbus/DbusMention.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package org.asamk.signal.dbus;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.freedesktop.dbus.Struct;
|
||||||
|
import org.freedesktop.dbus.annotations.Position;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
|
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||||
|
|
||||||
|
public final class DbusMention extends Struct {
|
||||||
|
|
||||||
|
@Position(0)
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
@Position(1)
|
||||||
|
public final int start;
|
||||||
|
|
||||||
|
@Position(2)
|
||||||
|
public final int length;
|
||||||
|
|
||||||
|
public DbusMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||||
|
this.name = getLegacyIdentifier(m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(),
|
||||||
|
null)));
|
||||||
|
this.start = mention.getStart();
|
||||||
|
this.length = mention.getLength();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue