int Meta_CallMostOnline(WPARAM hContact, LPARAM lParam) { DBCachedContact *cc = CheckMeta(hContact); if (cc == NULL) return 0; Meta_CopyContactNick(cc, db_mc_getSrmmSub(cc->contactID)); Meta_FixStatus(cc); return 0; }
int IsAutoPopup(MCONTACT hContact) { if (g_dat.flags & SMF_AUTOPOPUP) { char *szProto = GetContactProto(hContact); hContact = db_mc_getSrmmSub(hContact); if (hContact != NULL) szProto = GetContactProto(hContact); if (szProto && (g_dat.openFlags & SRMMStatusToPf2(CallProtoService(szProto, PS_GETSTATUS, 0, 0)))) return 1; } return 0; }
// we assume that it could be called only for the metacontacts static int Meta_SrmmIconClicked(WPARAM hMeta, LPARAM lParam) { StatusIconClickData *sicd = (StatusIconClickData*)lParam; if (lstrcmpA(sicd->szModule, META_PROTO)) return 0; DBCachedContact *cc = CheckMeta(hMeta); if (cc == NULL) return 0; HMENU hMenu = CreatePopupMenu(); int iDefault = Meta_GetContactNumber(cc, db_mc_getSrmmSub(cc->contactID)); MENUITEMINFO mii = { sizeof(mii) }; mii.fMask = MIIM_ID | MIIM_STATE | MIIM_STRING; for (int i = 0; i < cc->nSubs; i++) { char *szProto = GetContactProto(cc->pSubs[i]); if (szProto == NULL) continue; PROTOACCOUNT *pa = ProtoGetAccount(szProto); if (pa == NULL) continue; CMString tszNick; if (options.menu_contact_label == DNT_DID) tszNick = cli.pfnGetContactDisplayName(cc->pSubs[i], 0); else Meta_GetSubNick(hMeta, i, tszNick); tszNick.AppendFormat(_T(" [%s]"), pa->tszAccountName); mii.wID = i + 1; mii.fState = (i == iDefault) ? MFS_CHECKED : MFS_ENABLED; mii.dwTypeData = tszNick.GetBuffer(); mii.cch = tszNick.GetLength(); InsertMenuItem(hMenu, i, TRUE, &mii); } UINT res = TrackPopupMenu(hMenu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_BOTTOMALIGN | TPM_LEFTALIGN, sicd->clickLocation.x, sicd->clickLocation.y, 0, cli.hwndContactTree, NULL); if (res > 0) { MCONTACT hChosen = Meta_GetContactHandle(cc, res - 1); MetaSrmmData tmp = { cc->contactID }; if (MetaSrmmData *p = arMetaWindows.find(&tmp)) p->m_hSub = hChosen; db_mc_setDefault(cc->contactID, hChosen, true); } return 0; }
INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam) { CCSDATA *ccs = (CCSDATA*)lParam; DBCachedContact *cc = CheckMeta(ccs->hContact); if (cc == NULL || cc->nDefault == -1) { // This is a simple contact, let through the stack of protocols // (this should normally not happen, since linked contacts do not appear on the list.) return CallService(MS_PROTO_CHAINSEND, wParam, lParam); } MCONTACT hMostOnline = db_mc_getSrmmSub(cc->contactID); if (!hMostOnline) { // send failure to notify user of reason HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); TFakeAckParams *tfap = (TFakeAckParams *)mir_alloc(sizeof(TFakeAckParams)); tfap->hContact = ccs->hContact; tfap->hEvent = hEvent; tfap->id = 10; strcpy(tfap->msg, Translate("No online contacts found.")); DWORD dwThreadId; CloseHandle(CreateThread(NULL, 0, sttFakeAckFail, tfap, 0, &dwThreadId)); SetEvent(hEvent); return 10; } Meta_CopyContactNick(cc, hMostOnline); ccs->hContact = hMostOnline; char *proto = GetContactProto(hMostOnline); Meta_SetNick(proto); // (no matter what was there before) return CallContactService(ccs->hContact, PSS_MESSAGE, ccs->wParam, ccs->lParam); }
/** * update meta (subcontact and -protocol) status. This runs when the * MC protocol fires one of its events OR when a relevant database value changes * in the master contact. */ void CContactCache::updateMeta() { if (m_Valid) { MCONTACT hOldSub = m_hSub; m_hSub = db_mc_getSrmmSub(cc->contactID); m_szMetaProto = GetContactProto(m_hSub); m_wMetaStatus = (WORD)db_get_w(m_hSub, m_szMetaProto, "Status", ID_STATUS_OFFLINE); PROTOACCOUNT *pa = Proto_GetAccount(m_szMetaProto); if (pa) m_szAccount = pa->tszAccountName; if (hOldSub != m_hSub) { updateStatus(); updateNick(); updateUIN(); } } else { m_hSub = 0; m_szMetaProto = NULL; m_wMetaStatus = ID_STATUS_OFFLINE; m_xStatus = 0; } }
int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM lParam) { TCHAR szName[CONTAINER_NAMELEN + 1]; HANDLE hDbEvent = (HANDLE)lParam; DBEVENTINFO dbei = { sizeof(dbei) }; db_event_get(hDbEvent, &dbei); HWND hwnd = M.FindWindow(hContact); if (hwnd == NULL) hwnd = M.FindWindow(db_event_getContact(hDbEvent)); BOOL isCustomEvent = IsCustomEvent(dbei.eventType); BOOL isShownCustomEvent = DbEventIsForMsgWindow(&dbei); if (dbei.markedRead() || (isCustomEvent && !isShownCustomEvent)) return 0; CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); bool bAllowAutoCreate = false; bool bAutoPopup = M.GetByte(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP) != 0; bool bAutoCreate = M.GetByte("autotabs", 1) != 0; bool bAutoContainer = M.GetByte("autocontainer", 1) != 0; DWORD dwStatusMask = M.GetDword("autopopupmask", -1); if (hwnd) { TContainerData *pTargetContainer = 0; SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pTargetContainer); if (pTargetContainer == NULL || !PluginConfig.m_HideOnClose || IsWindowVisible(pTargetContainer->hwnd)) return 0; WINDOWPLACEMENT wp = { 0 }; wp.length = sizeof(wp); GetWindowPlacement(pTargetContainer->hwnd, &wp); GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN); if (bAutoPopup || bAutoCreate) { if (bAutoPopup) { if (wp.showCmd == SW_SHOWMAXIMIZED) ShowWindow(pTargetContainer->hwnd, SW_SHOWMAXIMIZED); else ShowWindow(pTargetContainer->hwnd, SW_SHOWNOACTIVATE); return 0; } TContainerData *pContainer = FindContainerByName(szName); if (pContainer != NULL) { if (bAutoContainer) { ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE); return 0; } goto nowindowcreate; } else if (bAutoContainer) { ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE); return 0; } } } else { switch (dbei.eventType) { case EVENTTYPE_AUTHREQUEST: case EVENTTYPE_ADDED: return 0; case EVENTTYPE_FILE: tabSRMM_ShowPopup(hContact, hDbEvent, dbei.eventType, 0, 0, 0, dbei.szModule, 0); return 0; } } // if no window is open, we are not interested in anything else but unread message events // new message if (!nen_options.iNoSounds) SkinPlaySound("AlertMsg"); if (nen_options.iNoAutoPopup) goto nowindowcreate; GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN); if (dwStatusMask == -1) bAllowAutoCreate = true; else { char *szProto = GetContactProto(hContact); if (szProto && !strcmp(szProto, META_PROTO)) szProto = GetContactProto(db_mc_getSrmmSub(hContact)); if (szProto) { DWORD dwStatus = (DWORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0); if (dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & dwStatusMask)) // should never happen, but... bAllowAutoCreate = true; } } if (bAllowAutoCreate && (bAutoPopup || bAutoCreate)) { if (bAutoPopup) { TContainerData *pContainer = FindContainerByName(szName); if (pContainer == NULL) pContainer = CreateContainer(szName, FALSE, hContact); if (pContainer) CreateNewTabForContact(pContainer, hContact, 0, NULL, TRUE, TRUE, FALSE, 0); return 0; } bool bActivate = false, bPopup = M.GetByte("cpopup", 0) != 0; TContainerData *pContainer = FindContainerByName(szName); if (pContainer != NULL) { if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->szName, L"default", 6)) { if ((pContainer = FindMatchingContainer(L"default", hContact)) != NULL) { CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent); return 0; } } else { CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent); return 0; } } if (bAutoContainer) { if ((pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, hContact)) != NULL) { // 2 means create minimized, don't popup... CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent); SendMessageW(pContainer->hwnd, WM_SIZE, 0, 0); } return 0; } } // for tray support, we add the event to the tray menu. otherwise we send it back to // the contact list for flashing nowindowcreate: if (!(dbei.flags & DBEF_READ)) { UpdateTrayMenu(0, 0, dbei.szModule, NULL, hContact, 1); if (!nen_options.bTraySupport) { TCHAR toolTip[256], *contactName; CLISTEVENT cle = { sizeof(cle) }; cle.hContact = hContact; cle.hDbEvent = hDbEvent; cle.flags = CLEF_TCHAR; cle.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE); cle.pszService = "SRMsg/ReadMessage"; contactName = pcli->pfnGetContactDisplayName(hContact, 0); mir_sntprintf(toolTip, SIZEOF(toolTip), TranslateT("Message from %s"), contactName); cle.ptszTooltip = toolTip; CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); } tabSRMM_ShowPopup(hContact, hDbEvent, dbei.eventType, 0, 0, 0, dbei.szModule, 0); } return 0; }