Skip to content

Commit

Permalink
获取收藏列表时,只获取自己收藏的
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Nov 4, 2020
1 parent 1592851 commit 31ce105
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/main/java/cn/wildfirechat/app/ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import cn.wildfirechat.sdk.*;
import cn.wildfirechat.sdk.model.IMResult;
import com.aliyun.oss.*;
import com.aliyun.oss.model.CopyObjectResult;
import com.aliyun.oss.model.PutObjectRequest;
import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
Expand Down Expand Up @@ -356,9 +355,9 @@ private void sendPcLoginRequestMessage(String fromUser, String toUser, int platf
payload.setPushContent("Web端登录请求");
} else if (platform == ProtoConstants.Platform.Platform_OSX) {
payload.setPushContent("Mac 端登录请求");
} else if(platform == ProtoConstants.Platform.Platform_LINUX) {
} else if (platform == ProtoConstants.Platform.Platform_LINUX) {
payload.setPushContent("Linux 端登录请求");
} else if(platform == ProtoConstants.Platform.Platform_Windows) {
} else if (platform == ProtoConstants.Platform.Platform_Windows) {
payload.setPushContent("Windows 端登录请求");
} else {
payload.setPushContent("PC 端登录请求");
Expand Down Expand Up @@ -413,7 +412,7 @@ private void sendTextMessage(String fromUser, String toUser, String text) {
public RestResult createPcSession(CreateSessionRequest request) {
String userId = request.getUserId();
// pc端切换登录用户时,还会带上之前的cookie,通过请求里面是否带有userId来判断是否是切换到新用户
if(request.getFlag() == 1 && !StringUtils.isEmpty(userId)){
if (request.getFlag() == 1 && !StringUtils.isEmpty(userId)) {
Subject subject = SecurityUtils.getSubject();
userId = (String) subject.getSession().getAttribute("userId");
}
Expand Down Expand Up @@ -460,7 +459,7 @@ public RestResult loginWithSession(String token) {
return RestResult.result(ERROR_SESSION_NOT_VERIFIED, response);
} else if (session.getStatus() == Session_Pre_Verify) {
return RestResult.error(ERROR_SESSION_NOT_VERIFIED);
} else if(session.getStatus() == Session_Canceled) {
} else if (session.getStatus() == Session_Canceled) {
return RestResult.error(ERROR_SESSION_CANCELED);
}
// comment end
Expand Down Expand Up @@ -893,7 +892,7 @@ public RestResult uploadMedia(int mediaType, MultipartFile file) {
}
// 关闭OSSClient。
ossClient.shutdown();
} else if(ossType == 3) {
} else if (ossType == 3) {
try {
// 使用MinIO服务的URL,端口,Access key和Secret key创建一个MinioClient对象
// MinioClient minioClient = new MinioClient("https://play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
Expand All @@ -902,7 +901,7 @@ public RestResult uploadMedia(int mediaType, MultipartFile file) {
// 使用putObject上传一个文件到存储桶中。
// minioClient.putObject("asiatrip",fileName, localFile.getAbsolutePath(), new PutObjectOptions(PutObjectOptions.MAX_OBJECT_SIZE, PutObjectOptions.MIN_MULTIPART_SIZE));
minioClient.putObject(bucket, fileName, localFile.getAbsolutePath(), new PutObjectOptions(file.getSize(), 0));
} catch(MinioException e) {
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
return RestResult.error(ERROR_SERVER_ERROR);
} catch (NoSuchAlgorithmException | IOException | InvalidKeyException e) {
Expand Down Expand Up @@ -1005,7 +1004,10 @@ public RestResult removeFavoriteItems(long id) {

@Override
public RestResult getFavoriteItems(long id, int count) {
List<FavoriteItem> favs = favoriteRepository.loadFav(id, count);
Subject subject = SecurityUtils.getSubject();
String userId = (String) subject.getSession().getAttribute("userId");

List<FavoriteItem> favs = favoriteRepository.loadFav(userId, id, count);
LoadFavoriteResponse response = new LoadFavoriteResponse();
response.items = favs;
response.hasMore = favs.size() == count;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/cn/wildfirechat/app/jpa/FavoriteItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import javax.persistence.*;

@Entity
@Table(name = "t_favorites", indexes = {@Index(columnList = "userId, type")})
@Table(name = "t_favorites", indexes = {@Index(columnList = "user_id, type")})
public class FavoriteItem {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
public Long id;

@Column(name = "user_id")
public String userId;

@Column(name = "type")
public int type;

@Column(name = "timestamp")
public long timestamp;

@Column(name = "conv_type")
Expand All @@ -25,8 +28,10 @@ public class FavoriteItem {
@Column(name = "conv_target")
public String convTarget;

@Column(name = "origin")
public String origin;

@Column(name = "sender")
public String sender;

@Column(name="title",columnDefinition="LONGTEXT")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/wildfirechat/app/jpa/FavoriteRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@RepositoryRestResource()
public interface FavoriteRepository extends CrudRepository<FavoriteItem, Long> {

@Query(value = "select * from t_favorites where id > ?1 order by id desc limit ?2", nativeQuery = true)
List<FavoriteItem> loadFav(long startId, int count);
@Query(value = "select * from t_favorites where user_id = ?1 and id > ?2 order by id desc limit ?3", nativeQuery = true)
List<FavoriteItem> loadFav(String userId, long startId, int count);
}

0 comments on commit 31ce105

Please sign in to comment.