Skip to content

Commit

Permalink
添加发送消息的示例
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed Jul 19, 2024
1 parent a11cf3c commit ea00ef6
Show file tree
Hide file tree
Showing 33 changed files with 2,271 additions and 193 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public interface ContentType {
int Composited = 11;
int Rich_Notification = 12;
int Articles = 13;
int StreamingText_Generationg = 14;
int StreamingText_Generated = 15;
int Not_Delivered = 16;
int Ptt_Voice = 23;
int Enter_Channel_Chat = 71;
int Leave_Channel_Chat = 72;
int Recall = 80;
Expand Down Expand Up @@ -126,6 +130,12 @@ public interface ContentType {
int Quit_Group_Visible_Notification = 121;
int Modify_Group_Extra = 122;
int Modify_Group_Member_Extra = 123;

int Call_Start = 400;
int Call_Accept = 401;
int Call_End = 402;
int Call_Add_Participant = 406;
int Call_Multi_Call_Ongoing = 416;
}

public interface MessagePersistFlag {
Expand Down
216 changes: 186 additions & 30 deletions sdk/src/main/java/cn/wildfirechat/sdk/Main.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2022 WildFireChat. All rights reserved.
*/

package cn.wildfirechat.sdk.messagecontent;

import cn.wildfirechat.pojos.MessagePayload;
import cn.wildfirechat.proto.ProtoConstants;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.util.ArrayList;
import java.util.Base64;
import java.util.List;


public class ArticlesMessageContent extends MessageContent {
public Article topArticle;
public ArrayList<Article> subArticles;

@Override
public int getContentType() {
return ProtoConstants.ContentType.Articles;
}

@Override
public int getPersistFlag() {
return ProtoConstants.PersistFlag.Persist_And_Count;
}

@Override
public MessagePayload encode() {
MessagePayload payload = super.encodeBase();
payload.setSearchableContent(topArticle.title);
JSONObject object = new JSONObject();

object.put("top", topArticle.toJson());
if (subArticles != null) {
JSONArray jsonArray = new JSONArray();
object.put("subArticles", jsonArray);
for (Article article : subArticles) {
jsonArray.add(article.toJson());
}
}
payload.setBase64edData(Base64.getEncoder().encodeToString(object.toString().getBytes()));


return payload;
}

@Override
public void decode(MessagePayload payload) {
try {
JSONObject object = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
JSONObject topObj = (JSONObject) object.get("top");
this.topArticle = Article.fromJson(topObj);
JSONArray jsonArray = (JSONArray) object.get("subArticles");
if (jsonArray != null && jsonArray.size() > 0) {
this.subArticles = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
subArticles.add(Article.fromJson((JSONObject) jsonArray.get(i)));
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
}


public List<LinkMessageContent> toLinkMessageContent() {
List<LinkMessageContent> contents = new ArrayList<>();
contents.add(this.topArticle.toLinkMessageContent());
if (this.subArticles != null) {
for (Article article : subArticles) {
contents.add(article.toLinkMessageContent());
}
}
return contents;
}

public static class Article {
public String articleId;
public String cover;
public String title;
public String digest;
public String url;
boolean readReport;

JSONObject toJson() {
JSONObject obj = new JSONObject();
obj.put("id", articleId);
obj.put("cover", cover);
obj.put("title", title);
obj.put("digest", digest);
obj.put("url", url);
obj.put("rr", readReport);


return obj;
}

static Article fromJson(JSONObject obj) {
Article article = new Article();
article.articleId = (String) obj.get("id");
article.cover = (String) obj.get("cover");
article.title = (String) obj.get("title");
article.digest = (String) obj.get("digest");
article.url = (String) obj.get("url");
article.readReport = (boolean) obj.get("rr");
return article;
}

public LinkMessageContent toLinkMessageContent() {
LinkMessageContent content = new LinkMessageContent(this.title, this.url);
content.setContentDigest(this.digest);
content.setThumbnailUrl(this.cover);
return content;
}

public Article() {
}
}
}
Loading

0 comments on commit ea00ef6

Please sign in to comment.