Skip to content

Commit

Permalink
Additional logging for writing settings(#59), WIP: investigating prob…
Browse files Browse the repository at this point in the history
…lem with HEAD request in SSO API
  • Loading branch information
0xf104a committed Nov 10, 2023
1 parent 4e72dd7 commit fa249bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void onConnected() {

@Override
public void onError(Exception ex) {
Log.e(TAG, "Exception in Nextcloud API");
ex.printStackTrace();
}
};
Expand All @@ -68,7 +69,8 @@ public JSONObject getNotifications(PollUpdateListener service) {
.build();
StringBuilder buffer = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(API.performNetworkRequest(request)));
BufferedReader in = new BufferedReader(
new InputStreamReader(API.performNetworkRequestV2(request).getBody()));
String line;
while ((line = in.readLine()) != null) {
buffer.append(line);
Expand Down Expand Up @@ -170,11 +172,13 @@ public void sendAction(String link, String method) throws Exception {

@Override
public boolean checkNewNotifications() throws Exception {
NextcloudRequest request = new NextcloudRequest.Builder().setMethod("HEAD")
NextcloudRequest request = new NextcloudRequest.Builder().setMethod("GET")
.setUrl(Uri.encode("/ocs/v2.php/apps/notifications/api/v2/notifications", "/"))
.build();
Response response = API.performNetworkRequestV2(request);
String lastEtag = Objects.requireNonNull(response.getPlainHeader("ETag")).toString();
String lastEtag = Objects.requireNonNull(response.getPlainHeader("ETag")).getValue();
Log.d(TAG, "lastETag=" + lastEtag);
Log.d(TAG, "mETag=" + mETag);
if(!lastEtag.equals(mETag)){
Log.d(TAG, "New notifications found");
mETag = lastEtag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class PollTask extends AsyncTask<NotificationService, Void, JSONObject> {
private static final String TAG = "NotificationService.PollTask";
@Override
protected JSONObject doInBackground(NotificationService... services) {
Log.d(TAG, "Checking notifications");
NextcloudAbstractAPI api = services[0].getAPI();
try {
if(api.checkNewNotifications()) {
boolean hasNotifications = api.checkNewNotifications();
if(hasNotifications) {
return api.getNotifications(services[0]);
}
} catch (Exception e) {
Expand Down

0 comments on commit fa249bb

Please sign in to comment.