News:

Join the Facebook Fan Page.

Main Menu

New IM JS popup

Started by Dado, March 17, 2004, 12:10:23 PM

Previous topic - Next topic

Dado

I wrote a small mod that pops up a confirm() dialog when new IM was received. OK goes to IM inbox, Cancel, just continues to load the current page.

It uses a cookie so that if you select cancel, you don't get the same popup over and over, only when a new message comes, it comes up again.

Could this go into the main release?

Sorry for my english ;)

pulpitfire

are you going to post a link, so people can try it out first?

Dado

Quote from: pege on March 17, 2004, 12:11:57 PM
are you going to post a link, so people can try it out first?

It's not yet merged to my forum, I'm just the "forum developer", not the admin :) But it works, very well.

I could send the file I've changed here (one of the templates files), I've marked everything that has been changed so no hacks are in there :) and everyone could test it on their own. Is that OK?

pulpitfire


Dado

All I'm missing is the upload fuke box ;) Where do I have perms to upload a file on this board?

pulpitfire

that's it.  now you have to be a charter member to upload files.  you could put a link to it on your site, or, if it's not ridiculously long, you could just post it in the thread here, between some code brackets.

Dado

file is Themes/default/index..teplate.php, paste at line 45, just under the template_main_above() declaration and the global line...


  // dado start
  // alert za PM ako ima novih
  global $db_prefix, $ID_MEMBER;
  $iVal = -1;
  if (isset($_COOKIE["smf_pm_cookie"]))
    $iVal = $_COOKIE["smf_pm_cookie"];

  $sQuery =  "select mem.realName,  count(pm.ID_PM) from {$db_prefix}im_recipients as pmr join {$db_prefix}instant_messages as pm join {$db_prefix}members as mem where mem.ID_MEMBER = pm.ID_MEMBER_FROM and pmr.ID_PM = pm.ID_PM and pmr.ID_MEMBER = {$ID_MEMBER} and pmr.is_read = 0 and pm.msgtime > $iVal group by (pm.ID_MEMBER_FROM)";

  $rQuery = mysql_query($sQuery);
  if ($rQuery){
    $iNum = mysql_num_rows($rQuery);
    if ($iNum){
      // zapisujemo cookie kad smo postavili obavijest
      setcookie("smf_pm_cookie", time());
      $sJS = "<script type=\"text/javascript\">\n";
      if ($iNum == 1){
        $aRow = mysql_fetch_array($rQuery);
        $sInsert = $aRow[0] ." sent you ". (($aRow[1]==1)?" one new PM.": $aRow[1]. " new PMs.");
      } else if ($iNum > 1){
        $sInsert = "You have received new PMs:";
        while ($aRow = mysql_fetch_array($rQuery)){
          $sInsert .= "\\n". $aRow[0] ." (". $aRow[1] .")";
        }
      }
      $sInsert .= "\\nGoto inbox now?";
      $sJS  = "<script type=\"text/javascript\">\n";
      $sJS .= "if (confirm('". $sInsert ."'))\n\twindow.location.href='". $scripturl ."?action=pm#new';";
      $sJS .= "\n</script>\n";
    }
  }

  // dado end


This goes under the title declaration...line 94... same file.


  // dado start
  if (isset($sJS))
    echo $sJS;
  //dado end

pulpitfire


[Unknown]

I can do this in about five lines and have on, for example, www.performance-shop.com.  I will be making it available later once SMF is more ready.

Just a hint though, there is absolutely no need for a query.

-[Unknown]

1979Z28

!#~!!

Unknown! Get those forsaken cars off your front page, and use some real cars! ;)

http://www.ufba.org (My Webpage) Those imports.. pft, total crap! ;)

jk of course. But I prefer Camaros and the likes... :-X

[Unknown]

Das ist nicht meine.... ist Brads.  Ich habe kein Auto.

-[Unknown]

Dado

Quote from: [Unknown] on March 17, 2004, 07:53:18 PM
Just a hint though, there is absolutely no need for a query.

Great, please do tell, I don't know how you can do it without one.  ???

[Unknown]

$context['user']['messages'], $context['user']['unread_messages'].

-[Unknown]

Dado

Quote from: [Unknown] on March 18, 2004, 02:04:21 PM
$context['user']['messages'], $context['user']['unread_messages'].

Yeah, I've seen that, but you haven't seen what mine does ;) My users wanted it to show who sent the new message so if they don't like the user, just don't go and read it... :-X

[Unknown]

But what if I have 5 new messages?

-[Unknown]

Dado

#15
Quote from: [Unknown] on March 19, 2004, 11:10:29 AM
But what if I have 5 new messages?

Test it, you'll like it ;)
It could be made an option in IM settings, me thinks. ::)

Another thing:  could you make the IM inbox output set the named anchor on the first new message. So we can do ?action=im#new or something...

pulpitfire

hmm...well, if it's a pop-up box, separate from the main forum window, it could be just like the 5 most recent topics, which each shows the poster.

[Unknown]

I see no rhyme or reason to wasting a lot of time on a query just to get the names.... just doesn't seem worth it.  At least don't do the query if there are no new messages...

-[Unknown]

Dado

#18
Quote from: [Unknown] on March 19, 2004, 06:16:33 PM
I see no rhyme or reason to wasting a lot of time on a query just to get the names.... just doesn't seem worth it.

Lot of stuff on the forum aren't very useful but are there just for the kick of it... Let's say I think this to be more useful then karma. :)

Quote
At least don't do the query if there are no new messages...


  // dado start
  // alert za PM ako ima novih

  global  $db_prefix, $ID_MEMBER;
  if (array_key_exists("unread_messages", $context["user"]) && $context["user"]["unread_messages"]){
    $iVal = -1;
    if (isset($_COOKIE["smf_pm_cookie"]))
      $iVal = $_COOKIE["smf_pm_cookie"];

    $sQuery =  "select mem.realName,  count(pm.ID_PM) from {$db_prefix}im_recipients as pmr join {$db_prefix}instant_messages as pm join {$db_prefix}members as mem where mem.ID_MEMBER = pm.ID_MEMBER_FROM and pmr.ID_PM = pm.ID_PM and pmr.ID_MEMBER = {$ID_MEMBER} and pmr.is_read = 0 and pm.msgtime > $iVal group by (pm.ID_MEMBER_FROM)";

    $rQuery = mysql_query($sQuery);

    if ($rQuery){
      $iNum = mysql_num_rows($rQuery);
      if ($iNum){
        // zapisujemo cookie kad smo postavili obavijest
        setcookie("smf_pm_cookie", time());

        if ($iNum == 1){
          $aRow = mysql_fetch_array($rQuery);
          $sInsert = $aRow[0] ." sent you ". (($aRow[1] == 1) ? " one new PM." : $aRow[1]. " new PMs.");
        } else {
          $sInsert = "You have received new PMs:";
          while ($aRow = mysql_fetch_array($rQuery)){
            $sInsert .= "\\n". $aRow[0] ." (". $aRow[1] .")";
          }
        }
        $sInsert .= "\\nGoto inbox now?";
        $sJS  = "<script type=\"text/javascript\">\n";
        $sJS .= "if (confirm('". $sInsert ."'))\n\twindow.location.href='". $scripturl ."?action=pm#new';";
        $sJS .= "\n</script>\n";
      }
    }
  }
  // dado end


This should do it.

Now, what about the named anchor mentioned above?

pulpitfire

Quote from: [Unknown] on March 19, 2004, 06:16:33 PM
I see no rhyme or reason to wasting a lot of time on a query just to get the names.... just doesn't seem worth it.  At least don't do the query if there are no new messages...

-[Unknown]

yep, that's fine.  it wouldn't have to do the query unless there are new messages.  obviously you're not going to want to personally code every idea that comes along into the next release.  but, maybe some mod developer will see the idea, like it, and hack it.  :)

Advertisement: