From 641f9ee3687768d5193940dad52c02a5f094612e Mon Sep 17 00:00:00 2001
From: Audric Ackermann <audric@loki.network>
Date: Thu, 25 Feb 2021 17:31:18 +1100
Subject: [PATCH 1/4] Fix the bug where if we leave and get added back, we get
 removed again

---
 ts/receiver/closedGroups.ts   | 4 +++-
 ts/session/group/index.ts     | 7 +++++--
 ts/session/utils/syncUtils.ts | 8 ++++----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts
index e28637d99..f97288fd9 100644
--- a/ts/receiver/closedGroups.ts
+++ b/ts/receiver/closedGroups.ts
@@ -235,6 +235,7 @@ export async function handleNewClosedGroup(
     members: members,
     admins,
     active: true,
+    weWereJustAdded: true,
   };
 
   // be sure to call this before sending the message.
@@ -509,7 +510,8 @@ async function performIfValid(
     lastJoinedTimestamp = aYearAgo;
   }
 
-  if (envelope.timestamp <= lastJoinedTimestamp) {
+  const envelopeTimestamp = _.toNumber(envelope.timestamp);
+  if (envelopeTimestamp <= lastJoinedTimestamp) {
     window.log.warn(
       'Got a group update with an older timestamp than when we joined this group last time. Dropping it.'
     );
diff --git a/ts/session/group/index.ts b/ts/session/group/index.ts
index 9bfff075d..4c2e940d6 100644
--- a/ts/session/group/index.ts
+++ b/ts/session/group/index.ts
@@ -48,6 +48,7 @@ export interface GroupInfo {
   blocked?: boolean;
   admins?: Array<string>;
   secretKey?: Uint8Array;
+  weWereJustAdded?: boolean;
 }
 
 interface UpdatableGroupState {
@@ -243,7 +244,7 @@ export function buildGroupDiff(
 }
 
 export async function updateOrCreateClosedGroup(details: GroupInfo) {
-  const { id } = details;
+  const { id, weWereJustAdded } = details;
 
   const conversation = await ConversationController.getInstance().getOrCreateAndWait(
     id,
@@ -268,7 +269,9 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) {
       updates.timestamp = updates.active_at;
     }
     updates.left = false;
-    updates.lastJoinedTimestamp = updates.active_at;
+    updates.lastJoinedTimestamp = weWereJustAdded
+      ? Date.now()
+      : updates.active_at;
   } else {
     updates.left = true;
   }
diff --git a/ts/session/utils/syncUtils.ts b/ts/session/utils/syncUtils.ts
index 5438dc86c..2ed6f0c03 100644
--- a/ts/session/utils/syncUtils.ts
+++ b/ts/session/utils/syncUtils.ts
@@ -66,8 +66,8 @@ export const forceSyncConfigurationNowIfNeeded = async (
         // tslint:disable-next-line: no-void-expression
         const callback = waitForMessageSent
           ? () => {
-            resolve(true);
-          }
+              resolve(true);
+            }
           : undefined;
         void getMessageQueue().sendSyncMessage(configMessage, callback as any);
         // either we resolve from the callback if we need to wait for it,
@@ -95,8 +95,8 @@ export const getCurrentConfigurationMessage = async (
   const openGroupsIds = convos
     .filter(c => !!c.get('active_at') && c.isPublic() && !c.get('left'))
     .map(c => c.id.substring((c.id as string).lastIndexOf('@') + 1)) as Array<
-      string
-    >;
+    string
+  >;
 
   // Filter Closed/Medium groups
   const closedGroupModels = convos.filter(

From e052a6743ac5e5cecdf2a187757dcf0e286d12fd Mon Sep 17 00:00:00 2001
From: Audric Ackermann <audric@loki.network>
Date: Mon, 1 Mar 2021 16:38:40 +1100
Subject: [PATCH 2/4] fix building of sync message from 1-to-1 convo

---
 ts/session/messages/outgoing/content/data/ChatMessage.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts
index fcd5ad6f4..8ae6330c3 100644
--- a/ts/session/messages/outgoing/content/data/ChatMessage.ts
+++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts
@@ -98,10 +98,10 @@ export class ChatMessage extends DataMessage {
   ) {
     if (
       (dataMessage as any).constructor.name !== 'DataMessage' &&
-      !(dataMessage instanceof DataMessage)
+      !(dataMessage instanceof SignalService.DataMessage)
     ) {
-      throw new Error(
-        'Tried to build a sync message from something else than a DataMessage'
+      window.log.warn(
+        'buildSyncMessage with something else than a DataMessage'
       );
     }
 

From b8a17bcd94e7800f400306b646b096202c72e329 Mon Sep 17 00:00:00 2001
From: Audric Ackermann <audric@loki.network>
Date: Mon, 1 Mar 2021 16:46:16 +1100
Subject: [PATCH 3/4] do not include lokiProfile on sync Message => we use
 ConfigMessage now

---
 .../outgoing/content/data/ChatMessage.ts       | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts
index 8ae6330c3..628bbd4c0 100644
--- a/ts/session/messages/outgoing/content/data/ChatMessage.ts
+++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts
@@ -108,23 +108,6 @@ export class ChatMessage extends DataMessage {
     if (!sentTimestamp || !isNumber(sentTimestamp)) {
       throw new Error('Tried to build a sync message without a sentTimestamp');
     }
-    // the dataMessage.profileKey is of type ByteBuffer. We need to make it a Uint8Array
-    const lokiProfile: any = {};
-    if (dataMessage.profileKey?.length) {
-      lokiProfile.profileKey = new Uint8Array(
-        (dataMessage.profileKey as any).toArrayBuffer()
-      );
-    }
-
-    if (dataMessage.profile) {
-      if (dataMessage.profile?.displayName) {
-        lokiProfile.displayName = dataMessage.profile.displayName;
-      }
-      if (dataMessage.profile?.profilePicture) {
-        lokiProfile.avatarPointer = dataMessage.profile.profilePicture;
-      }
-    }
-
     const timestamp = toNumber(sentTimestamp);
     const body = dataMessage.body || undefined;
     const attachments = (dataMessage.attachments || []).map(attachment => {
@@ -147,7 +130,6 @@ export class ChatMessage extends DataMessage {
       attachments,
       body,
       quote,
-      lokiProfile,
       preview,
       syncTarget,
     });

From 7b894b1a9030a406caa6a27ab4246ec03eddf3c4 Mon Sep 17 00:00:00 2001
From: Audric Ackermann <audric@loki.network>
Date: Tue, 2 Mar 2021 11:28:55 +1100
Subject: [PATCH 4/4] bump to v1.4.11

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index f5de4d199..c1f9c26ee 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "session-desktop",
   "productName": "Session",
   "description": "Private messaging from your desktop",
-  "version": "1.4.10",
+  "version": "1.4.11",
   "license": "GPL-3.0",
   "author": {
     "name": "Loki Project",