Skip to content

Commit a620b72

Browse files
authored
version 2.7.0
1 parent 9177689 commit a620b72

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

EasyInsta/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ dependencies {
1212
implementation files('libs/instagram4j-realtime.jar')
1313
implementation 'org.jetbrains:annotations:15.0'
1414
implementation 'com.github.instagram4j:instagram4j:2.0.7'
15-
api 'com.github.ErrorxCode:AsyncTask:1.0'
16-
}
15+
api project(':AsyncTask')
16+
}

EasyInsta/src/main/java/com/xcoder/easyinsta/Instagram.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ else if (e.getMessage().contains("challenge"))
136136

137137

138138
/**
139-
* Returns pre-logged in instagram instance from the cache. If no cache exist, It first perform login & then cache it so it can be used in future.
139+
* Returns pre-logged in instagram instance from the cache. If no cache exist, It first perform login and then cache it so it can be used in future.
140140
*
141141
* @param dir The cache directory of the application.
142142
* @param username Username of the account
@@ -240,7 +240,7 @@ public Actions actions() {
240240

241241

242242
/**
243-
* This class includes all the methods related to chat & messaging.
243+
* This class includes all the methods related to chat and messaging.
244244
*/
245245
public final class Direct {
246246

@@ -250,6 +250,7 @@ public final class Direct {
250250
* Sends a direct message to a user
251251
*
252252
* @param message The text to send.
253+
* @param username The user to send the message to.
253254
* @return A {@link AsyncTask} indication success or failure of the method
254255
*/
255256
public AsyncTask<Void> directMessage(@NotNull String username,@NotNull String message) {
@@ -266,6 +267,7 @@ public AsyncTask<Void> directMessage(@NotNull String username,@NotNull String me
266267
* Sends a photo to the user.
267268
*
268269
* @param photo The photo to send.
270+
* @param username The user to send the message to.
269271
* @return A {@link AsyncTask} indication success or failure of the request
270272
*/
271273
public AsyncTask<Void> directMessage(@NotNull String username,@NotNull File photo) {
@@ -282,7 +284,7 @@ public AsyncTask<Void> directMessage(@NotNull String username,@NotNull File phot
282284

283285
/**
284286
* Marks message as seen that was sent by the username.
285-
*
287+
* @param username The user to see the message of.
286288
* @return A {@link AsyncTask} indication success or failure of the request
287289
*/
288290
@NotNull
@@ -299,6 +301,7 @@ public AsyncTask<Void> seeMessage(@NotNull String username) {
299301
* Retrieve messages from a particular chat from last till number specified.
300302
*
301303
* @param howMany The number of messages to get. (including recipient chat). 0 for all
304+
* @param username The user to get the message from.
302305
* @param listener A listener for tracking progress. only works when count > 20
303306
* @return A {@link AsyncTask} holding list of messages.
304307
* @throws IllegalArgumentException if howMany is negative.
@@ -320,7 +323,7 @@ public AsyncTask<List<String>> getChatMessages(@NotNull String username,int howM
320323

321324
/**
322325
* Retrieve messages from a particular chat from a particular message till last.
323-
*
326+
* @param username The user to get the message from.
324327
* @param fromMessage The message from where to start fetching messages. This is case-sensitive
325328
* @param frequency If 'fromMessage' is occurred multiple time, then pass the no. from where to consider.
326329
* For example, To retrieve messages from 'hey' and if there are 3 more same messages (exact equal) like 'hey'
@@ -353,7 +356,7 @@ public AsyncTask<List<String>> getChatMessagesFrom(@NotNull String username,@Not
353356
* @return A {@link AsyncTask} indication success or failure of the request
354357
*/
355358
@NotNull
356-
public AsyncTask<Void> groupMessage(@NotNull String username,@NotNull String message, @NotNull String adminUsername) {
359+
public AsyncTask<Void> groupMessage(@NotNull String message, @NotNull String adminUsername) {
357360
return AsyncTask.callAsync(() -> {
358361
List<IGThread> threads = client.sendRequest(new DirectInboxRequest()).get().getInbox().getThreads();
359362
Long pk = client.actions().users().findByUsername(adminUsername).get().getUser().getPk();
@@ -377,7 +380,7 @@ public AsyncTask<Void> groupMessage(@NotNull String username,@NotNull String mes
377380
* @return A {@link AsyncTask} indication success or failure of the request
378381
*/
379382
@NotNull
380-
private AsyncTask<Void> createGroup(@NotNull String username,@NotNull String groupName, @NotNull String... usernames) {
383+
private AsyncTask<Void> createGroup(@NotNull String groupName, @NotNull String... usernames) {
381384
String[] pks = new String[usernames.length];
382385
return AsyncTask.callAsync(() -> {
383386
try {
@@ -423,11 +426,11 @@ public void spamDM(@NotNull String username,int count, @NotNull String[] message
423426
* @param messages list of String containing messages to sent. a random message picked will be sent from this list.
424427
* @param callback Callback indication success and failure of each message.
425428
*/
426-
public void spamGroup(@NotNull String username,int count, @NotNull String adminUsername, @NotNull String[] messages, @NotNull OnMessageActionCallback callback) {
429+
public void spamGroup(int count, @NotNull String adminUsername, @NotNull String[] messages, @NotNull OnMessageActionCallback callback) {
427430
for (int i = 0; i < count; i++) {
428431
String message = messages[new Random().nextInt(messages.length)];
429432
callback.onProgress(i * 100 / count);
430-
groupMessage(username,message,adminUsername).setOnCompleteCallback(task -> {
433+
groupMessage(message,adminUsername).setOnCompleteCallback(task -> {
431434
if (task.isSuccessful)
432435
callback.onSuccess(message);
433436
else
@@ -439,7 +442,7 @@ public void spamGroup(@NotNull String username,int count, @NotNull String adminU
439442

440443
/**
441444
* Deletes the messages from the last till the particular number.
442-
*
445+
* @param username The user to to delete messages from.
443446
* @param howMany The no. of messages (including recipient message) to delete. For example,
444447
* if there are last 2 message from him/her and then 3 messages from you,
445448
* so you have to pass 5 here to delete your 3 messages. Pass 0 to delete all.
@@ -462,6 +465,13 @@ public void deleteMessages(@NotNull String username,int howMany, @NotNull OnMess
462465
}
463466
}
464467

468+
/**
469+
* Starts deleting the messages from the exact 'message' that was sent bu you.
470+
* @param username The user to to delete messages from.
471+
* @param fromMessage The message to start deleting from.
472+
* @param frequency if the 'fromMessage' occurred more then 1 time, pass the number from where to consider. Otherwise pass 0.
473+
* @param callback The callback indication success,failure and progress of the operation.
474+
*/
465475
public void deleteMessagesFrom(@NotNull String username,@NotNull String fromMessage, int frequency, @Nullable OnMessageActionCallback callback) {
466476
callback = callback == null ? new OnMessageActionCallback() {
467477
@Override
@@ -493,6 +503,10 @@ public void onProgress(int percentage) {
493503
}
494504
}
495505

506+
/**
507+
* Starts listening for new messages.
508+
* @param listener The listener to call when new messages are received.
509+
*/
496510
public void attachNotificationListener(@NotNull OnNotificationListener listener) {
497511
IGRealtimeClient realtimeClient = new IGRealtimeClient(client, packet -> {
498512
try {
@@ -518,6 +532,10 @@ public void attachNotificationListener(@NotNull OnNotificationListener listener)
518532
thread.start();
519533
}
520534

535+
/**
536+
* Stops listening for new messages.
537+
* @throws NullPointerException if the listener was never attached.
538+
*/
521539
public void detectNotificationListener() {
522540
thread.stop();
523541
}
@@ -558,7 +576,7 @@ public AsyncTask<Void> setBio(@NotNull String bio) {
558576

559577
/**
560578
* Scraps 100 followers of the account associated with the username. Empty list if none found but Never null.
561-
*
579+
* @param username The user to get the followers from.
562580
* @return A {@link AsyncTask} holding list of the followers.
563581
*/
564582
public @NotNull
@@ -569,7 +587,7 @@ AsyncTask<List<String>> getFollowers(@NotNull String username) {
569587

570588
/**
571589
* Scraps 100 followings of the account associated with the provided username. Empty list if none found but Never null.
572-
*
590+
* @param username The user to get the followings from.
573591
* @return A {@link AsyncTask} holding list of the followings.
574592
*/
575593
public AsyncTask<List<String>> getFollowings(@NotNull String username) {
@@ -579,10 +597,9 @@ public AsyncTask<List<String>> getFollowings(@NotNull String username) {
579597

580598
/**
581599
* Gets the pending follow requests of yours.
582-
*
583600
* @return A {@link AsyncTask} holding usernames of the requests.
584601
*/
585-
public AsyncTask<List<String>> getFollowRequests(@NotNull String username) {
602+
public AsyncTask<List<String>> getFollowRequests() {
586603
return AsyncTask.callAsync(() -> {
587604
List<String> usernames = new ArrayList<>();
588605
FeedUsersResponse feedUsersResponse = client.sendRequest(new FriendshipsPendingRequest()).get(5, TimeUnit.SECONDS);
@@ -596,7 +613,7 @@ public AsyncTask<List<String>> getFollowRequests(@NotNull String username) {
596613

597614
/**
598615
* Gets the bio of the account associated with the provided username.
599-
*
616+
* @param username The user to get the bio from.
600617
* @return A {@link AsyncTask} holding bio of the user.
601618
*/
602619
public AsyncTask<String> getBio(@NotNull String username) {
@@ -606,7 +623,7 @@ public AsyncTask<String> getBio(@NotNull String username) {
606623

607624
/**
608625
* Gets the profile photo link of the account associated with the username provided.
609-
*
626+
* @param username The user to get the DP from.
610627
* @return A {@link AsyncTask} holding url of profile picture of the user.
611628
*/
612629
public AsyncTask<String> getProfilePicUrl(@NotNull String username) {
@@ -616,7 +633,7 @@ public AsyncTask<String> getProfilePicUrl(@NotNull String username) {
616633

617634
/**
618635
* Gets the follower count of the account associated with the username.
619-
*
636+
* @param username The user to get the followers from.
620637
* @return A {@link AsyncTask} holding number of followers of the user.
621638
*/
622639
public AsyncTask<Integer> getFollowersCount(@NotNull String username) {
@@ -626,7 +643,7 @@ public AsyncTask<Integer> getFollowersCount(@NotNull String username) {
626643

627644
/**
628645
* Gets the followings count of the account associated with the username provided.
629-
*
646+
* @param username The user to get the followings from.
630647
* @return A {@link AsyncTask} holding number of followings of the user.
631648
*/
632649
public AsyncTask<Integer> getFollowingsCount(@NotNull String username) {
@@ -636,7 +653,7 @@ public AsyncTask<Integer> getFollowingsCount(@NotNull String username) {
636653

637654
/**
638655
* Gets the post count of the account associated with the username provided.
639-
*
656+
* @param username The user to get the posts count from.
640657
* @return A {@link AsyncTask} holding number of posts of the user.
641658
*/
642659
public AsyncTask<Integer> getPostCount(@NotNull String username) {

EasyInsta/src/main/java/com/xcoder/easyinsta/Message.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
import com.github.instagram4j.instagram4j.IGClient;
44
import com.github.instagram4j.instagram4j.requests.direct.DirectThreadsBroadcastRequest;
5+
import com.xcoder.easyinsta.interfaces.OnNotificationListener;
6+
import com.xcoder.easyinsta.interfaces.OnProgressListener;
7+
import com.xcoder.tasks.AsyncTask;
58

9+
import org.jetbrains.annotations.NotNull;
610
import org.jetbrains.annotations.Nullable;
711

12+
import java.util.List;
813
import java.util.concurrent.ExecutionException;
914
import java.util.concurrent.TimeUnit;
1015
import java.util.concurrent.TimeoutException;
1116

17+
/**
18+
* Message that is received when a new direct message is received. This class contains info about the new message.
19+
*/
1220
public final class Message {
1321
private final IGClient client;
1422
public final String text;
@@ -29,7 +37,7 @@ public void reply(String message) {
2937
}
3038

3139
@Nullable
32-
public String getSenderUsername(){
40+
public String getSenderUsername() {
3341
try {
3442
return client.actions().users().info(userId).get(5, TimeUnit.SECONDS).getUsername();
3543
} catch (InterruptedException | ExecutionException | TimeoutException e) {

EasyInsta/src/main/java/com/xcoder/easyinsta/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.concurrent.TimeoutException;
3232
import java.util.stream.Collectors;
3333

34-
public class Utils {
34+
class Utils {
3535
private static IGClient client;
3636

3737

0 commit comments

Comments
 (0)