Skip to content

Commit

Permalink
Fix android app chat
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Sep 22, 2024
1 parent 3a50c20 commit a661419
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient
.get(url + basePath, `/api/chat/?order_id=${order.id}&offset=${lastIndex}`, {
tokenSHA256: garage.getSlot()?.tokenSHA256 ?? '',
tokenSHA256: garage.getSlot()?.getRobot()?.tokenSHA256 ?? '',
})
.then((results: any) => {
if (results != null) {
Expand Down Expand Up @@ -127,7 +127,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
const onMessage = (dataFromServer: ServerMessage): void => {
const slot = garage.getSlot();
const robot = slot?.getRobot();
if (robot && dataFromServer != null) {
if (slot && robot && dataFromServer != null) {
// If we receive an encrypted message
if (dataFromServer.message.substring(0, 27) === `-----BEGIN PGP MESSAGE-----`) {
void decryptMessage(
Expand Down Expand Up @@ -196,7 +196,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
// If input string contains '#' send unencrypted and unlogged message
else if (value.substring(0, 1) === '#') {
const { url, basePath } = federation
.getCoordinator(garage.getSlot()?.activeOrder?.shortAlias)
.getCoordinator(garage.getSlot()?.activeOrder?.shortAlias ?? '')
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient
.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ public void checkNotifications() {
JSONObject slot = (JSONObject) slots.get(robotToken);
JSONObject robots = slot.getJSONObject("robots");
JSONObject coordinatorRobot;
String shortAlias = slot.getString("activeShortAlias");
coordinatorRobot = robots.getJSONObject(shortAlias);
fetchNotifications(coordinatorRobot, shortAlias);
String shortAlias = "";
if (slot.has("activeShortAlias")) {
shortAlias = slot.getString("activeShortAlias");
} else if (slot.has("activeOrder") && !slot.isNull("activeOrder")) {
JSONObject activeOrder = slot.getJSONObject("activeOrder");
shortAlias = activeOrder.getString("shortAlias");
}
if (!shortAlias.isBlank()) {
coordinatorRobot = robots.getJSONObject(shortAlias);
fetchNotifications(coordinatorRobot, shortAlias);
}
}
} catch (JSONException | InterruptedException e) {
Log.d("NotificationsService", "Error reading garage: " + e);
Expand Down

0 comments on commit a661419

Please sign in to comment.