Merge branch 'master' into develop-1.0.15

This commit is contained in:
JW
2024-01-05 17:07:20 +01:00
4 changed files with 21 additions and 37 deletions

View File

@@ -28,15 +28,10 @@ import lombok.Getter;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class Picture { public class Picture {
@Getter @Getter
@@ -49,7 +44,6 @@ public class Picture {
} }
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) { public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
var index = profilePicture.getUrlListCount() - 1; var index = profilePicture.getUrlListCount() - 1;
if (index < 0) { if (index < 0) {
return new Picture(""); return new Picture("");
@@ -74,12 +68,11 @@ public class Picture {
return CompletableFuture.supplyAsync(this::downloadImage); return CompletableFuture.supplyAsync(this::downloadImage);
} }
private BufferedImage download(String urlString) private BufferedImage download(String urlString) {
{ if (urlString.isEmpty()) {
if(urlString.isEmpty())
{
return null; return null;
} }
var baos = new ByteArrayOutputStream(); var baos = new ByteArrayOutputStream();
try (var is = new URL(urlString).openStream()) { try (var is = new URL(urlString).openStream()) {
var byteChunk = new byte[4096]; var byteChunk = new byte[4096];
@@ -103,4 +96,9 @@ public class Picture {
public static Picture Empty() { public static Picture Empty() {
return new Picture(""); return new Picture("");
} }
}
@Override
public String toString() {
return "Picture{link='" + link + "', image=" + image + "}";
}
}

View File

@@ -37,6 +37,4 @@ public class Badge {
public static Badge empty() { public static Badge empty() {
return new Badge(); return new Badge();
} }
}
}

View File

@@ -43,13 +43,12 @@ public class User {
private long followers; private long followers;
private List<Badge> badges; private List<Badge> badges;
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
private Set<UserAttribute> attributes; private final Set<UserAttribute> attributes = new HashSet<>();
public List<UserAttribute> getAttributes() { public List<UserAttribute> getAttributes() {
return attributes.stream().toList(); return attributes.stream().toList();
} }
public boolean hasAttribute(UserAttribute userFlag) { public boolean hasAttribute(UserAttribute userFlag) {
return attributes.contains(userFlag); return attributes.contains(userFlag);
} }
@@ -106,7 +105,6 @@ public class User {
this.following = following; this.following = following;
this.followers = followers; this.followers = followers;
this.badges = badges; this.badges = badges;
this.attributes = new HashSet<>();
} }
public User(Long id, public User(Long id,
@@ -123,14 +121,12 @@ public class User {
this.following = following; this.following = following;
this.followers = followers; this.followers = followers;
this.badges = badges; this.badges = badges;
this.attributes = new HashSet<>();
} }
public User(Long userId, public User(Long userId,
String nickName) { String nickName) {
this.id = userId; this.id = userId;
this.name = nickName; this.name = nickName;
this.attributes = new HashSet<>();
} }
public User(Long userId, public User(Long userId,
@@ -213,4 +209,4 @@ public class User {
0, 0,
List.of(Badge.empty())); List.of(Badge.empty()));
} }
} }

View File

@@ -22,14 +22,12 @@
*/ */
package io.github.jwdeveloper.tiktok.gifts; package io.github.jwdeveloper.tiktok.gifts;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.data.models.Picture; import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException; import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import io.github.jwdeveloper.tiktok.live.GiftManager; import io.github.jwdeveloper.tiktok.live.GiftManager;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -89,23 +87,17 @@ public class TikTokGiftManager implements GiftManager {
} }
public Gift findById(int giftId) { public Gift findById(int giftId) {
if (!indexById.containsKey(giftId)) { Gift gift = indexById.get(giftId);
return Gift.UNDEFINED; return gift == null ? Gift.UNDEFINED : gift;
}
return indexById.get(giftId);
} }
public Gift findByName(String giftName) { public Gift findByName(String giftName) {
if (!indexByName.containsKey(giftName)) { Gift gift = indexByName.get(giftName);
return Gift.UNDEFINED; return gift == null ? Gift.UNDEFINED : gift;
}
return indexByName.get(giftName);
} }
@Override @Override
public List<Gift> getGifts() public List<Gift> getGifts() {
{
return indexById.values().stream().toList(); return indexById.values().stream().toList();
} }
}
}