diff options
author | 2019-09-24 11:54:21 +0300 | |
---|---|---|
committer | 2019-09-24 11:54:21 +0300 | |
commit | 2f2e9aab6194037259625200091949d8648e3409 (patch) | |
tree | 4669e3bf5389bf68581094ab01dee4155a91e24f /src/main/java/com/juick/server/api/SystemActivity.java | |
parent | 289afd5a0b510e4501cf421dd9a05bb53bc424c3 (diff) |
Use single event model for all application events
Diffstat (limited to 'src/main/java/com/juick/server/api/SystemActivity.java')
-rw-r--r-- | src/main/java/com/juick/server/api/SystemActivity.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main/java/com/juick/server/api/SystemActivity.java b/src/main/java/com/juick/server/api/SystemActivity.java new file mode 100644 index 00000000..162374d1 --- /dev/null +++ b/src/main/java/com/juick/server/api/SystemActivity.java @@ -0,0 +1,88 @@ +package com.juick.server.api; + +import com.juick.Message; +import com.juick.User; + +import java.util.List; + +public class SystemActivity { + public static SystemActivity like(User from, Message message, List<User> subscribers) { + var like = new SystemActivity(); + like.setType(ActivityType.like); + like.setFrom(from); + like.setMessage(message); + like.setTo(subscribers); + return like; + } + + public static SystemActivity message(User from, Message message, List<User> subscribers) { + var msg = new SystemActivity(); + msg.setType(ActivityType.message); + msg.setFrom(from); + msg.setMessage(message); + msg.setTo(subscribers); + return msg; + } + + public static SystemActivity read(User from, Message message) { + var read = new SystemActivity(); + read.setType(ActivityType.message); + read.setFrom(from); + var msg = new Message(); + msg.setMid(message.getMid()); + msg.setService(true); + msg.setUnread(false); + read.setMessage(msg); + return read; + } + + public static SystemActivity follow(User from, List<User> to) { + var follow = new SystemActivity(); + follow.setFrom(from); + follow.setTo(to); + return follow; + } + + public enum ActivityType { + message, + like, + follow + } + + private ActivityType type; + private User from; + private List<User> to; + private Message message; + + public ActivityType getType() { + return type; + } + + public void setType(ActivityType type) { + this.type = type; + } + + public User getFrom() { + return from; + } + + public void setFrom(User from) { + this.from = from; + } + + public List<User> getTo() { + return to; + } + + public void setTo(List<User> to) { + this.to = to; + } + + public Message getMessage() { + return message; + } + + public void setMessage(Message message) { + this.message = message; + } +} |