Turakar / signal4j

A facade to make using the libsignal-service easy
GNU General Public License v3.0
13 stars 6 forks source link

users cannot send to groups except when they are responding #5

Open Trolldemorted opened 7 years ago

Trolldemorted commented 7 years ago

signal4j does not offer (?) a way to send messages to groups, if the user knows only the groupid, because signal4j won't tell you the group's members.

In the sample plugins this works nicely as they only respond to group messages and thus get a handle to the group object, but a plugin that wants to send messages without receiving some does not.

I have added a new sendMessage overload to SignalService to have a dirty workaround:

public void sendMessage(String groupId, String content) throws IOException {
    byte[] id = Base64.decode(groupId);
    Group group = store.getDataStore().getGroup(new GroupId(id));
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
        .withTimestamp(System.currentTimeMillis())
        .asGroupMessage(SignalServiceGroup.newBuilder(Type.DELIVER)
            .withId(group.getId().getId())
            .build())
        .withBody(content)
        .withExpiration(group.getMessageExpirationTime())
        .build();
   sendMessage(group.getMembers(), message);
}

What did you intend?

Turakar commented 6 years ago

I intend that you keep the Group object as a handle for later reference instead of the group id. However, I understand that this would need an additional serialization process outside the library. Maybe it would be better to provide a function for getting the associated Group object from the groupId, maybe in DataStore. Additional methods for User etc. should be taken in consideration.

This would allow an application to only save the ids.