自分がリアクションや投票した後にストリーミングイベントを受け取ってもカウントを増やさない
This commit is contained in:
parent
2518524b26
commit
8da73791ca
|
@ -1145,7 +1145,7 @@ class Column(
|
|||
|
||||
val changeList = ArrayList<AdapterChange>()
|
||||
|
||||
// TODO userId が自分かどうか調べる
|
||||
// userId が自分かどうか調べる
|
||||
val myId = EntityId.from(access_info.token_info,TootApiClient.KEY_USER_ID)
|
||||
val byMe = myId != null && myId == ev.userId
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ class NicoEnquete(
|
|||
text = text,
|
||||
decoded_text = decoded_text,
|
||||
// 配列インデクスと同じだった id = EntityId.mayNull(src.parseLong("id")),
|
||||
votes = src.parseInt("votes")?:0,
|
||||
votes = src.parseInt("votes") ?: 0,
|
||||
isVoted = src.optBoolean("isVoted")
|
||||
)
|
||||
items.add(dst)
|
||||
|
@ -251,13 +251,17 @@ class NicoEnquete(
|
|||
}
|
||||
|
||||
// misskey用
|
||||
fun increaseVote(context:Context,argChoice : Int?,isMyVoted :Boolean) : Boolean {
|
||||
fun increaseVote(context : Context, argChoice : Int?, isMyVoted : Boolean) : Boolean {
|
||||
argChoice ?: return false
|
||||
|
||||
try {
|
||||
// 既に投票済み状態なら何もしない
|
||||
if(myVoted != null) return false
|
||||
|
||||
val item = this.items?.get(argChoice) ?: return false
|
||||
item.votes += 1
|
||||
if( isMyVoted) item.isVoted = true
|
||||
|
||||
if(isMyVoted) item.isVoted = true
|
||||
|
||||
// update ratios
|
||||
val votesList = ArrayList<Int>()
|
||||
var votesMax = 1
|
||||
|
@ -267,29 +271,28 @@ class NicoEnquete(
|
|||
votesList.add(votes)
|
||||
if(votes > votesMax) votesMax = votes
|
||||
}
|
||||
|
||||
|
||||
if(votesList.isNotEmpty()) {
|
||||
|
||||
|
||||
this.ratios = votesList.asSequence()
|
||||
.map { (it.toFloat() / votesMax.toFloat()) }
|
||||
.toMutableList()
|
||||
|
||||
|
||||
this.ratios_text = votesList.asSequence()
|
||||
.map { context.getString(R.string.vote_count_text, it) }
|
||||
.toMutableList()
|
||||
|
||||
|
||||
} else {
|
||||
this.ratios = null
|
||||
this.ratios_text = null
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}catch(ex:Throwable){
|
||||
log.e(ex,"increaseVote failed")
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.e(ex, "increaseVote failed")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -575,18 +575,26 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|||
fun increaseReaction(reaction : String?,byMe:Boolean):Boolean {
|
||||
reaction?: return false
|
||||
MisskeyReaction.shortcodeMap[reaction] ?: return false
|
||||
|
||||
if(byMe) {
|
||||
if(myReaction != null){
|
||||
// 自分でリアクションしたらUIで更新した後にストリーミングイベントが届くことがある
|
||||
return false
|
||||
}else{
|
||||
// 別クライアントから更新したのだろう
|
||||
myReaction = reaction
|
||||
}
|
||||
}
|
||||
|
||||
// カウントを増やす
|
||||
var map = this.reactionCounts
|
||||
if(map==null) {
|
||||
map = HashMap()
|
||||
this.reactionCounts = map
|
||||
}
|
||||
val v = map[ reaction ]
|
||||
map[ reaction ] = if( v==null ){
|
||||
1
|
||||
}else{
|
||||
v+1
|
||||
}
|
||||
if( byMe) myReaction = reaction
|
||||
map[ reaction ] = (v?:0) +1
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue