-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtalk.view.ts
137 lines (102 loc) · 2.8 KB
/
talk.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
namespace $.$$ {
export class $hyoo_talks extends $.$hyoo_talks {
domain() {
return this.$.$hyoo_talks_domain
}
yard() {
return this.domain().yard()
}
chat_id_current() {
return this.$.$mol_state_arg.value( 'chat' ) ?? ''
}
settings_opened() {
return this.$.$mol_state_arg.value( 'settings' ) !== null
}
roster_opened() {
return this.$.$mol_state_arg.value( 'roster' ) !== null
}
@ $mol_mem
embed() : boolean {
const val = this.$.$mol_state_arg.value( 'embed' )
if( val !== null ) return true
if( this.roster_opened() ) return false
const context = this.$.$mol_dom_context
return context.self !== context.parent
}
@ $mol_mem
pages() {
const chat = this.chat_id_current()
const roster = !this.embed()
return [
... roster ? [ this.Roster() ] : [],
... chat ? [ this.Chat_page( chat ) ] : [],
... this.settings_opened() ? [ this.Settings() ] : [],
]
}
User() {
return this.domain().User()
}
background() {
const uri = this.User().background()
const shade = `hsl( var(--mol_theme_hue), 0% , calc( 50% + 50% * var(--mol_theme_luma) ), .8 )`
return uri ? `linear-gradient( ${shade}, ${shade} ), url(${ JSON.stringify( uri ) })` : shade
}
roster_body() {
return [
... this.User().chats().length > 1 ? [ this.Links_query() ] : [],
this.Links(),
]
}
@ $mol_mem
links() {
return this.User().chats()
.filter( $mol_match_text( this.links_query(), chat => [ chat.title() ] ) )
.map( chat => this.Chat_link( chat.id ) )
.reverse()
}
chat( id: $mol_int62_string ) {
return this.domain().Chat( id )
}
person( id: $mol_int62_string ) {
return this.domain().Person( id )
}
@ $mol_mem_key
chat_title( id: $mol_int62_string ) {
return this.chat( id ).title() || this.unnamed()
}
chat_arg( id: string ) {
return { chat: id }
}
chat_new() {
const chat = this.domain().chat_new()
this.User().chat_watch( chat, true )
this.$.$mol_dom_context.location.href = '#!chat=' + chat.id
}
@ $mol_mem_key
chat_unread_count( id: $mol_int62_string ) {
return this.chat( id ).unread_count()
}
@ $mol_mem_key
message_notify( chat: $hyoo_talks_chat ) {
if( !this.chat_unread_count( chat.id ) ) return null
this.$.$mol_notify.show({
context: `${chat.title()}`,
message: this.new_message(),
uri: this.$.$mol_state_arg.link({ chat: chat.id })
})
return null
}
chat_link_sub( id: $mol_int62_string ) {
return [
... this.chat_unread_count( id ) === 0 ? [] : [ this.Chat_unread_count( id ) ],
this.Chat_link_title( id ),
]
}
// auto() {
// for( const chat of this.User().chats() ) {
// this.message_notify( chat )
// }
// return null
// }
}
}