Repository navigation
Expand file tree
/
Copy pathMainChatForm.frm
More file actions
295 lines (262 loc) · 9.35 KB
/
Copy pathMainChatForm.frm
File metadata and controls
295 lines (262 loc) · 9.35 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
VERSION 5.00
Begin VB.Form MainChatForm
BorderStyle = 1 'Fixed Single
Caption = "Matter95"
ClientHeight = 5850
ClientLeft = 45
ClientTop = 330
ClientWidth = 8070
Icon = "MainChatForm.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5850
ScaleWidth = 8070
StartUpPosition = 3 'Windows Default
Begin VB.Timer PostUpdateTimer
Enabled = 0 'False
Interval = 1000
Left = 8160
Top = 0
End
Begin VB.ListBox TeamList
Height = 645
ItemData = "MainChatForm.frx":030A
Left = 240
List = "MainChatForm.frx":030C
TabIndex = 4
Top = 600
Width = 2895
End
Begin VB.TextBox PostTextBox
Enabled = 0 'False
Height = 375
Left = 240
TabIndex = 3
Top = 5280
Width = 6255
End
Begin VB.CommandButton SubmitButton
Caption = "Send"
Enabled = 0 'False
Height = 375
Left = 6720
TabIndex = 2
Top = 5280
Width = 1095
End
Begin VB.TextBox PostViewTextBox
Height = 4215
Left = 3360
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 600
Width = 4455
End
Begin VB.ListBox ChannelList
Height = 2985
ItemData = "MainChatForm.frx":030E
Left = 240
List = "MainChatForm.frx":0310
TabIndex = 0
Top = 1800
Width = 2895
End
Begin VB.Label Label4
Caption = "Posts"
Height = 255
Left = 3360
TabIndex = 8
Top = 240
Width = 1335
End
Begin VB.Label Label3
Caption = "Write a post"
Height = 255
Left = 240
TabIndex = 7
Top = 4920
Width = 2055
End
Begin VB.Label Label2
Caption = "Channels:"
Height = 255
Left = 240
TabIndex = 6
Top = 1440
Width = 1455
End
Begin VB.Label Label1
Caption = "Teams:"
Height = 255
Left = 240
TabIndex = 5
Top = 240
Width = 1335
End
End
Attribute VB_Name = "MainChatForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim colMyTeams As Collection
Dim colMyChannels As Collection
Dim objPosts As Dictionary
Dim dictChannelIndexToChannelId As Dictionary
Dim sLastPostId As String
Dim sCurrentChannelId As String
Private Sub Form_Load()
PostViewTextBox.Locked = True
PostUpdateTimer.Enabled = False
MainChatForm.Caption = "Matter95 - " & MattermostClient.sServerURL
Set dictChannelIndexToChannelId = New Dictionary
Set colMyTeams = MattermostClient.GetMyTeams()
'MsgBox (colMyTeams.Count)
'MsgBox (JSON.GetParserErrors)
Dim i As Integer
For i = 1 To colMyTeams.Count
Dim sTeamDisplayName As String
sTeamDisplayName = colMyTeams(i)("display_name")
TeamList.AddItem sTeamDisplayName
'MsgBox (colMyTeams(i)("id"))
Next i
End Sub
Private Sub Form_Unload(iCancel As Integer)
End
End Sub
Private Sub PostViewTextBox_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub PostTextBox_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SubmitPost
KeyAscii = 0
End If
End Sub
Private Sub SubmitPost()
If PostTextBox.Text = "" Then
Exit Sub
End If
Dim sMessageString As String
sMessageString = PostTextBox.Text
PostTextBox.Text = ""
MattermostClient.CreatePost sCurrentChannelId, sMessageString
End Sub
Private Sub SubmitButton_Click()
SubmitPost
End Sub
Private Sub TeamList_Click()
PostUpdateTimer.Enabled = False
PostTextBox.Enabled = False
SubmitButton.Enabled = False
ChannelList.Clear
dictChannelIndexToChannelId.RemoveAll
PostViewTextBox.Text = ""
sLastPostId = ""
Dim sTeamId As String
Dim i As Integer
For i = 0 To colMyTeams.Count - 1
If TeamList.Selected(i) Then
sTeamId = colMyTeams(i + 1)("id")
End If
Next i
Set colMyChannels = MattermostClient.GetMyChannelsForTeam(sTeamId)
Dim j As Integer
For j = 1 To colMyChannels.Count
Dim sChannelId As String
Dim sChannelDisplayName As String
sChannelId = colMyChannels(j)("id")
sChannelDisplayName = colMyChannels(j)("display_name")
If sChannelDisplayName = "" Then
If colMyChannels(j)("type") = "D" Then
Dim sChannelName As String
sChannelName = colMyChannels(j)("name")
Dim sOtherUserId As String
Dim arrSplitChannelName() As String
arrSplitChannelName = Split(sChannelName, "__")
If arrSplitChannelName(0) = MattermostClient.objCurrentUser("id") Then
sOtherUserId = arrSplitChannelName(1)
Else
sOtherUserId = arrSplitChannelName(0)
End If
Dim colOtherUserResult As Object
Dim arrUsersIds(1) As String
arrUsersIds(0) = sOtherUserId
Set colOtherUserResult = MattermostClient.GetUsersByIds(arrUsersIds)
sChannelDisplayName = "@" & colOtherUserResult(1)("username")
End If
End If
dictChannelIndexToChannelId.Add j - 1, sChannelId
ChannelList.AddItem sChannelDisplayName
Next j
End Sub
Private Sub ChannelList_Click()
PostUpdateTimer.Enabled = False
PostTextBox.Enabled = False
SubmitButton.Enabled = False
PostViewTextBox.Text = ""
sLastPostId = ""
Dim sChannelId As String
Dim i As Integer
For i = 0 To colMyChannels.Count - 1
If ChannelList.Selected(i) Then
sChannelId = dictChannelIndexToChannelId(i)
End If
Next i
sCurrentChannelId = sChannelId
Set objPosts = MattermostClient.GetPostsForChannel(sChannelId)
Dim j As Integer
For j = objPosts("order").Count To 1 Step -1
Dim objPost As Object
Set objPost = objPosts("posts")(objPosts("order")(j))
Dim sUserName As String
If Not MattermostClient.dictUsersById.Exists(objPost("user_id")) Then
Dim arrUsersIds(1) As String
arrUsersIds(0) = objPost("user_id")
MattermostClient.GetUsersByIds arrUsersIds
End If
If MattermostClient.dictUsersById.Exists(objPost("user_id")) Then
Dim objUser As Object
Set objUser = MattermostClient.dictUsersById(objPost("user_id"))
sUserName = objUser("username")
Else
sUserName = objPost("user_id")
End If
PostViewTextBox.Text = PostViewTextBox.Text & sUserName & ": " & objPost("message") & vbNewLine & vbNewLine
PostViewTextBox.SelStart = &HFFFF&
sLastPostId = objPost("id")
Next j
PostUpdateTimer.Enabled = True
PostTextBox.Enabled = True
SubmitButton.Enabled = True
End Sub
Private Sub PostUpdateTimer_Timer()
Dim objNewPosts As Object
Set objNewPosts = MattermostClient.GetPostsForChannel(sCurrentChannelId, sLastPostId)
If Not objNewPosts("posts").Count = 0 Then
Dim j As Integer
For j = objNewPosts("order").Count To 1 Step -1
Dim objPost As Object
Set objPost = objNewPosts("posts")(objNewPosts("order")(j))
objPosts.Add objPost("id"), objPost
Dim sUserName As String
If Not MattermostClient.dictUsersById.Exists(objPost("user_id")) Then
Dim arrUsersIds(1) As String
arrUsersIds(0) = objPost("user_id")
MattermostClient.GetUsersByIds arrUsersIds
End If
If MattermostClient.dictUsersById.Exists(objPost("user_id")) Then
Dim objUser As Object
Set objUser = MattermostClient.dictUsersById(objPost("user_id"))
sUserName = objUser("username")
Else
sUserName = objPost("user_id")
End If
PostViewTextBox.Text = PostViewTextBox.Text & sUserName & ": " & objPost("message") & vbNewLine & vbNewLine
PostViewTextBox.SelStart = &HFFFF&
sLastPostId = objPost("id")
Next j
End If
End Sub