private long createPendingDate() {
   long res = im.actor.runtime.Runtime.getCurrentSyncedTime();
   if (lastSendDate >= res) {
     res = lastSendDate + 1;
   }
   lastSendDate = res;
   return res;
 }
Esempio n. 2
0
 private void notifyChange() {
   Runtime.postToMainThread(
       () -> {
         for (ModelChangedListener<UserVM> l : listeners) {
           l.onChanged(UserVM.this);
         }
       });
 }
Esempio n. 3
0
public class MTUids {

  private static final AtomicLongCompat NEXT_ID = im.actor.runtime.Runtime.createAtomicLong(1);

  public static long nextId() {
    return NEXT_ID.getAndIncrement();
  }
}
Esempio n. 4
0
  private void reportProgress(float progress) {
    if (isCompleted) {
      return;
    }

    if (progress > currentProgress) {
      currentProgress = progress;
    }

    if (notifyCancellable != null) {
      notifyCancellable.cancel();
      notifyCancellable = null;
    }

    long delta = im.actor.runtime.Runtime.getActorTime() - lastNotifyDate;
    if (delta > NOTIFY_THROTTLE) {
      lastNotifyDate = im.actor.runtime.Runtime.getActorTime();
      performReportProgress();
    } else {
      notifyCancellable = schedule((Runnable) () -> performReportProgress(), delta);
    }
  }
Esempio n. 5
0
  public void requestSms(
      String phone, final JsAuthSuccessClosure success, final JsAuthErrorClosure error) {
    try {
      long res = Long.parseLong(phone);
      messenger
          .requestStartPhoneAuth(res)
          .start(
              new CommandCallback<AuthState>() {
                @Override
                public void onResult(AuthState res) {
                  success.onResult(Enums.convert(res));
                }

                @Override
                public void onError(Exception e) {
                  String tag = "INTERNAL_ERROR";
                  String message = "Internal error";
                  boolean canTryAgain = false;
                  if (e instanceof RpcException) {
                    tag = ((RpcException) e).getTag();
                    message = e.getMessage();
                    canTryAgain = ((RpcException) e).isCanTryAgain();
                  }
                  error.onError(tag, message, canTryAgain, getAuthState());
                }
              });
    } catch (Exception e) {
      Log.e(TAG, e);
      im.actor.runtime.Runtime.postToMainThread(
          new Runnable() {
            @Override
            public void run() {
              error.onError("PHONE_NUMBER_INVALID", "Invalid phone number", false, getAuthState());
            }
          });
    }
  }
Esempio n. 6
0
  public void sendCode(
      String code, final JsAuthSuccessClosure success, final JsAuthErrorClosure error) {
    try {
      messenger
          .validateCode(code)
          .start(
              new CommandCallback<AuthState>() {
                @Override
                public void onResult(AuthState res) {
                  success.onResult(Enums.convert(res));
                }

                @Override
                public void onError(Exception e) {
                  String tag = "INTERNAL_ERROR";
                  String message = "Internal error";
                  boolean canTryAgain = false;
                  if (e instanceof RpcException) {
                    tag = ((RpcException) e).getTag();
                    message = e.getMessage();
                    canTryAgain = ((RpcException) e).isCanTryAgain();
                  }
                  error.onError(tag, message, canTryAgain, getAuthState());
                }
              });
    } catch (Exception e) {
      e.printStackTrace();
      im.actor.runtime.Runtime.postToMainThread(
          new Runnable() {
            @Override
            public void run() {
              error.onError("PHONE_CODE_INVALID", "Invalid code number", false, getAuthState());
            }
          });
    }
  }
  private void performSendContent(final Peer peer, final long rid, AbsContent content) {
    WakeLock wakeLock = im.actor.runtime.Runtime.makeWakeLock();

    ApiMessage message;
    if (content instanceof TextContent) {
      message =
          new ApiTextMessage(
              ((TextContent) content).getText(),
              ((TextContent) content).getMentions(),
              ((TextContent) content).getTextMessageEx());
    } else if (content instanceof DocumentContent) {
      DocumentContent documentContent = (DocumentContent) content;

      FileRemoteSource source = (FileRemoteSource) documentContent.getSource();

      ApiDocumentEx documentEx = null;

      if (content instanceof PhotoContent) {
        PhotoContent photoContent = (PhotoContent) content;
        documentEx = new ApiDocumentExPhoto(photoContent.getW(), photoContent.getH());
      } else if (content instanceof VideoContent) {
        VideoContent videoContent = (VideoContent) content;
        documentEx =
            new ApiDocumentExVideo(
                videoContent.getW(), videoContent.getH(), videoContent.getDuration());
      } else if (content instanceof AnimationContent) {
        AnimationContent animationContent = (AnimationContent) content;
        documentEx = new ApiDocumentExAnimation(animationContent.getW(), animationContent.getH());
      } else if (content instanceof VoiceContent) {
        VoiceContent voiceContent = (VoiceContent) content;
        documentEx = new ApiDocumentExVoice(voiceContent.getDuration());
      }

      ApiFastThumb fastThumb = null;
      if (documentContent.getFastThumb() != null) {
        fastThumb =
            new ApiFastThumb(
                documentContent.getFastThumb().getW(),
                documentContent.getFastThumb().getH(),
                documentContent.getFastThumb().getImage());
      }

      message =
          new ApiDocumentMessage(
              source.getFileReference().getFileId(),
              source.getFileReference().getAccessHash(),
              source.getFileReference().getFileSize(),
              source.getFileReference().getFileName(),
              documentContent.getMimeType(),
              fastThumb,
              documentEx);
    } else if (content instanceof LocationContent) {
      message = new ApiJsonMessage(((LocationContent) content).getRawJson());
    } else if (content instanceof ContactContent) {
      message = new ApiJsonMessage(((ContactContent) content).getRawJson());
    } else if (content instanceof JsonContent) {
      message = new ApiJsonMessage(((JsonContent) content).getRawJson());
    } else if (content instanceof StickerContent) {
      message = ((ContentRemoteContainer) content.getContentContainer()).getMessage();
    } else {
      return;
    }

    performSendApiContent(peer, rid, message, wakeLock);
  }
 private void performUploadFile(long rid, String descriptor, String fileName) {
   fileUplaodingWakeLocks.put(rid, Runtime.makeWakeLock());
   context().getFilesModule().requestUpload(rid, descriptor, fileName, self());
 }