Merge pull request #1494 from RoboSats/fix-android-app-chat

Fix android app chat
This commit is contained in:
KoalaSat 2024-09-22 17:03:10 +00:00 committed by GitHub
commit ec28fae097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -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) {
@ -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(
@ -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(

View File

@ -144,9 +144,17 @@ public class NotificationsService extends Service {
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);