* riece-commands.el (riece-command-invite): Don't accept channel
[riece] / lisp / riece-naming.el
1 ;;; riece-naming.el --- toplevel naming management
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (eval-when-compile (require 'riece-inlines))
28
29 (require 'riece-globals)
30 (require 'riece-channel)
31 (require 'riece-user)
32 (require 'riece-display)
33
34 (defun riece-naming-assert-join (user-name channel-name)
35   (if (string-equal-ignore-case user-name riece-real-nickname)
36       (riece-join-channel channel-name))
37   (riece-user-toggle-channel user-name channel-name t)
38   (riece-channel-toggle-user channel-name user-name t))
39
40 (defun riece-naming-assert-part (user-name channel-name)
41   (if (string-equal-ignore-case user-name riece-real-nickname)
42       (progn
43         (riece-part-channel channel-name)
44         (riece-forget-channel channel-name))
45     (riece-user-toggle-channel user-name channel-name nil)
46     (riece-channel-toggle-user channel-name user-name nil)
47     (riece-channel-toggle-operator channel-name user-name nil)
48     (riece-channel-toggle-speaker channel-name user-name nil)
49     (if (riece-identity-equal user-name (riece-current-nickname))
50         (let* ((identity (riece-make-identity channel-name))
51                (pointer (riece-identity-member
52                          identity riece-current-channels)))
53           (if pointer
54               (setcar pointer nil))))))
55
56 (defun riece-naming-assert-rename (old-name new-name)
57   (if (string-equal-ignore-case old-name riece-real-nickname)
58       (setq riece-last-nickname riece-real-nickname
59             riece-real-nickname new-name))
60   (let* ((old (riece-get-user old-name))
61          (channels (riece-user-channels old))
62          users pointer)
63     (while channels
64       (setq users (riece-channel-get-users (car channels))
65             pointer (member old-name users))
66       (if pointer
67           (setcar pointer new-name))
68       (setq users (riece-channel-get-operators (car channels))
69             pointer (member old-name users))
70       (if pointer
71           (setcar pointer new-name))
72       (setq users (riece-channel-get-speakers (car channels))
73             pointer (member old-name users))
74       (if pointer
75           (setcar pointer new-name))
76       (setq channels (cdr channels)))
77     (riece-rename-user old-name new-name)))
78
79 (provide 'riece-naming)