Skip to content

Commit

Permalink
Merge pull request #73 from papercups-io/2.1.2
Browse files Browse the repository at this point in the history
Merge fixes into main
  • Loading branch information
aguilaair authored Oct 16, 2021
2 parents 0f6fd98 + 651a907 commit c9b2a6e
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 28 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [2.1.4] - 12/09/2021.
🐛 Fixed an issue where new customer conversations would create a new ID, stopping links between conversations.

## [2.1.3] - 11/09/2021.
🐛 Fixed an issue where chats appeared as Anonymous in specific cases even if externalId was provided. (covers more cases)

## [2.1.2] - 11/09/2021.
🐛 Fixed an issue where chats appeared as Anonymous in specific cases even if externalId was provided.

## [2.1.1] - 21/08/2021.
🐛 Fixed an issue where chats are not recovered due to an API change.

## [2.1.0+1] - 18/04/2021.
🎨 Format code

Expand Down
4 changes: 4 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ class _MyHomePageState extends State<MyHomePage> {
greeting:
"Hello, have any questions or feedback? Let me know below!",
subtitle: subtitleController.text,
customer: CustomerMetadata(
email: "[email protected]",
externalId: "123",
),
),
),
),
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -183,7 +183,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand All @@ -197,7 +197,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.1.0+1"
version: "2.1.4"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -335,7 +335,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
thememode_selector:
dependency: "direct main"
description:
Expand Down
2 changes: 2 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"

#include <url_launcher_windows/url_launcher_plugin.h>
Expand Down
2 changes: 2 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down
6 changes: 4 additions & 2 deletions lib/papercups_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ class _PaperCupsWidgetState extends State<PaperCupsWidget> {
}

void setCustomer(PapercupsCustomer c, {rebuild = false}) {
_customer = c;
if (rebuild) setState(() {});
if (_customer != c) {
_customer = c;
if (rebuild) setState(() {});
}
}

void setConversation(Conversation c) {
Expand Down
11 changes: 9 additions & 2 deletions lib/utils/getCustomerDetails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Future<PapercupsCustomer> getCustomerDetails(
Function? sc, {
Client? client,
}) async {
if (c?.id != null) {
return Future.value(c);
}
if (client == null) {
client = Client();
}
Expand Down Expand Up @@ -43,8 +46,12 @@ Future<PapercupsCustomer> getCustomerDetails(
externalId: data["external_id"],
firstSeen: data["first_seen"] != null ? parseDateFromUTC(data["first_seen"]) : null,
id: data["id"],
lastSeenAt: data["last_seen_at"] != null ? parseDateFromUTC(data["last_seen_at"]) : null,
updatedAt: data["updated_at"] != null ? parseDateFromUTC(data["updated_at"]) : null,
lastSeenAt: data["last_seen_at"] != null
? parseDateFromUTC(data["last_seen_at"])
: null,
updatedAt: data["updated_at"] != null
? parseDateFromUTC(data["updated_at"])
: null,
name: data["name"],
phone: data["phone"],
);
Expand Down
18 changes: 9 additions & 9 deletions lib/utils/getCustomerDetailsFromMetadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ Future<PapercupsCustomer> getCustomerDetailsFromMetadata(
// Generating the Papercups customer data.
c = PapercupsCustomer(
id: data["customer_id"],
externalId: c == null ? null : c.externalId,
email: c == null ? null : c.email,
createdAt: c == null ? null : c.createdAt,
firstSeen: c == null ? null : c.firstSeen,
lastSeenAt: c == null ? null : c.lastSeenAt,
name: c == null ? null : c.name,
phone: c == null ? null : c.phone,
updatedAt: c == null ? null : c.updatedAt,
externalId: p.customer?.externalId,
email: p.customer?.email,
createdAt: c?.createdAt,
firstSeen: c?.firstSeen,
lastSeenAt: c?.lastSeenAt,
name: p.customer?.name,
phone: p.customer?.otherMetadata?["phoneNumber"],
updatedAt: c?.updatedAt,
);
} catch (e) {
throw (e);
}
// Function to set the client.
if(c.id != null){
if (c.id != null) {
sc(c);
}
// Closing HTTP client.
Expand Down
22 changes: 17 additions & 5 deletions lib/utils/getPastCustomerMessages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Future<Map<String, dynamic>> getPastCustomerMessages(
client = Client();
}
List<PapercupsMessage> rMsgs = [];
PapercupsCustomer newCust;

try {
// Get messages.
Expand All @@ -27,10 +28,17 @@ Future<Map<String, dynamic>> getPastCustomerMessages(
);

// JSON Decode.
var data = jsonDecode(res.body)["data"][0];
var data = jsonDecode(res.body)["data"];
try {
data = data[0];
} catch (e) {
return {
"msgs": rMsgs,
"cust": c,
};
}

// For every message generate a PapercupsMessage object and add it to the list.
data["messages"].forEach((val) {
data[0]["messages"].forEach((val) {
rMsgs.add(
PapercupsMessage(
accountId: val["account_id"],
Expand All @@ -56,7 +64,7 @@ Future<Map<String, dynamic>> getPastCustomerMessages(
});
// Get the customer details.
var customerData = data["customer"];
c = PapercupsCustomer(
newCust = PapercupsCustomer(
createdAt: parseDateFromUTC(customerData["created_at"]),
email: customerData["email"],
externalId: customerData["external_id"],
Expand All @@ -69,11 +77,15 @@ Future<Map<String, dynamic>> getPastCustomerMessages(
);
} catch (e) {
print("An error ocurred while getting past customer data.");
return {
"msgs": [],
"cust": c,
};
}
client.close();
// Return messages and customer details.
return {
"msgs": rMsgs,
"cust": c,
"cust": newCust,
};
}
8 changes: 6 additions & 2 deletions lib/utils/updateUserMetadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ Future<PapercupsCustomer?> updateUserMetadata(
externalId: data["external_id"],
firstSeen: data["first_seen"] != null ? parseDateFromUTC(data["first_seen"]) : null,
id: data["id"],
lastSeenAt: data["last_seen_at"] != null ? parseDateFromUTC(data["last_seen_at"]) : null,
updatedAt: data["updated_at"] != null ? parseDateFromUTC(data["updated_at"]) : null,
lastSeenAt: data["last_seen_at"] != null
? parseDateFromUTC(data["last_seen_at"])
: null,
updatedAt: data["updated_at"] != null
? parseDateFromUTC(data["updated_at"])
: null,
name: data["name"],
phone: data["phone"],
);
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -316,7 +316,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -531,7 +531,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
timeago:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: papercups_flutter
description: Native Flutter implementation of the papercups.io chat widget.
version: 2.1.0+1
version: 2.1.4
homepage: https://github.com/aguilaair/papercups_flutter

environment:
Expand Down

0 comments on commit c9b2a6e

Please sign in to comment.