MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / AddChannel

Method AddChannel

src/windows/ChannelView.cpp:336–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334static UINT g_columnIndices[] = { 1 };
335
336void ChannelView::AddChannel(const Channel & ch)
337{
338 if (!ch.HasPermissionConst(PERM_VIEW_CHANNEL))
339 {
340 // If not a category, return. We'll remove invisible categories without elements after the fact.
341 if (ch.m_channelType != Channel::CATEGORY)
342 return;
343 }
344
345 ChannelMember cmem;
346 cmem.m_hItem = NULL;
347 cmem.m_childCount = 0;
348 cmem.m_snowflake = ch.m_snowflake;
349
350 const TCHAR* ptr = (const TCHAR*)ConvertCppStringToTString(ch.m_name);
351 _tcsncpy(cmem.str, ptr, _countof(cmem.str));
352 cmem.str[_countof(cmem.str) - 1] = 0; // Ensure that it is null terminated. tcsncpy doesn't.
353 free((void*)ptr);
354
355 int index = int(m_channels.size());
356 int old_level = -1;
357
358 if (TreeMode())
359 {
360 int parentIndex = -1;
361 HTREEITEM hParent = TVI_ROOT;
362 if (ch.m_channelType == Channel::CATEGORY) {
363 parentIndex = -2;
364 }
365 else if (ch.m_parentCateg != 0) {
366 parentIndex = m_idToIdx[ch.m_parentCateg];
367 hParent = m_channels[parentIndex].m_hItem;
368 m_channels[parentIndex].m_childCount++;
369 }
370
371 old_level = m_level;
372 if (ch.m_channelType == Channel::CATEGORY) m_level = 1;
373 if (IsChannelASubThread(ch.m_channelType)) {
374 old_level = m_level;
375 m_level = 3;
376 }
377
378 cmem.m_hItem = AddItemToTree(m_treeHwnd, cmem.str, hParent, index, parentIndex, GetIcon(ch, true)); // categories are expanded by default
379 }
380 else
381 {
382 LVITEM lvi{};
383 lvi.mask = LVIF_COLUMNS;
384 lvi.stateMask = LVIS_OVERLAYMASK;
385 lvi.iItem = index;
386 lvi.iSubItem = 0;
387 lvi.cColumns = _countof(g_columnIndices);
388 lvi.puColumns = g_columnIndices;
389 ListView_InsertItem(m_listHwnd, &lvi);
390 }
391
392 m_channels.push_back(cmem);
393 m_idToIdx[cmem.m_snowflake] = index;

Callers 1

WindowProcFunction · 0.45

Calls 5

IsChannelASubThreadFunction · 0.85
HasPermissionConstMethod · 0.80
GetDMRecipientMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected