private SignalServiceDataMessage createSignalServiceMessage(SignalServiceEnvelope envelope, DataMessage content) { SignalServiceGroup groupInfo = createGroupInfo(envelope, content); List <SignalServiceAttachment> attachments = new List <SignalServiceAttachment>(); bool endSession = ((content.Flags & (uint)DataMessage.Types.Flags.EndSession) != 0); bool expirationUpdate = ((content.Flags & (uint)DataMessage.Types.Flags.ExpirationTimerUpdate) != 0); foreach (AttachmentPointer pointer in content.Attachments) { attachments.Add(new SignalServiceAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.getRelay(), pointer.SizeOneofCase == AttachmentPointer.SizeOneofOneofCase.Size ? pointer.Size : 0, pointer.ThumbnailOneofCase == AttachmentPointer.ThumbnailOneofOneofCase.Thumbnail ? pointer.Thumbnail.ToByteArray() : null, pointer.DigestOneofCase == AttachmentPointer.DigestOneofOneofCase.Digest ? pointer.Digest.ToByteArray() : null, pointer.FileNameOneofCase == AttachmentPointer.FileNameOneofOneofCase.FileName ? pointer.FileName : null, pointer.FlagsOneofCase == AttachmentPointer.FlagsOneofOneofCase.Flags && (pointer.Flags & (uint)AttachmentPointer.Types.Flags.VoiceMessage) != 0)); } return(new SignalServiceDataMessage() { Timestamp = envelope.getTimestamp(), Group = groupInfo, Attachments = attachments, Body = content.Body, EndSession = endSession, ExpiresInSeconds = (int)content.ExpireTimer, ExpirationUpdate = expirationUpdate }); }
private SignalServiceGroup createGroupInfo(SignalServiceEnvelope envelope, DataMessage content) { if (!content.HasGroup) { return(null); } SignalServiceGroup.Type type; switch (content.Group.Type) { case GroupContext.Types.Type.DELIVER: type = SignalServiceGroup.Type.DELIVER; break; case GroupContext.Types.Type.UPDATE: type = SignalServiceGroup.Type.UPDATE; break; case GroupContext.Types.Type.QUIT: type = SignalServiceGroup.Type.QUIT; break; case GroupContext.Types.Type.REQUEST_INFO: type = SignalServiceGroup.Type.REQUEST_INFO; break; default: type = SignalServiceGroup.Type.UNKNOWN; break; } if (content.Group.Type != GroupContext.Types.Type.DELIVER) { String name = null; IList <String> members = null; SignalServiceAttachmentPointer avatar = null; if (content.Group.HasName) { name = content.Group.Name; } if (content.Group.MembersCount > 0) { members = content.Group.MembersList; } if (content.Group.HasAvatar) { avatar = new SignalServiceAttachmentPointer(content.Group.Avatar.Id, content.Group.Avatar.ContentType, content.Group.Avatar.Key.ToByteArray(), envelope.getRelay()); } return(new SignalServiceGroup(type, content.Group.Id.ToByteArray(), name, members, avatar)); } return(new SignalServiceGroup(content.Group.Id.ToByteArray())); }
private void handleMessage(SignalServiceEnvelope envelope, bool sendExplicitReceipt) { var worker = App.Current.Worker; long messageId = DatabaseFactory.getPushDatabase().Insert(envelope); if (sendExplicitReceipt) { worker.AddTaskActivities(new DeliveryReceiptTask(envelope.getSource(), envelope.getTimestamp(), envelope.getRelay())); } worker.AddTaskActivities(new PushDecryptTask(messageId, envelope.getSource())); }
private SignalServiceDataMessage createSignalServiceMessage(SignalServiceEnvelope envelope, DataMessage content) { SignalServiceGroup groupInfo = createGroupInfo(envelope, content); List <SignalServiceAttachment> attachments = new List <SignalServiceAttachment>(); bool endSession = ((content.Flags & (uint)DataMessage.Types.Flags.END_SESSION) != 0); bool expirationUpdate = ((content.Flags & (uint)DataMessage.Types.Flags.EXPIRATION_TIMER_UPDATE) != 0); foreach (AttachmentPointer pointer in content.AttachmentsList) { attachments.Add(new SignalServiceAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.getRelay(), pointer.HasSize ? new May <uint>(pointer.Size) : May <uint> .NoValue, pointer.HasThumbnail ? new May <byte[]>(pointer.Thumbnail.ToByteArray()) : May <byte[]> .NoValue)); } return(new SignalServiceDataMessage(envelope.getTimestamp(), groupInfo, attachments, content.Body, endSession, (int)content.ExpireTimer, expirationUpdate)); }
private SignalServiceGroup createGroupInfo(SignalServiceEnvelope envelope, DataMessage content) { if (content.GroupOneofCase == DataMessage.GroupOneofOneofCase.None) { return(null); } SignalServiceGroup.GroupType type; switch (content.Group.Type) { case GroupContext.Types.Type.Deliver: type = SignalServiceGroup.GroupType.DELIVER; break; case GroupContext.Types.Type.Update: type = SignalServiceGroup.GroupType.UPDATE; break; case GroupContext.Types.Type.Quit: type = SignalServiceGroup.GroupType.QUIT; break; case GroupContext.Types.Type.RequestInfo: type = SignalServiceGroup.GroupType.REQUEST_INFO; break; default: type = SignalServiceGroup.GroupType.UNKNOWN; break; } if (content.Group.Type != GroupContext.Types.Type.Deliver) { String name = null; IList <String> members = null; SignalServiceAttachmentPointer avatar = null; if (content.Group.NameOneofCase == GroupContext.NameOneofOneofCase.Name) { name = content.Group.Name; } if (content.Group.Members.Count > 0) { members = content.Group.Members; } if (content.Group.AvatarOneofCase == GroupContext.AvatarOneofOneofCase.Avatar) { AttachmentPointer pointer = content.Group.Avatar; avatar = new SignalServiceAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.getRelay(), pointer.Digest.ToByteArray(), null, false); } return(new SignalServiceGroup() { Type = type, GroupId = content.Group.Id.ToByteArray(), Name = name, Members = members, Avatar = avatar }); } return(new SignalServiceGroup() { GroupId = content.Group.Id.ToByteArray(), Type = type }); }