Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceGroup
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceGroup.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 6 votes |
private static Long handleGroupLeave(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, @NonNull GroupRecord record, boolean outgoing) { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); GroupId id = GroupId.v1orThrow(group.getGroupId()); List<RecipientId> members = record.getMembers(); GroupContext.Builder builder = createGroupContext(group); builder.setType(GroupContext.Type.QUIT); if (members.contains(Recipient.externalPush(context, content.getSender()).getId())) { database.remove(id, Recipient.externalPush(context, content.getSender()).getId()); if (outgoing) database.setActive(id, false); return storeMessage(context, content, group, builder.build(), outgoing); } return null; }
Example #2
Source Project: mollyim-android Author: mollyim File: GroupUtil.java License: GNU General Public License v3.0 | 6 votes |
@WorkerThread public static void setDataMessageGroupContext(@NonNull Context context, @NonNull SignalServiceDataMessage.Builder dataMessageBuilder, @NonNull GroupId.Push groupId) { if (groupId.isV2()) { GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId); GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties(); SignalServiceGroupV2 group = SignalServiceGroupV2.newBuilder(v2GroupProperties.getGroupMasterKey()) .withRevision(v2GroupProperties.getGroupRevision()) .build(); dataMessageBuilder.asGroupMessage(group); } else { dataMessageBuilder.asGroupMessage(new SignalServiceGroup(groupId.getDecodedId())); } }
Example #3
Source Project: mollyim-android Author: mollyim File: RequestGroupInfoJob.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onRun() throws IOException, UntrustedIdentityException { SignalServiceGroup group = SignalServiceGroup.newBuilder(Type.REQUEST_INFO) .withId(groupId.getDecodedId()) .build(); SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder() .asGroupMessage(group) .withTimestamp(System.currentTimeMillis()) .build(); SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); Recipient recipient = Recipient.resolved(source); messageSender.sendMessage(RecipientUtil.toSignalServiceAddress(context, recipient), UnidentifiedAccessUtil.getAccessFor(context, recipient), message); }
Example #4
Source Project: bcm-android Author: bcmapp File: IncomingTextMessage.java License: GNU General Public License v3.0 | 6 votes |
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis, String encodedBody, Optional<SignalServiceGroup> group, long expiresInMillis) { this.message = encodedBody; this.payloadType = parseBodyPayloadType(encodedBody); this.sender = sender; this.senderDeviceId = senderDeviceId; this.protocol = 31337; this.serviceCenterAddress = "GCM"; this.replyPathPresent = true; this.pseudoSubject = ""; this.sentTimestampMillis = sentTimestampMillis; this.push = true; this.subscriptionId = -1; this.expiresInMillis = expiresInMillis; this.groupId = null; }
Example #5
Source Project: bcm-android Author: bcmapp File: IncomingMediaMessage.java License: GNU General Public License v3.0 | 6 votes |
public IncomingMediaMessage(MasterSecretUnion masterSecret, Address from, long sentTimeMillis, int subscriptionId, long expiresIn, boolean expirationUpdate, Optional<String> relay, Optional<String> body, Optional<SignalServiceGroup> group, Optional<List<SignalServiceAttachment>> attachments) { this.push = true; this.from = from; this.sentTimeMillis = sentTimeMillis; this.body = body.orNull(); this.subscriptionId = subscriptionId; this.expiresIn = expiresIn; this.expirationUpdate = expirationUpdate; this.groupId = null; this.attachments.addAll(PointerAttachment.forPointers(masterSecret, attachments)); }
Example #6
Source Project: signald Author: thefinn93 File: JsonGroupInfo.java License: GNU General Public License v3.0 | 6 votes |
JsonGroupInfo(SignalServiceGroup groupInfo, String username) throws IOException, NoSuchAccountException { Manager manager = Manager.get(username); this.groupId = Base64.encodeBytes(groupInfo.getGroupId()); if (groupInfo.getMembers().isPresent()) { this.members = groupInfo.getMembers().get(); } if (groupInfo.getName().isPresent()) { this.name = groupInfo.getName().get(); } else { GroupInfo group = manager.getGroup(groupInfo.getGroupId()); if(group != null) { this.name = group.name; } } this.type = groupInfo.getType().toString(); }
Example #7
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 6 votes |
public long sendGroupMessage(String messageText, List<String> attachments, byte[] groupId) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException { final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); if (attachments != null) { messageBuilder.withAttachments(Utils.getSignalServiceAttachments(attachments)); } if (groupId != null) { SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER) .withId(groupId) .build(); messageBuilder.asGroupMessage(group); } final GroupInfo g = getGroupForSending(groupId); messageBuilder.withExpiration(g.messageExpirationTime); return sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress())); }
Example #8
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 6 votes |
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) throws AttachmentInvalidException { SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE) .withId(g.groupId) .withName(g.name) .withMembers(new ArrayList<>(g.getMembers())); File aFile = getGroupAvatarFile(g.groupId); if (aFile.exists()) { try { group.withAvatar(Utils.createAttachment(aFile)); } catch (IOException e) { throw new AttachmentInvalidException(aFile.toString(), e); } } return SignalServiceDataMessage.newBuilder() .asGroupMessage(group.build()) .withExpiration(g.messageExpirationTime); }
Example #9
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 6 votes |
private boolean isMessageBlocked(SignalServiceEnvelope envelope, SignalServiceContent content) { SignalServiceAddress source; if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { source = envelope.getSourceAddress(); } else if (content != null) { source = content.getSender(); } else { return false; } ContactInfo sourceContact = account.getContactStore().getContact(source); if (sourceContact != null && sourceContact.blocked) { return true; } if (content != null && content.getDataMessage().isPresent()) { SignalServiceDataMessage message = content.getDataMessage().get(); if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) { SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get(); GroupInfo group = getGroup(groupInfo.getGroupId()); if (groupInfo.getType() == SignalServiceGroup.Type.DELIVER && group != null && group.blocked) { return true; } } } return false; }
Example #10
Source Project: signal-cli Author: AsamK File: JsonDataMessage.java License: GNU General Public License v3.0 | 6 votes |
JsonDataMessage(SignalServiceDataMessage dataMessage) { this.timestamp = dataMessage.getTimestamp(); if (dataMessage.getGroupContext().isPresent() && dataMessage.getGroupContext().get().getGroupV1().isPresent()) { SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get(); this.groupInfo = new JsonGroupInfo(groupInfo); } if (dataMessage.getBody().isPresent()) { this.message = dataMessage.getBody().get(); } this.expiresInSeconds = dataMessage.getExpiresInSeconds(); if (dataMessage.getAttachments().isPresent()) { this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size()); for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) { this.attachments.add(new JsonAttachment(attachment)); } } else { this.attachments = new ArrayList<>(); } }
Example #11
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 5 votes |
public static @Nullable Long process(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, boolean outgoing) { SignalServiceGroupContext signalServiceGroupContext = message.getGroupContext().get(); Optional<SignalServiceGroup> groupV1 = signalServiceGroupContext.getGroupV1(); if (signalServiceGroupContext.getGroupV2().isPresent()) { throw new AssertionError("Cannot process GV2"); } if (!groupV1.isPresent() || groupV1.get().getGroupId() == null) { Log.w(TAG, "Received group message with no id! Ignoring..."); return null; } GroupDatabase database = DatabaseFactory.getGroupDatabase(context); SignalServiceGroup group = groupV1.get(); GroupId id = GroupId.v1orThrow(group.getGroupId()); Optional<GroupRecord> record = database.getGroup(id); if (record.isPresent() && group.getType() == Type.UPDATE) { return handleGroupUpdate(context, content, group, record.get(), outgoing); } else if (!record.isPresent() && group.getType() == Type.UPDATE) { return handleGroupCreate(context, content, group, outgoing); } else if (record.isPresent() && group.getType() == Type.QUIT) { return handleGroupLeave(context, content, group, record.get(), outgoing); } else if (record.isPresent() && group.getType() == Type.REQUEST_INFO) { return handleGroupInfoRequest(context, content, record.get()); } else { Log.w(TAG, "Received unknown type, ignoring..."); return null; } }
Example #12
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 5 votes |
private static @Nullable Long handleGroupCreate(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, boolean outgoing) { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); GroupId.V1 id = GroupId.v1orThrow(group.getGroupId()); GroupContext.Builder builder = createGroupContext(group); builder.setType(GroupContext.Type.UPDATE); SignalServiceAttachment avatar = group.getAvatar().orNull(); List<RecipientId> members = new LinkedList<>(); if (group.getMembers().isPresent()) { for (SignalServiceAddress member : group.getMembers().get()) { members.add(Recipient.externalPush(context, member).getId()); } } database.create(id, group.getName().orNull(), members, avatar != null && avatar.isPointer() ? avatar.asPointer() : null, null); Recipient sender = Recipient.externalPush(context, content.getSender()); if (FeatureFlags.messageRequests() && (sender.isSystemContact() || sender.isProfileSharing())) { Log.i(TAG, "Auto-enabling profile sharing because 'adder' is trusted. contact: " + sender.isSystemContact() + ", profileSharing: " + sender.isProfileSharing()); DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.externalGroup(context, id).getId(), true); } return storeMessage(context, content, group, builder.build(), outgoing); }
Example #13
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 5 votes |
private static GroupContext.Builder createGroupContext(SignalServiceGroup group) { GroupContext.Builder builder = GroupContext.newBuilder(); builder.setId(ByteString.copyFrom(group.getGroupId())); if (group.getAvatar().isPresent() && group.getAvatar().get().isPointer()) { builder.setAvatar(AttachmentPointer.newBuilder() .setCdnId(group.getAvatar().get().asPointer().getRemoteId().getV2().get()) .setKey(ByteString.copyFrom(group.getAvatar().get().asPointer().getKey())) .setContentType(group.getAvatar().get().getContentType())); } if (group.getName().isPresent()) { builder.setName(group.getName().get()); } if (group.getMembers().isPresent()) { builder.addAllMembersE164(Stream.of(group.getMembers().get()) .filter(a -> a.getNumber().isPresent()) .map(a -> a.getNumber().get()) .toList()); builder.addAllMembers(Stream.of(group.getMembers().get()) .map(GroupV1MessageProcessor::createMember) .toList()); } return builder; }
Example #14
Source Project: mollyim-android Author: mollyim File: LeaveGroupJob.java License: GNU General Public License v3.0 | 5 votes |
private static @NonNull List<Recipient> deliver(@NonNull Context context, @NonNull GroupId.Push groupId, @NonNull String name, @NonNull List<RecipientId> members, @NonNull List<RecipientId> destinations) throws IOException, UntrustedIdentityException { SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); List<SignalServiceAddress> addresses = Stream.of(destinations).map(Recipient::resolved).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList(); List<SignalServiceAddress> memberAddresses = Stream.of(members).map(Recipient::resolved).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList(); List<Optional<UnidentifiedAccessPair>> unidentifiedAccess = Stream.of(destinations).map(Recipient::resolved).map(recipient -> UnidentifiedAccessUtil.getAccessFor(context, recipient)).toList(); SignalServiceGroup serviceGroup = new SignalServiceGroup(SignalServiceGroup.Type.QUIT, groupId.getDecodedId(), name, memberAddresses, null); SignalServiceDataMessage.Builder dataMessage = SignalServiceDataMessage.newBuilder() .withTimestamp(System.currentTimeMillis()) .asGroupMessage(serviceGroup); List<SendMessageResult> results = messageSender.sendMessage(addresses, unidentifiedAccess, false, dataMessage.build()); Stream.of(results) .filter(r -> r.getIdentityFailure() != null) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .forEach(r -> Log.w(TAG, "Identity failure for " + r.getId())); Stream.of(results) .filter(SendMessageResult::isUnregisteredFailure) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .forEach(r -> Log.w(TAG, "Unregistered failure for " + r.getId())); return Stream.of(results) .filter(r -> r.getSuccess() != null || r.getIdentityFailure() != null || r.isUnregisteredFailure()) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .toList(); }
Example #15
Source Project: mollyim-android Author: mollyim File: ProfileKeySendJob.java License: GNU General Public License v3.0 | 5 votes |
private List<Recipient> deliver(@NonNull Recipient conversationRecipient, @NonNull List<Recipient> destinations) throws IOException, UntrustedIdentityException { SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); List<SignalServiceAddress> addresses = Stream.of(destinations).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList(); List<Optional<UnidentifiedAccessPair>> unidentifiedAccess = Stream.of(destinations).map(recipient -> UnidentifiedAccessUtil.getAccessFor(context, recipient)).toList(); SignalServiceDataMessage.Builder dataMessage = SignalServiceDataMessage.newBuilder() .asProfileKeyUpdate(true) .withTimestamp(System.currentTimeMillis()) .withProfileKey(Recipient.self().resolve().getProfileKey()); if (conversationRecipient.isGroup()) { dataMessage.asGroupMessage(new SignalServiceGroup(conversationRecipient.requireGroupId().getDecodedId())); } List<SendMessageResult> results = messageSender.sendMessage(addresses, unidentifiedAccess, false, dataMessage.build()); Stream.of(results) .filter(r -> r.getIdentityFailure() != null) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .forEach(r -> Log.w(TAG, "Identity failure for " + r.getId())); Stream.of(results) .filter(SendMessageResult::isUnregisteredFailure) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .forEach(r -> Log.w(TAG, "Unregistered failure for " + r.getId())); return Stream.of(results) .filter(r -> r.getSuccess() != null || r.getIdentityFailure() != null || r.isUnregisteredFailure()) .map(SendMessageResult::getAddress) .map(a -> Recipient.externalPush(context, a)) .toList(); }
Example #16
Source Project: mollyim-android Author: mollyim File: PushProcessMessageJob.java License: GNU General Public License v3.0 | 5 votes |
private void handleUnknownGroupMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceGroupContext group) throws BadGroupIdException { if (group.getGroupV1().isPresent()) { SignalServiceGroup groupV1 = group.getGroupV1().get(); if (groupV1.getType() != SignalServiceGroup.Type.REQUEST_INFO) { ApplicationDependencies.getJobManager().add(new RequestGroupInfoJob(Recipient.externalPush(context, content.getSender()).getId(), GroupId.v1(groupV1.getGroupId()))); } else { Log.w(TAG, "Received a REQUEST_INFO message for a group we don't know about. Ignoring."); } } else { Log.w(TAG, "Received a message for a group we don't know about without a GV1 context. Ignoring."); } }
Example #17
Source Project: bcm-android Author: bcmapp File: SignalServiceCipher.java License: GNU General Public License v3.0 | 5 votes |
private SignalServiceDataMessage createSignalServiceMessage(SignalServiceProtos.Envelope envelope, DataMessage content) throws InvalidMessageException { SignalServiceGroup groupInfo = createGroupInfo(envelope, content); List<SignalServiceAttachment> attachments = new LinkedList<>(); boolean endSession = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE) != 0); boolean expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0); boolean profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0); boolean newGroupShare = ((content.getFlags() & 8) != 0);//添加 newGroupShare 类型 for (AttachmentPointer pointer : content.getAttachmentsList()) { attachments.add(new SignalServiceAttachmentPointer(pointer.getId(), pointer.getContentType(), pointer.getKey().toByteArray(), envelope.getRelay(), pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(), pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(), pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(), pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(), (pointer.getFlags() & AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0, pointer.hasUrl() ? Optional.of(pointer.getUrl()) : Optional.<String>absent())); } if (content.hasTimestamp() && content.getTimestamp() != envelope.getTimestamp()) { throw new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + envelope.getTimestamp()); } return new SignalServiceDataMessage(envelope.getTimestamp(), groupInfo, attachments, content.getBody(), endSession, content.getExpireTimer(), expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null, profileKeyUpdate, newGroupShare); }
Example #18
Source Project: bcm-android Author: bcmapp File: IdentityUtil.java License: GNU General Public License v3.0 | 5 votes |
public static void markIdentityVerified(Recipient recipient, boolean verified, boolean remote) { PrivateChatRepo repo = Repository.getChatRepo(recipient.getAddress().context()); ThreadRepo threadRepo = Repository.getThreadRepo(recipient.getAddress().context()); if (repo == null || threadRepo == null) { return; } long threadId = threadRepo.getThreadIdFor(recipient); long time = ChatTimestamp.getTime(recipient.getAddress().context(), threadId); if (remote) { IncomingTextMessage incoming = new IncomingTextMessage(recipient.getAddress(), 1, time, null, Optional.<SignalServiceGroup>absent(), 0); if (verified) incoming = new IncomingIdentityVerifiedMessage(incoming); else incoming = new IncomingIdentityDefaultMessage(incoming); repo.insertIncomingTextMessage(incoming); } else { OutgoingTextMessage outgoing; if (verified) outgoing = new OutgoingIdentityVerifiedMessage(recipient); else outgoing = new OutgoingIdentityDefaultMessage(recipient); Log.w(TAG, "Inserting verified outbox..."); repo.insertOutgoingTextMessage(threadId, outgoing, time, null); } }
Example #19
Source Project: signal-bot Author: nerdclub-tfg File: Signal.java License: GNU Affero General Public License v3.0 | 5 votes |
public void sendMessage(User sender, Group group, SignalServiceDataMessage.Builder messageBuilder) throws IOException { messageBuilder.withTimestamp(System.currentTimeMillis()); if(group != null) { messageBuilder.asGroupMessage(SignalServiceGroup.newBuilder(Type.DELIVER).withId(group.getId().getId()).build()); sendMessage(group.getMembers(), messageBuilder.build()); } else { sendMessage(sender.getNumber(), messageBuilder.build()); } }
Example #20
Source Project: libsignal-service-java Author: signalapp File: UnsupportedDataMessageException.java License: GNU General Public License v3.0 | 5 votes |
public UnsupportedDataMessageException(int currentVersion, int requiredVersion, String sender, int senderDevice, Optional<SignalServiceGroup> group) { super("Required version: " + requiredVersion + ", Our version: " + currentVersion); this.requiredVersion = requiredVersion; this.sender = sender; this.senderDevice = senderDevice; this.group = group; }
Example #21
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 5 votes |
public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, byte[] groupId) throws IOException, EncapsulatedExceptions, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException { SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() .withReaction(reaction); if (groupId != null) { SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER) .withId(groupId) .build(); messageBuilder.asGroupMessage(group); } final GroupInfo g = getGroupForSending(groupId); sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress())); }
Example #22
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 5 votes |
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions, NotAGroupMemberException { SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT) .withId(groupId) .build(); SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() .asGroupMessage(group); final GroupInfo g = getGroupForSending(groupId); g.removeMember(account.getSelfAddress()); account.getGroupStore().updateGroup(g); sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress())); }
Example #23
Source Project: signal-cli Author: AsamK File: Manager.java License: GNU General Public License v3.0 | 5 votes |
void sendGroupInfoRequest(byte[] groupId, SignalServiceAddress recipient) throws IOException, EncapsulatedExceptions { if (groupId == null) { return; } SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO) .withId(groupId); SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() .asGroupMessage(group.build()); // Send group info request message to the recipient who sent us a message with this groupId sendMessageLegacy(messageBuilder, Collections.singleton(recipient)); }
Example #24
Source Project: signal-cli Author: AsamK File: JsonGroupInfo.java License: GNU General Public License v3.0 | 5 votes |
JsonGroupInfo(SignalServiceGroup groupInfo) { this.groupId = Base64.encodeBytes(groupInfo.getGroupId()); if (groupInfo.getMembers().isPresent()) { this.members = new ArrayList<>(groupInfo.getMembers().get().size()); for (SignalServiceAddress address : groupInfo.getMembers().get()) { this.members.add(address.getNumber().get()); } } if (groupInfo.getName().isPresent()) { this.name = groupInfo.getName().get(); } this.type = groupInfo.getType().toString(); }
Example #25
Source Project: mollyim-android Author: mollyim File: SignalServiceMessageSender.java License: GNU General Public License v3.0 | 4 votes |
private GroupContext createGroupContent(SignalServiceGroup group) throws IOException { GroupContext.Builder builder = GroupContext.newBuilder(); builder.setId(ByteString.copyFrom(group.getGroupId())); if (group.getType() != SignalServiceGroup.Type.DELIVER) { if (group.getType() == SignalServiceGroup.Type.UPDATE) builder.setType(GroupContext.Type.UPDATE); else if (group.getType() == SignalServiceGroup.Type.QUIT) builder.setType(GroupContext.Type.QUIT); else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO) builder.setType(GroupContext.Type.REQUEST_INFO); else throw new AssertionError("Unknown type: " + group.getType()); if (group.getName().isPresent()) { builder.setName(group.getName().get()); } if (group.getMembers().isPresent()) { for (SignalServiceAddress address : group.getMembers().get()) { if (address.getNumber().isPresent()) { builder.addMembersE164(address.getNumber().get()); } GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder(); if (address.getUuid().isPresent()) { memberBuilder.setUuid(address.getUuid().get().toString()); } if (address.getNumber().isPresent()) { memberBuilder.setE164(address.getNumber().get()); } builder.addMembers(memberBuilder.build()); } } if (group.getAvatar().isPresent()) { if (group.getAvatar().get().isStream()) { builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream())); } else { builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer())); } } } else { builder.setType(GroupContext.Type.DELIVER); } return builder.build(); }
Example #26
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 4 votes |
private static @Nullable Long handleGroupUpdate(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, @NonNull GroupRecord groupRecord, boolean outgoing) { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); GroupId.V1 id = GroupId.v1orThrow(group.getGroupId()); Set<RecipientId> recordMembers = new HashSet<>(groupRecord.getMembers()); Set<RecipientId> messageMembers = new HashSet<>(); for (SignalServiceAddress messageMember : group.getMembers().get()) { messageMembers.add(Recipient.externalPush(context, messageMember).getId()); } Set<RecipientId> addedMembers = new HashSet<>(messageMembers); addedMembers.removeAll(recordMembers); Set<RecipientId> missingMembers = new HashSet<>(recordMembers); missingMembers.removeAll(messageMembers); GroupContext.Builder builder = createGroupContext(group); builder.setType(GroupContext.Type.UPDATE); if (addedMembers.size() > 0) { Set<RecipientId> unionMembers = new HashSet<>(recordMembers); unionMembers.addAll(messageMembers); database.updateMembers(id, new LinkedList<>(unionMembers)); builder.clearMembers(); for (RecipientId addedMember : addedMembers) { Recipient recipient = Recipient.resolved(addedMember); if (recipient.getE164().isPresent()) { builder.addMembersE164(recipient.getE164().get()); } builder.addMembers(createMember(RecipientUtil.toSignalServiceAddress(context, recipient))); } } else { builder.clearMembers(); } if (missingMembers.size() > 0) { // TODO We should tell added and missing about each-other. } if (group.getName().isPresent() || group.getAvatar().isPresent()) { SignalServiceAttachment avatar = group.getAvatar().orNull(); database.update(id, group.getName().orNull(), avatar != null ? avatar.asPointer() : null); } if (group.getName().isPresent() && group.getName().get().equals(groupRecord.getTitle())) { builder.clearName(); } if (!groupRecord.isActive()) database.setActive(id, true); return storeMessage(context, content, group, builder.build(), outgoing); }
Example #27
Source Project: mollyim-android Author: mollyim File: GroupV1MessageProcessor.java License: GNU General Public License v3.0 | 4 votes |
private static @Nullable Long storeMessage(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) { if (group.getAvatar().isPresent()) { ApplicationDependencies.getJobManager() .add(new AvatarGroupsV1DownloadJob(GroupId.v1orThrow(group.getGroupId()))); } try { if (outgoing) { MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context); RecipientId recipientId = DatabaseFactory.getRecipientDatabase(context).getOrInsertFromGroupId(GroupId.v1orThrow(group.getGroupId())); Recipient recipient = Recipient.resolved(recipientId); OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(recipient, storage, null, content.getTimestamp(), 0, false, null, Collections.emptyList(), Collections.emptyList()); long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient); long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null); mmsDatabase.markAsSent(messageId, true); return threadId; } else { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); String body = Base64.encodeBytes(storage.toByteArray()); IncomingTextMessage incoming = new IncomingTextMessage(Recipient.externalPush(context, content.getSender()).getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerTimestamp(), body, Optional.of(GroupId.v1orThrow(group.getGroupId())), 0, content.isNeedsReceipt()); IncomingGroupUpdateMessage groupMessage = new IncomingGroupUpdateMessage(incoming, storage, body); Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage); if (insertResult.isPresent()) { ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId()); return insertResult.get().getThreadId(); } else { return null; } } } catch (MmsException e) { Log.w(TAG, e); } return null; }
Example #28
Source Project: mollyim-android Author: mollyim File: PushProcessMessageJob.java License: GNU General Public License v3.0 | 4 votes |
private boolean shouldIgnore(@Nullable SignalServiceContent content) throws BadGroupIdException { if (content == null) { Log.w(TAG, "Got a message with null content."); return true; } Recipient sender = Recipient.externalPush(context, content.getSender()); if (content.getDataMessage().isPresent()) { SignalServiceDataMessage message = content.getDataMessage().get(); Recipient conversation = getMessageDestination(content, message); if (conversation.isGroup() && conversation.isBlocked()) { return true; } else if (conversation.isGroup()) { GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); Optional<GroupId> groupId = GroupUtil.idFromGroupContext(message.getGroupContext()); if (groupId.isPresent() && groupDatabase.isUnknownGroup(groupId.get())) { return false; } boolean isTextMessage = message.getBody().isPresent(); boolean isMediaMessage = message.getAttachments().isPresent() || message.getQuote().isPresent() || message.getSharedContacts().isPresent(); boolean isExpireMessage = message.isExpirationUpdate(); boolean isGv2Message = message.isGroupV2Message(); boolean isGv2Update = message.isGroupV2Update(); boolean isContentMessage = !message.isGroupV1Update() && !isGv2Update && !isExpireMessage && (isTextMessage || isMediaMessage); boolean isGroupActive = groupId.isPresent() && groupDatabase.isActive(groupId.get()); boolean isLeaveMessage = message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1Type() == SignalServiceGroup.Type.QUIT; if (isGv2Message && !FeatureFlags.groupsV2()) { Log.i(TAG, "Ignoring GV2 message by feature flag."); return true; } return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage && !isGv2Update); } else { return sender.isBlocked(); } } else if (content.getCallMessage().isPresent() || content.getTypingMessage().isPresent()) { return sender.isBlocked(); } return false; }
Example #29
Source Project: bcm-android Author: bcmapp File: IncomingJoinedMessage.java License: GNU General Public License v3.0 | 4 votes |
public IncomingJoinedMessage(Address sender) { super(sender, 1, System.currentTimeMillis(), null, Optional.<SignalServiceGroup>absent(), 0); }
Example #30
Source Project: libsignal-service-java Author: signalapp File: SignalServiceMessageSender.java License: GNU General Public License v3.0 | 4 votes |
private GroupContext createGroupContent(SignalServiceGroup group) throws IOException { GroupContext.Builder builder = GroupContext.newBuilder(); builder.setId(ByteString.copyFrom(group.getGroupId())); if (group.getType() != SignalServiceGroup.Type.DELIVER) { if (group.getType() == SignalServiceGroup.Type.UPDATE) builder.setType(GroupContext.Type.UPDATE); else if (group.getType() == SignalServiceGroup.Type.QUIT) builder.setType(GroupContext.Type.QUIT); else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO) builder.setType(GroupContext.Type.REQUEST_INFO); else throw new AssertionError("Unknown type: " + group.getType()); if (group.getName().isPresent()) { builder.setName(group.getName().get()); } if (group.getMembers().isPresent()) { for (SignalServiceAddress address : group.getMembers().get()) { if (address.getNumber().isPresent()) { builder.addMembersE164(address.getNumber().get()); } GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder(); if (address.getUuid().isPresent()) { memberBuilder.setUuid(address.getUuid().get().toString()); } if (address.getNumber().isPresent()) { memberBuilder.setE164(address.getNumber().get()); } builder.addMembers(memberBuilder.build()); } } if (group.getAvatar().isPresent()) { if (group.getAvatar().get().isStream()) { builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream())); } else { builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer())); } } } else { builder.setType(GroupContext.Type.DELIVER); } return builder.build(); }