Skip to content

Commit

Permalink
Obey day_change property for date line
Browse files Browse the repository at this point in the history
  • Loading branch information
jspricke committed Jun 19, 2021
1 parent 1a5926c commit 06ed00c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Buffer @WorkerThread constructor(
@JvmField var shortName: String = ""
@JvmField var hidden: Boolean = false
@JvmField var type = BufferSpec.Type.Other
@JvmField var displayDayChange: Boolean = false

private var notify: Notify = Notify.default

Expand All @@ -34,6 +35,7 @@ class Buffer @WorkerThread constructor(
internal var updateHidden = false
internal var updateType = false
internal var updateNotifyLevel = false
internal var updateDayChange = false

var number: Int by updatable(::updateName, this@Buffer::number)
var fullName: String by updatable(::updateName, this@Buffer::fullName)
Expand All @@ -42,6 +44,7 @@ class Buffer @WorkerThread constructor(
var hidden: Boolean by updatable(::updateHidden)
var type: BufferSpec.Type by updatable(::updateType)
var notify: Notify? by updatable(::updateNotifyLevel)
var displayDayChange: Boolean by updatable(::updateDayChange)
}

fun update(block: Updater.() -> Unit) {
Expand All @@ -65,6 +68,7 @@ class Buffer @WorkerThread constructor(
if (updater.updateNotifyLevel) notify = updater.notify ?: Notify.default
if (updater.updateHidden) hidden = updater.hidden
if (updater.updateType) type = updater.type
if (updater.updateDayChange) displayDayChange = updater.displayDayChange
}

////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -215,7 +219,7 @@ class Buffer @WorkerThread constructor(
}

synchronized(this) {
lines.replaceLines(newLines)
lines.replaceLines(newLines, displayDayChange)
}
}

Expand All @@ -227,7 +231,7 @@ class Buffer @WorkerThread constructor(
val notifyPmOrMessage = line.notifyLevel == LineSpec.NotifyLevel.Message || notifyPm

synchronized(this) {
lines.addLast(line)
lines.addLast(line, displayDayChange)

// notify levels: 0 none 1 highlight 2 message 3 all
// treat hidden lines and lines that are not supposed to generate a “notification” as read
Expand Down
35 changes: 19 additions & 16 deletions app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ class Lines {
// in very rare cases status might not be FETCHING here, particularly when closing buffers
// while the app is connecting and has already requested lines

fun replaceLines(lines: Collection<Line>) {
fun replaceLines(lines: Collection<Line>, displayDayChange: Boolean) {
if (status != Status.Fetching) return
unfiltered.clear()
filtered.clear()
dateOfLastUnfilteredLine = null
dateOfLastFilteredLine = null

for (line in lines) {
addLast(line)
addLast(line, displayDayChange)
}
}

Expand Down Expand Up @@ -135,26 +135,29 @@ class Lines {
return lastDateLine
}

fun addLast(line: Line) {
fun addLast(line: Line, displayDayChange: Boolean) {
if (shouldAddSquiggleOnNewLine) {
shouldAddSquiggleOnNewLine = false
if (status == Status.Init && unfiltered.size > 0) addLast(SquiggleLine()) // invisible
if (status == Status.Init && unfiltered.size > 0)
addLast(SquiggleLine(), displayDayChange) // invisible
}

val newDate = Instant.ofEpochSecond(line.timestamp / 1000)
.atZone(ZoneId.systemDefault())
.toLocalDate()
if(displayDayChange) {
val newDate = Instant.ofEpochSecond(line.timestamp / 1000)
.atZone(ZoneId.systemDefault())
.toLocalDate()

if (dateOfLastUnfilteredLine != newDate) {
unfiltered.addLast(obtainDateChangeLine(dateOfLastUnfilteredLine, newDate))
dateOfLastUnfilteredLine = newDate
skipUnfiltered++
}
if (dateOfLastUnfilteredLine != newDate) {
unfiltered.addLast(obtainDateChangeLine(dateOfLastUnfilteredLine, newDate))
dateOfLastUnfilteredLine = newDate
skipUnfiltered++
}

if (line.isVisible && dateOfLastFilteredLine != newDate) {
filtered.addLast(obtainDateChangeLine(dateOfLastFilteredLine, newDate))
dateOfLastFilteredLine = newDate
skipFiltered++
if (line.isVisible && dateOfLastFilteredLine != newDate) {
filtered.addLast(obtainDateChangeLine(dateOfLastFilteredLine, newDate))
dateOfLastFilteredLine = newDate
skipFiltered++
}
}

if (shouldAddSquiggleOnNewVisibleLine && line.isVisible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class Notify(val value: Int) {
inline val notify: Notify? get() = Notify::value.find(entry.getIntOrNull("notify"))
inline val type get() = Type.fromLocalVariables(entry.getHashtable("local_variables"))
inline val hidden get() = entry.getIntOrNull("hidden") == 1
inline val displayDayChange get() = entry.getIntOrNull("day_change") == 1

// todo get rid of openWhileRunning
fun toBuffer(openWhileRunning: Boolean) = Buffer(pointer).apply {
Expand All @@ -50,6 +51,7 @@ enum class Notify(val value: Int) {
notify = this@BufferSpec.notify
hidden = this@BufferSpec.hidden
type = this@BufferSpec.type
displayDayChange = this@BufferSpec.displayDayChange
}

if (P.isBufferOpen(pointer)) setOpen(open = true, syncHotlistOnOpen = false)
Expand All @@ -67,7 +69,7 @@ enum class Notify(val value: Int) {

companion object {
const val listBuffersRequest = "(listbuffers) hdata buffer:gui_buffers(*) " +
"number,full_name,short_name,type,title,nicklist,local_variables,notify,hidden"
"number,full_name,short_name,type,title,nicklist,local_variables,notify,hidden,day_change"

const val renumberRequest = "(renumber) hdata buffer:gui_buffers(*) number"
}
Expand Down

0 comments on commit 06ed00c

Please sign in to comment.