From 0287a721c02034b46eb8f32bc628334ebab93fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Tue, 18 Sep 2018 09:13:06 +0200 Subject: [PATCH] history: add arrow directions --- src/types.jl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/types.jl b/src/types.jl index 43a592c..f97e679 100644 --- a/src/types.jl +++ b/src/types.jl @@ -12,6 +12,11 @@ struct MatrixUser deviceid::String end +import Base.== +==(u::MatrixUser, s::String) = + string("@", u.userid, ":", join(split(URI(u.server.instance).host, ".")[end-1:end], ".")) == s +==(s::String, u::MatrixUser) = u == s + import Base.show function Base.show(io::IO, n::MatrixServer) print(io, string("(matrix) ", n.instance)) @@ -43,7 +48,19 @@ struct MatrixMsg end using Dates -function Base.show(io::IO, m::MatrixMsg) +function Base.show(io::IO, m::MatrixMsg; muser::Union{Nothing,MatrixUser} = nothing) + global user + if muser === nothing + if isdefined(MatrixChat, :user) + direction = m.sender == user ? + " ««« " : " »»» " + else + direction = " »»» " + end + else + direction = " »»» " + end + d = Dates.epochms2datetime(m.timestamp + Dates.datetime2epochms(Dates.unix2datetime(0))) dtfmt = if Dates.Hour(now()) - Dates.Hour(d) < Dates.Hour(24) @@ -52,6 +69,6 @@ function Base.show(io::IO, m::MatrixMsg) string(day(d), " ", Dates.monthabbr(d)) end - print(io, string("[", dtfmt, "] ", m.sender, " »»» ", m.body)) + print(io, string("[", dtfmt, "] ", m.sender, direction, m.body)) nothing end