This commit is contained in:
Andrea Cavalli 2021-01-10 00:08:30 +01:00
parent a258991e83
commit f1642713d6
4 changed files with 40 additions and 19 deletions

View File

@ -52,7 +52,7 @@
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlib-session-container</artifactId>
<version>4.0.22</version>
<version>4.2.4</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>

View File

@ -8,8 +8,6 @@ import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import com.hazelcast.cp.internal.util.Tuple2;
import com.hazelcast.cp.internal.util.Tuple3;
import it.tdlight.jni.TdApi;
import it.tdlight.jni.TdApi.AuthorizationStateClosed;
import it.tdlight.jni.TdApi.AuthorizationStateClosing;
@ -53,6 +51,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import reactor.util.function.Tuples;
public class TransferServiceImpl implements TransferService {
@ -379,11 +378,11 @@ public class TransferServiceImpl implements TransferService {
return Mono.empty();
}))
.collect(Collectors.toSet())
.map(transferDestClients -> Tuple2.of(transferSourceClients, transferDestClients));
.map(transferDestClients -> Tuples.of(transferSourceClients, transferDestClients));
})
.map(clientsTuple -> {
var sourceClients = clientsTuple.element1;
var destClients = clientsTuple.element2;
var sourceClients = clientsTuple.getT1();
var destClients = clientsTuple.getT2();
App.getLogService().append(Level.INFO, "Found source userbots: " + sourceClients.stream().map(TransferClient::toString).collect(Collectors.joining(", ")));
App.getLogService().append(Level.INFO, "Found destination userbots: " + destClients.stream().map(TransferClient::toString).collect(Collectors.joining(", ")));
var chosenClients = new HashSet<TransferClient>(sourceClients);
@ -422,7 +421,7 @@ public class TransferServiceImpl implements TransferService {
return new Exception("Error while obtaining source group members: " + error.getLocalizedMessage(), error);
})
.subscribeOn(Schedulers.boundedElastic())
.map(members -> Tuple2.of(clients, members));
.map(members -> Tuples.of(clients, members));
})
// Finished getting the list of members of the source group
@ -432,8 +431,8 @@ public class TransferServiceImpl implements TransferService {
.then(percentageConsumer.apply(10)).thenReturn(context);
})
.flatMap(context -> {
var clients = context.element1;
var unresolvedUsers = context.element2;
var clients = context.getT1();
var unresolvedUsers = context.getT2();
return Flux
.fromIterable(clients)
.flatMap(client -> Flux
@ -448,7 +447,7 @@ public class TransferServiceImpl implements TransferService {
.collect(Collectors.toSet())
)
.last()
.map(resolvedUsers -> Tuple2.of(clients, resolvedUsers));
.map(resolvedUsers -> Tuples.of(clients, resolvedUsers));
})
// Finished resolving users
@ -458,8 +457,8 @@ public class TransferServiceImpl implements TransferService {
.then(percentageConsumer.apply(15)).thenReturn(context);
})
.flatMap(context -> {
var clients = context.element1;
var unfilteredUsers = context.element2;
var clients = context.getT1();
var unfilteredUsers = context.getT2();
return Flux
.fromIterable(unfilteredUsers)
.<User>flatMap(user -> {
@ -498,7 +497,7 @@ public class TransferServiceImpl implements TransferService {
.thenReturn(user);
})
.collect(Collectors.toSet())
.map(resolvedUsers -> Tuple3.of(clients, resolvedUsers, unfilteredUsers.size()));
.map(resolvedUsers -> Tuples.of(clients, resolvedUsers, unfilteredUsers.size()));
})
// Finished filtering unsuitable users
@ -508,9 +507,9 @@ public class TransferServiceImpl implements TransferService {
.then(percentageConsumer.apply(20)).thenReturn(context);
})
.flatMap(context -> {
var clients = context.element1;
var users = context.element2;
var totalUsersCount = context.element3;
var clients = context.getT1();
var users = context.getT2();
var totalUsersCount = context.getT3();
var client = clients.stream().skip(ThreadLocalRandom.current().nextInt(clients.size())).findFirst().orElseThrow();
AtomicInteger processedUsersStats = new AtomicInteger(0);
return Flux
@ -592,13 +591,13 @@ public class TransferServiceImpl implements TransferService {
}
})
.collect(Collectors.toSet())
.map(resolvedUsers -> Tuple3.of(clients, resolvedUsers, totalUsersCount));
.map(resolvedUsers -> Tuples.of(clients, resolvedUsers, totalUsersCount));
})
// Finished transferring users
.doOnNext(context -> {
App.getLogService().append(Level.INFO, "Users added. Added " + transferredSuccessfullyUsersStats.get() + "/" + context.element3 + " users");
App.getLogService().append(Level.INFO, "Users added. Added " + transferredSuccessfullyUsersStats.get() + "/" + context.getT3() + " users");
})
.then(percentageConsumer.apply(100))

View File

@ -18,3 +18,26 @@ public enum UserStatusType {
ADD_TOO_MANY_REQUESTS,
UNKNOWN
}
/*
Possible errors
Code Type Description
400 BOTS_TOO_MUCH There are too many bots in this chat/channel
400 BOT_GROUPS_BLOCKED This bot can't be added to groups
400 CHANNEL_INVALID The provided channel is invalid
400 CHANNEL_PRIVATE You haven't joined this channel/supergroup
400 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this
400 CHAT_INVALID Invalid chat
403 CHAT_WRITE_FORBIDDEN You can't write in this chat
400 INPUT_USER_DEACTIVATED The specified user was deleted
400 MSG_ID_INVALID Invalid message ID provided
400 USERS_TOO_MUCH The maximum number of users has been exceeded (to create a chat, for example)
400 USER_BANNED_IN_CHANNEL You're banned from sending messages in supergroups/channels
400 USER_BLOCKED User blocked
400 USER_BOT Bots can only be admins in channels.
403 USER_CHANNELS_TOO_MUCH One of the users you tried to add is already in too many channels/supergroups
400 USER_ID_INVALID The provided user ID is invalid
400 USER_KICKED This user was kicked from this supergroup/channel
400 USER_NOT_MUTUAL_CONTACT The provided user is not a mutual contact
403 USER_PRIVACY_RESTRICTED The user's privacy settings do not allow you to do this
*/

@ -1 +0,0 @@
Subproject commit a04010d72b8c8eb4165697f07c3da685b1a88a50