Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboard: better strings (fixes #3683) #3684

Merged
merged 18 commits into from
Jul 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chat: share with community, teams and enterprises (fixes #3679) (#3680)
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi committed Jun 24, 2024
commit f302d3be932ca0754e229a07d9c46183acb21d10
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ android {
defaultConfig {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1613
versionName "0.16.13"
versionCode 1615
versionName "0.16.15"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Original file line number Diff line number Diff line change
@@ -15,8 +15,9 @@ open class RealmChatHistory : RealmObject() {
var _id: String? = null
var _rev: String? = null
var user: String? = null
var aiProvider: String? = null
var title: String? = null
var updatedTime: String? = null
var createdDate: String? = null
var conversations: RealmList<Conversation>? = null
companion object {
@JvmStatic
@@ -31,8 +32,9 @@ open class RealmChatHistory : RealmObject() {
chatHistory._rev = JsonUtils.getString("_rev", act)
chatHistory._id = JsonUtils.getString("_id", act)
chatHistory.title = JsonUtils.getString("title", act)
chatHistory.updatedTime = JsonUtils.getString("updatedTime", act)
chatHistory.createdDate = JsonUtils.getString("createdDate", act)
chatHistory.user = JsonUtils.getString("user", act)
chatHistory.aiProvider = JsonUtils.getString("aiProvider", act)
chatHistory.conversations = parseConversations(mRealm, JsonUtils.getJsonArray("conversations", act))
mRealm.commitTransaction()
}
72 changes: 56 additions & 16 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmNews.kt
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import android.text.TextUtils
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.gson.JsonSyntaxException
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmObject
@@ -70,6 +71,7 @@ open class RealmNews : RealmObject() {

val imagesArray: JsonArray
get() = if (images == null) JsonArray() else Gson().fromJson(images, JsonArray::class.java)

val labelsArray: JsonArray
get() {
val array = JsonArray()
@@ -100,17 +102,14 @@ open class RealmNews : RealmObject() {
}
return ms
}

val isCommunityNews: Boolean
get() {
val array = Gson().fromJson(viewIn, JsonArray::class.java)
var isCommunity = false
for (e in array) {
val `object` = e.asJsonObject
if (`object`.has("section") && `object`["section"].asString.equals(
"community",
ignoreCase = true
)
) {
if (`object`.has("section") && `object`["section"].asString.equals("community", ignoreCase = true)) {
isCommunity = true
break
}
@@ -121,9 +120,7 @@ open class RealmNews : RealmObject() {
companion object {
@JvmStatic
fun insert(mRealm: Realm, doc: JsonObject?) {
if (!mRealm.isInTransaction) {
mRealm.beginTransaction()
}
if (!mRealm.isInTransaction) mRealm.beginTransaction()
var news = mRealm.where(RealmNews::class.java)
.equalTo("_id", JsonUtils.getString("_id", doc))
.findFirst()
@@ -214,8 +211,11 @@ open class RealmNews : RealmObject() {

@JvmStatic
fun createNews(map: HashMap<String?, String>, mRealm: Realm, user: RealmUserModel?, imageUrls: RealmList<String>?): RealmNews {
if (!mRealm.isInTransaction) mRealm.beginTransaction()
val news = mRealm.createObject(RealmNews::class.java, UUID.randomUUID().toString())
if (!mRealm.isInTransaction) {
mRealm.beginTransaction()
}

val news = mRealm.createObject(RealmNews::class.java, "${UUID.randomUUID()}")
news.message = map["message"]
news.time = Date().time
news.createdOn = user?.planetCode
@@ -226,19 +226,59 @@ open class RealmNews : RealmObject() {
news.messagePlanetCode = map["messagePlanetCode"]
news.messageType = map["messageType"]
news.viewIn = getViewInJson(map)
news.chat = map["chat"]?.toBoolean() ?: false

try {
news.updatedDate = map["updatedDate"]?.toLong()!!
news.updatedDate = map["updatedDate"]?.toLong() ?: 0
} catch (e: Exception) {
e.printStackTrace()
}

news.userId = user?.id
news.replyTo = if (map.containsKey("replyTo")) {
map["replyTo"]
} else {
""
}
news.replyTo = map["replyTo"] ?: ""
news.user = Gson().toJson(user?.serialize())
news.imageUrls = imageUrls

if (map.containsKey("news")) {
val newsObj = map["news"]
val gson = Gson()
try {
val newsJsonString = newsObj?.replace("=", ":")
val newsJson = gson.fromJson(newsJsonString, JsonObject::class.java)
news.newsId = JsonUtils.getString("_id", newsJson)
news.newsRev = JsonUtils.getString("_rev", newsJson)
news.newsUser = JsonUtils.getString("user", newsJson)
news.aiProvider = JsonUtils.getString("aiProvider", newsJson)
news.newsTitle = JsonUtils.getString("title", newsJson)
if (newsJson.has("conversations")) {
val conversationsElement = newsJson.get("conversations")
if (conversationsElement.isJsonPrimitive && conversationsElement.asJsonPrimitive.isString) {
val conversationsString = conversationsElement.asString
try {
val conversationsArray = gson.fromJson(conversationsString, JsonArray::class.java)
if (conversationsArray.size() > 0) {
val conversationsList = ArrayList<HashMap<String, String>>()
conversationsArray.forEach { conversationElement ->
val conversationObj = conversationElement.asJsonObject
val conversationMap = HashMap<String, String>()
conversationMap["query"] = conversationObj.get("query").asString
conversationMap["response"] = conversationObj.get("response").asString
conversationsList.add(conversationMap)
}
news.conversations = Gson().toJson(conversationsList)
}
} catch (e: JsonSyntaxException) {
e.printStackTrace()
}
}
}
news.newsCreatedDate = JsonUtils.getLong("createdDate", newsJson)
news.newsUpdatedDate = JsonUtils.getLong("updatedDate", newsJson)
} catch (e: JsonSyntaxException) {
e.printStackTrace()
}
}

mRealm.commitTransaction()
return news
}
Loading
Loading