-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.lisp
56 lines (49 loc) · 1.53 KB
/
room.lisp
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
(uiop:define-package #:lem-rooms-client/room
(:use #:cl
#:alexandria)
(:shadow #:room)
(:export #:room-management-pane
#:room-room
#:room-id
#:room-name
#:room-client-id
#:room-directory
#:room-invitation
#:room-owner-p
#:register-room
#:set-room-directory
#:find-room-by-id
#:find-room-by-file
#:default-room))
(in-package #:lem-rooms-client/room)
(defvar *rooms* '())
(defstruct room
id
name
directory
management-pane
invitation
owner-p
(room nil :type rooms-client/agent-api:room))
(defun register-room (&key room room-name directory management-pane owner-p)
(let ((room (make-room :id (rooms-client/agent-api:room-id room)
:room room
:name room-name
:directory directory
:management-pane management-pane
:owner-p owner-p)))
(push room *rooms*)
room))
(defmethod set-room-directory ((room room) directory)
(setf (room-directory room)
(namestring (uiop:ensure-directory-pathname directory))))
(defun find-room-by-id (room-id)
(find room-id *rooms* :key #'room-id :test #'equal))
(defun find-room-by-file (file)
(dolist (room *rooms*)
(let ((root-path (namestring (room-directory room)))
(sub-path (namestring file)))
(when (starts-with-subseq root-path sub-path)
(return room)))))
(defun default-room ()
(first *rooms*))